Return-Path: Delivered-To: apmail-jakarta-jetspeed-dev-archive@www.apache.org Received: (qmail 29419 invoked from network); 7 Feb 2005 06:59:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 7 Feb 2005 06:59:33 -0000 Received: (qmail 64246 invoked by uid 500); 7 Feb 2005 06:59:31 -0000 Delivered-To: apmail-jakarta-jetspeed-dev-archive@jakarta.apache.org Received: (qmail 64201 invoked by uid 500); 7 Feb 2005 06:59:31 -0000 Mailing-List: contact jetspeed-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jetspeed Developers List" Reply-To: "Jetspeed Developers List" Delivered-To: mailing list jetspeed-dev@jakarta.apache.org Received: (qmail 64188 invoked by uid 500); 7 Feb 2005 06:59:30 -0000 Received: (qmail 64182 invoked by uid 500); 7 Feb 2005 06:59:30 -0000 Received: (qmail 64177 invoked by uid 99); 7 Feb 2005 06:59:30 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Sun, 06 Feb 2005 22:59:29 -0800 Received: (qmail 29386 invoked by uid 1992); 7 Feb 2005 06:59:28 -0000 Date: 7 Feb 2005 06:59:28 -0000 Message-ID: <20050207065928.29385.qmail@minotaur.apache.org> From: rwatler@apache.org To: jakarta-jetspeed-2-cvs@apache.org Subject: cvs commit: jakarta-jetspeed-2/portal/src/java/org/apache/jetspeed/tools/pamanager WarInfusionPAM.java FileSystemPAM.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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