From 3c19f1cf97e9a8868311f2edc9667b52085dbccc Mon Sep 17 00:00:00 2001 From: Ivan Olexyn Date: Sun, 17 May 2020 17:23:55 +0200 Subject: [PATCH] + omit sub-dirs in makeListDeleted. no need to run rm -r for every sub-dir --- .../ensync/artifacts/SyncDirectory.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/com/olexyn/ensync/artifacts/SyncDirectory.java index 4d4bf58..a7b7c75 100644 --- a/src/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -115,7 +115,24 @@ public class SyncDirectory { Map substractB = readFreshState(); listDeleted = tools.mapMinus(fromA, substractB); - + + Map swap = new HashMap<>(); + + + for (var entry : listDeleted.entrySet()) { + + String key = entry.getKey(); + String parentKey = entry.getValue().getParent(); + + + if (listDeleted.containsKey(parentKey) || swap.containsKey(parentKey)) { + swap.put(key, listDeleted.get(key)); + } + } + + listDeleted = tools.mapMinus(listDeleted, swap); + + } @@ -133,7 +150,7 @@ public class SyncDirectory { String freshFileKey = freshFileEntry.getKey(); SyncFile freshFile = freshFileEntry.getValue(); - if(freshFile.isDirectory()){ continue;} // no need to modify Directories, the Filesystem will do that, if a File changed. + if (freshFile.isDirectory()) { continue;} // no need to modify Directories, the Filesystem will do that, if a File changed. // If KEY exists in OLD , thus FILE was NOT created. if (stateFileMap.containsKey(freshFileKey)) { @@ -193,11 +210,6 @@ public class SyncDirectory { this.otherParentFile = new File(otherParentPath); - - - - - } } @@ -225,7 +237,7 @@ public class SyncDirectory { */ public void doDelete() { - for (var entry: listDeleted.entrySet()) { + for (var entry : listDeleted.entrySet()) { SyncFile deletedFile = entry.getValue(); for (var otherEntry : syncMap.syncDirectories.entrySet()) { @@ -241,7 +253,7 @@ public class SyncDirectory { } } - private void deleteFile(Info info, SyncDirectory thisSD, SyncFile thisFile, SyncDirectory otherSD){ + private void deleteFile(Info info, SyncDirectory thisSD, SyncFile thisFile, SyncDirectory otherSD) { SyncFile otherFile = new SyncFile(otherSD, otherSD.path + thisFile.relativePath); @@ -298,7 +310,6 @@ public class SyncDirectory { } - }