summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2020-01-17 12:48:41 +0100
committerSimon Rettberg2020-01-17 12:48:41 +0100
commit805c69cbf378205406659a3680f80eb48cb90c6f (patch)
treedb2320730b5bcf2454d821dd77d120c7470c0014 /src
parent[WakeOnLan] Native Java implementation (diff)
downloadtmlite-bwlp-805c69cbf378205406659a3680f80eb48cb90c6f.tar.gz
tmlite-bwlp-805c69cbf378205406659a3680f80eb48cb90c6f.tar.xz
tmlite-bwlp-805c69cbf378205406659a3680f80eb48cb90c6f.zip
[Symlink] Don't follow symlinks when deleting old link source
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/Symlink.java24
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" )