You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dw...@apache.org on 2007/10/04 19:51:28 UTC

svn commit: r581975 - in /geronimo/server/branches/2.0/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

Author: dwoods
Date: Thu Oct  4 10:51:25 2007
New Revision: 581975

URL: http://svn.apache.org/viewvc?rev=581975&view=rev
Log:
GERONIMO-3489 Deployment problems caused by file deletion failures

Modified:
    geronimo/server/branches/2.0/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java
    geronimo/server/branches/2.0/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java

Modified: geronimo/server/branches/2.0/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java?rev=581975&r1=581974&r2=581975&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java (original)
+++ geronimo/server/branches/2.0/modules/geronimo-kernel/src/main/java/org/apache/geronimo/kernel/config/IOUtil.java Thu Oct  4 10:51:25 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/branches/2.0/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.0/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java?rev=581975&r1=581974&r2=581975&view=diff
==============================================================================
--- geronimo/server/branches/2.0/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java (original)
+++ geronimo/server/branches/2.0/modules/geronimo-system/src/main/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java Thu Oct  4 10:51:25 2007
@@ -173,9 +173,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);
         }