diff --git a/src/main/java/com/olexyn/ensync/Tools.java b/src/main/java/com/olexyn/ensync/Tools.java index def6a10..f383d99 100644 --- a/src/main/java/com/olexyn/ensync/Tools.java +++ b/src/main/java/com/olexyn/ensync/Tools.java @@ -1,19 +1,16 @@ package com.olexyn.ensync; -import com.olexyn.ensync.artifacts.SyncFile; -import com.olexyn.ensync.lock.LockKeeper; - -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; public class Tools { @@ -51,7 +48,7 @@ public class Tools { } - public Set setMinus(Set fromA, Set subtractB) { + public static Set setMinus(Set fromA, Set subtractB) { Set difference = new HashSet<>(); for (var key : fromA) { if (fromA.contains(key) && !subtractB.contains(key)) { diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java index ae9680f..69f25f0 100644 --- a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java +++ b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java @@ -2,6 +2,7 @@ package com.olexyn.ensync.artifacts; import com.olexyn.ensync.Tools; import com.olexyn.ensync.lock.LockKeeper; +import com.olexyn.ensync.util.HashUtil; import com.olexyn.ensync.util.IgnoreUtil; import com.olexyn.min.log.LogU; import org.apache.commons.io.FileUtils; @@ -10,11 +11,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.math.BigInteger; import java.nio.channels.Channels; import java.nio.file.Files; import java.nio.file.Path; -import java.security.MessageDigest; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -90,7 +89,7 @@ public class SyncDirectory { * List is cleared and created each time. */ public Map fillListOfLocallyCreatedFiles(Map listFileSystem, Record record) { - var listCreated = tools.setMinus(listFileSystem.keySet(), record.getFiles().keySet()); + var listCreated = Tools.setMinus(listFileSystem.keySet(), record.getFiles().keySet()); return listCreated.stream().collect(Collectors.toMap(key -> key, listFileSystem::get)); } @@ -98,8 +97,8 @@ public class SyncDirectory { * Compare the OLD and NEW pools. * List is cleared and created each time. */ - public Map makeListOfLocallyDeletedFiles(Map listFileSystem, Record record) { - var listDeleted = tools.setMinus(record.getFiles().keySet(), listFileSystem.keySet()); + public Map makeListOfLocallyDeletedFiles(Map listFileSystem, Record record) { + var listDeleted = Tools.setMinus(record.getFiles().keySet(), listFileSystem.keySet()); return listDeleted.stream().collect(Collectors.toMap(key -> key, key -> record.getFiles().get(key))); } @@ -165,7 +164,7 @@ public class SyncDirectory { } } - public void doDeleteOpsOnOtherSDs(Map listDeleted) { + public void doDeleteOpsOnOtherSDs(Map listDeleted) { int deleteCount = 0; for (var deletedFile : listDeleted.values()) { for (var otherFile : otherFiles(deletedFile)) { @@ -196,7 +195,7 @@ public class SyncDirectory { * Here the >= is crucial, since otherFile might have == modified, * but in that case we still want to delete both files. */ - private boolean deleteFileIfNewer(RecordFile thisFile, SyncFile otherFile) { + private boolean deleteFileIfNewer(SyncFile thisFile, SyncFile otherFile) { if (!otherFile.exists()) { LogU.infoPlain("Not deleted (not found) " + otherFile.toPath() + " not found."); return false;