You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by rw...@apache.org on 2005/02/07 07:59:28 UTC
cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager WarInfusionPAM.java FileSystemPAM.java
rwatler 2005/02/06 22:59:28
Modified: portal/src/java/org/apache/jetspeed/tools/pamanager
WarInfusionPAM.java FileSystemPAM.java
Log:
add backup deep copy to move deployment file operations - preserves deploy function if move fails due to locking or file system partitioning
Revision Changes Path
1.4 +6 -13 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/WarInfusionPAM.java
Index: WarInfusionPAM.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/WarInfusionPAM.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- WarInfusionPAM.java 4 Feb 2005 08:28:29 -0000 1.3
+++ WarInfusionPAM.java 7 Feb 2005 06:59:28 -0000 1.4
@@ -455,14 +455,7 @@
if (contextXmlFile.exists())
{
tempDeployPortletAppContextFile = new File(tempDirectory, deployPortletAppContextFile.getName() + "-expanded-war-context-" + getUniqueId());
- FileInputStream read = new FileInputStream(contextXmlFile);
- FileOutputStream copy = new FileOutputStream(tempDeployPortletAppContextFile);
- while ((bytesRead = read.read(buffer)) != -1)
- {
- copy.write(buffer, 0, bytesRead);
- }
- copy.close();
- read.close();
+ copyFile(contextXmlFile, tempDeployPortletAppContextFile);
}
// delete expanded portlet app war file
@@ -479,7 +472,7 @@
deployPortletAppWarFile.delete();
if (!deployPortletAppWarFile.exists())
{
- tempDeployPortletAppWarFile.renameTo(deployPortletAppWarFile);
+ moveFile(tempDeployPortletAppWarFile, deployPortletAppWarFile);
if (deployPortletAppWarFile.exists())
{
log.info("Portlet application deployment of " + deployPortletAppWarFile.getAbsolutePath() + " complete.");
@@ -501,8 +494,8 @@
deleteFile(deployPortletAppDirectory, true);
if (!deployPortletAppContextFile.exists() && !deployPortletAppDirectory.exists())
{
- tempDeployPortletAppContextFile.renameTo(deployPortletAppContextFile);
- tempDeployPortletAppDirectory.renameTo(deployPortletAppDirectory);
+ moveFile(tempDeployPortletAppContextFile, deployPortletAppContextFile);
+ moveFile(tempDeployPortletAppDirectory, deployPortletAppDirectory);
if (deployPortletAppContextFile.exists() && deployPortletAppDirectory.exists())
{
log.info("Expanded portlet application deployment of " + deployPortletAppContextFile.getAbsolutePath() + " and " + deployPortletAppDirectory.getAbsolutePath() + " complete.");
@@ -525,7 +518,7 @@
deleteFile(deployPortletAppDirectory, true);
if (!deployPortletAppDirectory.exists())
{
- tempDeployPortletAppDirectory.renameTo(deployPortletAppDirectory);
+ moveFile(tempDeployPortletAppDirectory, deployPortletAppDirectory);
if (deployPortletAppDirectory.exists())
{
log.info("Expanded portlet application deployment of " + deployPortletAppDirectory.getAbsolutePath() + " complete.");
1.50 +61 -2 jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java
Index: FileSystemPAM.java
===================================================================
RCS file: /home/cvs/jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager/FileSystemPAM.java,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- FileSystemPAM.java 4 Feb 2005 08:28:29 -0000 1.49
+++ FileSystemPAM.java 7 Feb 2005 06:59:28 -0000 1.50
@@ -23,6 +23,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.channels.FileChannel;
import java.util.Iterator;
import java.util.prefs.Preferences;
@@ -921,7 +922,7 @@
}
/**
- * deleteFile - move and deep file delete utility
+ * deleteFile - move and delete deep file utility
*
* @param file
* @param useTemp
@@ -933,14 +934,72 @@
{
if (useTemp)
{
+ // move to temp and delete
File delete = new File(tempDirectory, file.getName() + "-move-to-delete-" + getUniqueId());
if (file.renameTo(delete))
{
+ // delete deep
return (new DirectoryHelper(delete)).remove();
}
}
+ // delete deep in place
return (new DirectoryHelper(file)).remove();
}
return file.delete();
}
+
+ /**
+ * moveFile - move or copy deep file utility
+ *
+ * @param fromFile
+ * @param toFile
+ */
+ protected boolean moveFile(File fromFile, File toFile)
+ {
+ // move directories if possible, otherwise copy and delete
+ if (!fromFile.renameTo(toFile))
+ {
+ return (copyFile(fromFile, toFile) && deleteFile(fromFile, false));
+ }
+ return true;
+ }
+
+ /**
+ * copyFile - copy deep file utility
+ *
+ * @param fromFile
+ * @param toFile
+ */
+ protected boolean copyFile(File fromFile, File toFile)
+ {
+ // delete destination and copy if possible
+ deleteFile(toFile, false);
+ if (!toFile.exists())
+ {
+ try
+ {
+ if (fromFile.isDirectory())
+ {
+ // copy directory deep
+ (new DirectoryHelper(toFile)).copyFrom(fromFile);
+ }
+ else
+ {
+ // make destination directory and copy single file
+ toFile.getParentFile().mkdirs();
+ toFile.createNewFile();
+ FileChannel src = new FileInputStream(fromFile).getChannel();
+ FileChannel dst = new FileOutputStream(toFile).getChannel();
+ dst.transferFrom(src, 0, src.size());
+ src.close();
+ dst.close();
+ }
+ return true;
+ }
+ catch (IOException ioe)
+ {
+ }
+ }
+ return false;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org