sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1685721 - /sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
Date Tue, 16 Jun 2015 07:18:48 GMT
Author: cziegeler
Date: Tue Jun 16 07:18:48 2015
New Revision: 1685721

URL: http://svn.apache.org/r1685721
Log:
SLING-4809 : Filesystem classwriter does not delete directories

Modified:
    sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java

Modified: sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java?rev=1685721&r1=1685720&r2=1685721&view=diff
==============================================================================
--- sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
(original)
+++ sling/trunk/bundles/commons/fsclassloader/src/main/java/org/apache/sling/commons/fsclassloader/impl/FSClassLoaderProvider.java
Tue Jun 16 07:18:48 2015
@@ -27,6 +27,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
@@ -152,20 +154,35 @@ public class FSClassLoaderProvider
     }
 
     private void checkClassLoader(final String filePath) {
-        synchronized ( this ) {
-            final FSDynamicClassLoader currentLoader = this.loader;
-            if ( currentLoader != null && filePath.endsWith(".class") ) {
-                // remove store directory and .class
-                final String path = filePath.substring(this.root.getAbsolutePath().length()
+ 1, filePath.length() - 6);
-                // convert to a class name
-                final String className = path.replace(File.separatorChar, '.');
-                currentLoader.check(className);
+        if ( filePath.endsWith(".class") ) {
+            // remove store directory and .class
+            final String path = filePath.substring(this.root.getAbsolutePath().length() +
1, filePath.length() - 6);
+            // convert to a class name
+            final String className = path.replace(File.separatorChar, '.');
+
+            synchronized ( this ) {
+                final FSDynamicClassLoader currentLoader = this.loader;
+                if ( currentLoader != null ) {
+                    currentLoader.check(className);
+                }
             }
         }
     }
 
     //---------- SCR Integration ----------------------------------------------
 
+    private boolean deleteRecursive(final File f, final List<String> names) {
+        if ( f.isDirectory() ) {
+            for(final File c : f.listFiles()) {
+                if ( !deleteRecursive(c, names) ) {
+                    return false;
+                }
+            }
+        }
+        names.add(f.getAbsolutePath());
+        return f.delete();
+    }
+
     /**
      * @see org.apache.sling.commons.classloader.ClassLoaderWriter#delete(java.lang.String)
      */
@@ -173,10 +190,13 @@ public class FSClassLoaderProvider
         final String path = cleanPath(name);
         final File file = new File(path);
         if ( file.exists() ) {
-            final boolean result = file.delete();
-            logger.debug("Deleted {} : {}", name,result);
+            final List<String> names = new ArrayList<String>();
+            final boolean result = deleteRecursive(file, names);
+            logger.debug("Deleted {} : {}", name, result);
             if ( result ) {
-                this.checkClassLoader(file.getAbsolutePath());
+                for(final String n : names ) {
+                    this.checkClassLoader(n);
+                }
             }
 
             return result;



Mime
View raw message