Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 26440 invoked from network); 4 Oct 2007 17:50:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Oct 2007 17:50:07 -0000 Received: (qmail 55590 invoked by uid 500); 4 Oct 2007 17:49:56 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 55544 invoked by uid 500); 4 Oct 2007 17:49:56 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 55515 invoked by uid 99); 4 Oct 2007 17:49:56 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Oct 2007 10:49:56 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Oct 2007 17:50:06 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 6D1111A9832; Thu, 4 Oct 2007 10:49:16 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r581974 - in /geronimo/server/trunk/modules: geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java Date: Thu, 04 Oct 2007 17:49:15 -0000 To: scm@geronimo.apache.org From: dwoods@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071004174916.6D1111A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dwoods Date: Thu Oct 4 10:49:13 2007 New Revision: 581974 URL: http://svn.apache.org/viewvc?rev=581974&view=rev Log: GERONIMO-3489 Deployment problems caused by file deletion failures Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java Modified: geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java?rev=581974&r1=581973&r2=581974&view=diff ============================================================================== --- geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java (original) +++ geronimo/server/trunk/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java Thu Oct 4 10:49:13 2007 @@ -36,10 +36,14 @@ import java.util.jar.JarFile; import java.util.zip.ZipEntry; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + /** * @version $Rev$ $Date$ */ public class IOUtil { + private final static Log log = LogFactory.getLog(IOUtil.class); public static void recursiveCopy(File srcDir, File destDir) throws IOException { if (srcDir == null) throw new NullPointerException("sourceDir is null"); if (destDir == null) throw new NullPointerException("destDir is null"); @@ -99,6 +103,57 @@ } out.flush(); } + + private static void listFiles(File directory) { + if (!log.isDebugEnabled() || !directory.isDirectory()) { + return; + } + File[] files = directory.listFiles(); + log.debug(directory.getPath() + " has " + files.length + " files:"); + for (File file : files) { + log.debug(file.getPath()); + } + } + + private static boolean deleteFile(File file) { + boolean fileDeleted = file.delete(); + if (fileDeleted) { + return true; + } + + // special retry code to handle occasional Windows JDK and Unix NFS timing failures + int retryLimit = 5; + int retries; + int interruptions = 0; + for (retries = 1; !fileDeleted && retries <= retryLimit; retries++) { + if (log.isDebugEnabled()) { + listFiles(file); + } + System.runFinalization(); + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + interruptions++; + } + System.gc(); + try { + Thread.sleep(1000); + } catch (InterruptedException ie) { + interruptions++; + } + fileDeleted = file.delete(); + } + if (fileDeleted) { + if (log.isDebugEnabled()) { + log.debug(file.getPath() + " deleted after " + retries + + " retries, with " + interruptions + " interruptions."); + } + } else { + log.warn(file.getPath() + " not deleted after " + retryLimit + + " retries, with " + interruptions + " interruptions."); + } + return fileDeleted; + } public static boolean recursiveDelete(File root) { if (root == null) { @@ -113,12 +168,12 @@ if (file.isDirectory()) { recursiveDelete(file); } else { - file.delete(); + deleteFile(file); } } } } - return root.delete(); + return deleteFile(root); } public static void flush(OutputStream thing) { Modified: geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java?rev=581974&r1=581973&r2=581974&view=diff ============================================================================== --- geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java (original) +++ geronimo/server/trunk/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java Thu Oct 4 10:49:13 2007 @@ -174,9 +174,31 @@ } File location = repository.getLocation(configId); if (location.exists()) { - throw new ConfigurationAlreadyExistsException("Configuration already exists: " + configId); + boolean isEmptyDirectory = false; + if (location.isDirectory()) { + File[] files = location.listFiles(); + isEmptyDirectory = files.length < 1; + if (!isEmptyDirectory && log.isDebugEnabled()) { + log.debug(location.getPath() + " has " + files.length + " files:"); + for (File file : files) { + log.debug(file.getPath()); + } + } + } + if (isEmptyDirectory) { + if (log.isDebugEnabled()) { + log.debug(location.getPath() + " is empty"); + } + } else { + log.error(location.getPath() + " is not an empty directory"); + throw new ConfigurationAlreadyExistsException("Configuration already exists: " + configId); + } + } else { + if (log.isDebugEnabled()) { + log.debug("Creating configuration directory: " + location.getPath()); + } + location.mkdirs(); } - location.mkdirs(); if (!location.exists()) { throw new ConfigurationAlreadyExistsException("Could not create configuration directory: " + location); }