diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/org/openslx/taskmanager/tasks/Symlink.java | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/Symlink.java b/src/main/java/org/openslx/taskmanager/tasks/Symlink.java index 7a6a3bd..44919fc 100644 --- a/src/main/java/org/openslx/taskmanager/tasks/Symlink.java +++ b/src/main/java/org/openslx/taskmanager/tasks/Symlink.java @@ -59,7 +59,7 @@ public class Symlink extends AbstractTask @Override protected boolean execute() { - FileUtils.deleteQuietly( new File( linkname ) ); + deleteRecursiveIfExists( new File( linkname ) ); if ( this.target != null ) { try { Files.createSymbolicLink( Paths.get( this.linkname ), Paths.get( this.target ) ); @@ -72,6 +72,28 @@ public class Symlink extends AbstractTask } /** + * Recursively deletes `item`, which may be a directory. + * Symbolic links will be deleted instead of their referents. + * Returns a boolean indicating whether `item` still exists. + * http://stackoverflow.com/questions/8666420 + */ + public static boolean deleteRecursiveIfExists( File item ) + { + if ( !item.exists() ) + return true; + boolean ret = true; + if ( !Files.isSymbolicLink( item.toPath() ) && item.isDirectory() ) { + File[] subitems = item.listFiles(); + for ( File subitem : subitems ) { + if ( !deleteRecursiveIfExists( subitem ) ) { + ret = false; + } + } + } + return item.delete() && ret; + } + + /** * Output - contains additional status data of this task */ @SuppressWarnings( "unused" ) |