Skip to content

Commit

Permalink
SLING-4809 : Filesystem classwriter does not delete directories
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1685721 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
cziegeler committed Jun 16, 2015
1 parent 4e7e2c7 commit 015b7c3
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
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;
Expand Down Expand Up @@ -152,31 +154,49 @@ public ClassLoader getClassLoader() {
}

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)
*/
public boolean delete(final String name) {
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;
Expand Down

0 comments on commit 015b7c3

Please sign in to comment.