diff --git a/README.md b/README.md
index 6110d7b..fb0f7a3 100644
--- a/README.md
+++ b/README.md
@@ -30,6 +30,16 @@ DataRoot a data root
+
+### Flow
+* `for` each `SyncBundle`
+ * `for` each `SyncDirectory`
+ * check what files were CRUD,
+ * propagate to other `SyncDirectory` of current `SyncBundle`.
+
+
+
+
### Demo
[](https://youtu.be/znR3jyM_4Ss "ensync WIP Demo")
diff --git a/pom.xml b/pom.xml
index a4334ca..03a88f8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,150 +1,145 @@
-
-
- 4.0.0
-
- com.olexyn.ensync
- ensync
- 0.1
-
- ensync
- http://www.example.com
-
-
- UTF-8
- 7.3.1
- ${vaadin.version}
- false
- 1.11
- 1.11
- 1.6.20-RC2
-
-
-
-
- junit
- junit
- 4.11
- test
-
-
- org.json
- json
- 20190722
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- commons-io
- commons-io
- 2.11.0
-
-
-
-
-
-
-
-
- maven-clean-plugin
- 3.1.0
-
-
-
- maven-resources-plugin
- 3.0.2
-
-
- maven-compiler-plugin
- 3.8.0
-
-
- maven-surefire-plugin
- 2.22.1
-
-
- maven-jar-plugin
- 3.0.2
-
-
- maven-install-plugin
- 2.5.2
-
-
- maven-deploy-plugin
- 2.8.2
-
-
-
- maven-site-plugin
- 3.7.1
-
-
- maven-project-info-reports-plugin
- 3.0.0
-
-
-
-
-
- org.jetbrains.kotlin
- kotlin-maven-plugin
- ${kotlin.version}
-
-
- compile
- compile
-
- compile
-
-
-
- test-compile
- test-compile
-
- test-compile
-
-
-
-
- 1.8
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- compile
- compile
-
- compile
-
-
-
- testCompile
- test-compile
-
- testCompile
-
-
-
-
-
-
+
+ 4.0.0
+ com.olexyn.ensync
+ ensync
+ 0.1
+ ensync
+
+ UTF-8
+ 7.3.1
+ ${vaadin.version}
+ false
+ 18
+ 18
+ 1.6.20-RC2
+
+
+
+ junit
+ junit
+ 4.11
+ test
+
+
+ org.json
+ json
+ 20190722
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ org.jetbrains.kotlin
+ kotlin-test
+ ${kotlin.version}
+ test
+
+
+ org.jetbrains.kotlin
+ kotlin-stdlib-jdk8
+ ${kotlin.version}
+
+
+ commons-io
+ commons-io
+ 2.11.0
+
+
+ com.olexyn.min.log
+ min-log
+ 0.1.1
+ compile
+
+
+
+
+
+
+ maven-clean-plugin
+ 3.1.0
+
+
+ maven-resources-plugin
+ 3.0.2
+
+
+ maven-compiler-plugin
+ 3.8.0
+
+
+ maven-surefire-plugin
+ 2.22.1
+
+
+ maven-jar-plugin
+ 3.0.2
+
+
+ maven-install-plugin
+ 2.5.2
+
+
+ maven-deploy-plugin
+ 2.8.2
+
+
+ maven-site-plugin
+ 3.7.1
+
+
+ maven-project-info-reports-plugin
+ 3.0.0
+
+
+
+
+
+ org.jetbrains.kotlin
+ kotlin-maven-plugin
+ ${kotlin.version}
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ test-compile
+ test-compile
+
+ test-compile
+
+
+
+
+ 18
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ compile
+ compile
+
+ compile
+
+
+
+ testCompile
+ test-compile
+
+ testCompile
+
+
+
+
+
+
diff --git a/src/main/java/com/olexyn/ensync/Execute.java b/src/main/java/com/olexyn/ensync/Execute.java
deleted file mode 100644
index e92f362..0000000
--- a/src/main/java/com/olexyn/ensync/Execute.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package com.olexyn.ensync;
-
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
-import java.util.List;
-
-public class Execute {
-
-
- /**
- * @param cmd an array representing a shell command
- * @return TwoBr class, containing two BufferedReaders,
- * output and error
- * @see output BufferedReader, corresponds to STDOUT
- * error BufferedReader, corresponds to STDERR
- */
- public TwoBr execute(String cmd[]) {
- TwoBr twobr = new TwoBr();
- try {
- Process process = Runtime.getRuntime().exec(cmd);
- process.waitFor();
- twobr.output = new BufferedReader(new InputStreamReader(process.getInputStream()));
- twobr.error = new BufferedReader(new InputStreamReader(process.getErrorStream()));
- } catch (Exception e) {
- e.printStackTrace();
- }
- return twobr;
- }
-
-
- public TwoBr execute(List cmd) {
-
- String[] cmdArr = new String[cmd.size()];
- for (int i = 0; i < cmd.size(); i++) {
- cmdArr[i] = cmd.get(i);
- }
-
- return execute(cmdArr);
- }
-
- public void executeBatch(List batch) {
-
- for (String[] strings : batch) {
- execute(strings);
- }
-
- }
-
-
- public class TwoBr {
- public BufferedReader output;
- public BufferedReader error;
- }
-}
diff --git a/src/main/java/com/olexyn/ensync/Flow.java b/src/main/java/com/olexyn/ensync/Flow.java
index 95892c8..0c75587 100644
--- a/src/main/java/com/olexyn/ensync/Flow.java
+++ b/src/main/java/com/olexyn/ensync/Flow.java
@@ -4,21 +4,19 @@ import com.olexyn.ensync.artifacts.DataRoot;
import com.olexyn.ensync.artifacts.Record;
import com.olexyn.ensync.artifacts.SyncDirectory;
import com.olexyn.ensync.lock.LockKeeper;
+import com.olexyn.min.log.LogU;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.logging.Logger;
import java.util.stream.Collectors;
public class Flow implements Runnable {
- private static final Logger LOGGER = LogUtil.get(Flow.class);
-
public static final long POLLING_PAUSE = 100;
private final AtomicBoolean running = new AtomicBoolean(false);
public void start() {
- LOGGER.info("START Flow.");
+ LogU.infoStart("Flow");
Thread worker = new Thread(this, "FLOW_WORKER");
worker.start();
}
@@ -48,10 +46,10 @@ public class Flow implements Runnable {
);
}
try {
- LOGGER.info("Sleeping... for " + POLLING_PAUSE + "ms.");
+ LogU.infoPlain("Sleeping... for %sms", POLLING_PAUSE);
Thread.sleep(POLLING_PAUSE);
} catch (InterruptedException ignored) {
- LOGGER.info("Thread interrupted.");
+ LogU.warnPlain("Thread interrupted.");
}
}
}
@@ -60,19 +58,21 @@ public class Flow implements Runnable {
*
*/
private void sync(SyncDirectory sDir) {
- LOGGER.info("DO SYNC " + sDir.directoryPath);
+ LogU.infoPlain("DO SYNC %s", sDir.directoryPath);
var listFileSystem = sDir.readFileSystem();
- LOGGER.info("# FS: " + listFileSystem.size());
+ LogU.infoPlain("# FS: %s", listFileSystem.size());
var record = new Record(sDir.directoryPath);
record.getFiles().putAll(sDir.readRecord());
- LOGGER.info("# Record: " + record.getFiles().size());
+ LogU.infoPlain("# Record: %s", record.getFiles().size());
var listCreated = sDir.fillListOfLocallyCreatedFiles(listFileSystem, record);
- LOGGER.info("# Created: " + listCreated.size());
var listDeleted = sDir.makeListOfLocallyDeletedFiles(listFileSystem, record);
- LOGGER.info("# Deleted: " + listDeleted.size());
var listModified = sDir.makeListOfLocallyModifiedFiles(listFileSystem, record);
- LOGGER.info("# Modified: " + listModified.size());
+ Tools tools = new Tools();
+ int newly = tools.setMinus(listCreated.keySet(), listDeleted.keySet()).size();
+ LogU.infoPlain("# Created: %s\n thereof newly created (not mv) %s", listCreated.size(), newly);
+ LogU.infoPlain("# Deleted: %s", listDeleted.size());
+ LogU.infoPlain("# Modified: %s", listModified.size());
sDir.doCreateOpsOnOtherSDs(listCreated);
sDir.doDeleteOpsOnOtherSDs(listDeleted);
diff --git a/src/main/java/com/olexyn/ensync/LogUtil.java b/src/main/java/com/olexyn/ensync/LogUtil.java
deleted file mode 100644
index ee3d121..0000000
--- a/src/main/java/com/olexyn/ensync/LogUtil.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package com.olexyn.ensync;
-
-
-import java.io.IOException;
-import java.util.Date;
-import java.util.logging.FileHandler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-import java.util.logging.SimpleFormatter;
-
-
-
-public class LogUtil {
-
- private static final String format = "[%1$tF %1$tT] [%4$-7s] %5$-100s [%2$s]\n";
-
- public static Logger get(Class> c) {
- return get(c, Level.INFO);
- }
-
- public static Logger get(Class> c, Level level) {
- System.setProperty("java.util.logging.SimpleFormatter.format", format);
- Logger logger = Logger.getLogger(c.getName());
- try {
- String dir = System.getProperty("user.dir") + "/logs/main.log";
- FileHandler fh = new FileHandler(dir, true);
- fh.setFormatter(new SimpleFormatter() {
- @Override
- public synchronized String format(LogRecord logRecord) {
- String msg = logRecord.getMessage();
- return String.format(format,
- new Date(logRecord.getMillis()),
- logRecord.getSourceClassName() + " " + logRecord.getSourceMethodName(),
- "",
- logRecord.getLevel().getLocalizedName(),
- msg
- );
- }
- });
-
- logger.addHandler(fh);
- logger.setLevel(level);
- } catch (NullPointerException | IOException e) {
- e.printStackTrace();
- }
- return logger;
- }
-
-}
diff --git a/src/main/java/com/olexyn/ensync/MainApp.java b/src/main/java/com/olexyn/ensync/MainApp.java
index 9e9c212..8974d03 100644
--- a/src/main/java/com/olexyn/ensync/MainApp.java
+++ b/src/main/java/com/olexyn/ensync/MainApp.java
@@ -4,6 +4,7 @@ import com.olexyn.ensync.artifacts.DataRoot;
import com.olexyn.ensync.artifacts.SyncBundle;
import com.olexyn.ensync.lock.LockUtil;
import com.olexyn.ensync.util.IgnoreUtil;
+import com.olexyn.min.log.LogU;
import org.json.JSONException;
import org.json.JSONObject;
@@ -17,6 +18,7 @@ public class MainApp {
final private static Tools TOOLS = new Tools();
public static void main(String[] args) throws JSONException {
+ LogU.remake(null, "com.olexyn.ensync.", "[%1$tF %1$tT] [%2$-7s] [%3$-10s] %4$-180s [%5$s]\n");
var configPath = Path.of(System.getProperty("user.dir") + "/src/main/resources/config.json");
String configString = Tools.fileToString(LockUtil.lockFile(configPath).getFc());
diff --git a/src/main/java/com/olexyn/ensync/OperationMode.java b/src/main/java/com/olexyn/ensync/OperationMode.java
deleted file mode 100644
index 1d81975..0000000
--- a/src/main/java/com/olexyn/ensync/OperationMode.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.olexyn.ensync;
-
-public enum OperationMode {
- JAVA_FX,
- JSON
-}
diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java
index 5f321f4..1d72cd1 100644
--- a/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java
+++ b/src/main/java/com/olexyn/ensync/artifacts/SyncDirectory.java
@@ -1,9 +1,9 @@
package com.olexyn.ensync.artifacts;
-import com.olexyn.ensync.LogUtil;
import com.olexyn.ensync.Tools;
import com.olexyn.ensync.lock.LockKeeper;
import com.olexyn.ensync.util.IgnoreUtil;
+import com.olexyn.min.log.LogU;
import org.apache.commons.io.FileUtils;
import java.io.File;
@@ -21,8 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -34,7 +32,6 @@ import static com.olexyn.ensync.artifacts.Constants.RECORD_SEPARATOR;
*/
public class SyncDirectory {
- private static final Logger LOGGER = LogUtil.get(SyncDirectory.class);
private final SyncBundle syncMap;
public Path directoryPath;
Tools tools = new Tools();
@@ -136,7 +133,7 @@ public class SyncDirectory {
var i = new BigInteger(1, m.digest());
return String.format("%1$032X", i);
} catch (Exception e) {
- LOGGER.log(Level.INFO, "Failed to create Hash.", e);
+ LogU.warnPlain("Failed to create Hash.\n%s", e.getMessage());
return null;
}
}
@@ -159,7 +156,7 @@ public class SyncDirectory {
outputList.add(line);
});
- LOGGER.info("Writing " + outputList.size() + " files to Record: " + record.getPath());
+ LogU.infoPlain("Writing " + outputList.size() + " files to Record: " + record.getPath());
tools.writeStringListToFile(record.getPath().toString(), outputList);
}
@@ -173,7 +170,7 @@ public class SyncDirectory {
.filter(file -> IgnoreUtil.noIgnore(file.toPath()))
.filter(file -> !file.getName().equals(Constants.STATE_FILE_NAME));
} catch (IOException e) {
- LOGGER.severe("Could walk the file tree : Record will be empty.");
+ LogU.warnPlain("Could walk the file tree : Record will be empty.");
return Stream.empty();
}
}
@@ -187,11 +184,14 @@ public class SyncDirectory {
}
public void doDeleteOpsOnOtherSDs(Map listDeleted) {
+ int deleteCount = 0;
for (var deletedFile : listDeleted.values()) {
for (var otherFile : otherFiles(deletedFile)) {
- deleteFileIfNewer(deletedFile, otherFile);
+ var ok = deleteFileIfNewer(deletedFile, otherFile);
+ if (ok) { deleteCount++; }
}
}
+ LogU.infoPlain("DELETED " + deleteCount + "/" + listDeleted.size() + " Files.");
}
public void doModifyOpsOnOtherSDs(Map listModified) {
@@ -214,26 +214,31 @@ public class SyncDirectory {
* Here the >= is crucial, since otherFile might have == modified,
* but in that case we still want to delete both files.
*/
- private void deleteFileIfNewer(RecordFile thisFile, SyncFile otherFile) {
+ private boolean deleteFileIfNewer(RecordFile thisFile, SyncFile otherFile) {
if (!otherFile.exists()) {
- LOGGER.info("Could not delete: " + otherFile.toPath() + " not found.");
- return; }
+ LogU.infoPlain("Not deleted (not found) " + otherFile.toPath() + " not found.");
+ return false;
+ }
if (thisFile.lastModified() >= otherFile.lastModified()) {
try {
Files.delete(otherFile.toPath());
- LOGGER.info("Deleted: " + otherFile.toPath());
+ LogU.infoPlain("Deleted " + otherFile.toPath());
+ return true;
} catch (IOException e) {
- LOGGER.info("Could not delete: " + otherFile.toPath());
+ LogU.infoPlain("Not deleted (IOE) " + otherFile.toPath());
+ return false;
}
}
+ LogU.infoPlain("Not deleted (other file modified recently)");
+ return false;
}
/**
* Overwrite other file if this file is newer.
*/
private void writeFileIfNewer(SyncFile thisFile, SyncFile otherFile) {
- LOGGER.info("Try write from: " + thisFile.toPath());
- LOGGER.info(" to: " + otherFile.toPath());
+ LogU.infoPlain("Try write from: " + thisFile.toPath());
+ LogU.infoPlain(" to: " + otherFile.toPath());
if (!thisFile.isFile()) { return; }
if (otherFile.exists()) {
var thisHash = getHash(thisFile.toPath());
@@ -243,7 +248,7 @@ public class SyncDirectory {
dropAge(thisFile, otherFile);
return;
} else if (thisFile.lastModified() <= otherFile.lastModified()) {
- LOGGER.info("Did not override due to target being newer.");
+ LogU.infoPlain("Did not override due to target being newer.");
return;
}
}
@@ -252,15 +257,15 @@ public class SyncDirectory {
private void dropAge(SyncFile thisFile, SyncFile otherFile) {
if (thisFile.lastModified() == otherFile.lastModified()) {
- LOGGER.info("Same age, ignore");
+ LogU.infoPlain("Same age, ignore");
return;
}
if (thisFile.lastModified() < otherFile.lastModified()) {
otherFile.setLastModified(thisFile.lastModified());
- LOGGER.info("Dropped age of: " + otherFile.toPath() + " -> " + otherFile.lastModified());
+ LogU.infoPlain("Dropped age of: %s -> %s",otherFile.toPath(), otherFile.lastModified());
} else {
thisFile.setLastModified(otherFile.lastModified());
- LOGGER.info("Dropped age of: " + thisFile.toPath() + " -> " + thisFile.lastModified());
+ LogU.infoPlain("Dropped age of: %s -> %s",thisFile.toPath(), thisFile.lastModified());
}
}
@@ -269,7 +274,7 @@ public class SyncDirectory {
try {
FileUtils.createParentDirectories(otherFile);
} catch (IOException e) {
- LOGGER.info("Could not create Parent");
+ LogU.warnPlain("Could not create Parent");
}
}
var thisFc = LockKeeper.getFc(thisFile.toPath());
@@ -280,14 +285,15 @@ public class SyncDirectory {
) {
copyStream(is, os);
} catch (Exception e) {
- LOGGER.severe("Could not copy file from: " + thisFile.toPath());
- LOGGER.severe(" to: " + otherFile.toPath());
+ LogU.warnPlain("Could not copy file from: %s", thisFile.toPath());
+ LogU.warnPlain(" to: %s", otherFile.toPath());
e.printStackTrace();
}
- LOGGER.info(thisFile.toPath() + " "+ thisFile.lastModified());
- LOGGER.info(otherFile.toPath() + " " + otherFile.lastModified());
+
+ LogU.infoPlain(thisFile.toPath() + " "+ thisFile.lastModified());
+ LogU.infoPlain(otherFile.toPath() + " " + otherFile.lastModified());
otherFile.setLastModified(thisFile.lastModified());
- LOGGER.info(otherFile.toPath() + " " + otherFile.lastModified());
+ LogU.infoPlain(otherFile.toPath() + " " + otherFile.lastModified());
}
public static void copyStream(InputStream input, OutputStream output)
diff --git a/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java b/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java
index a4a467e..b0748d4 100644
--- a/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java
+++ b/src/main/java/com/olexyn/ensync/artifacts/SyncFile.java
@@ -1,15 +1,13 @@
package com.olexyn.ensync.artifacts;
-import com.olexyn.ensync.LogUtil;
+import com.olexyn.min.log.LogU;
import java.io.File;
-import java.util.logging.Logger;
import static com.olexyn.ensync.artifacts.Constants.EMPTY;
public class SyncFile extends File {
- private static final Logger LOGGER = LogUtil.get(SyncFile.class);
private final String relativePath;
private final SyncDirectory sDir;
@@ -36,8 +34,8 @@ public class SyncFile extends File {
@Override
public long lastModified(){
if (exists()) { return super.lastModified(); }
- LOGGER.info("Did not find File for " + this);
- LOGGER.info("Returning -1 (never existed).");
+ LogU.infoPlain("Did not find File for " + this);
+ LogU.infoPlain("Returning -1 (never existed).");
return -1;
}
diff --git a/src/main/java/com/olexyn/ensync/lock/LockKeeper.java b/src/main/java/com/olexyn/ensync/lock/LockKeeper.java
index ab2fd93..df9cb54 100644
--- a/src/main/java/com/olexyn/ensync/lock/LockKeeper.java
+++ b/src/main/java/com/olexyn/ensync/lock/LockKeeper.java
@@ -1,7 +1,7 @@
package com.olexyn.ensync.lock;
-import com.olexyn.ensync.LogUtil;
import com.olexyn.ensync.util.IgnoreUtil;
+import com.olexyn.min.log.LogU;
import java.io.IOException;
import java.nio.channels.FileChannel;
@@ -10,15 +10,12 @@ import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.logging.Logger;
import java.util.stream.Collectors;
public class LockKeeper {
private static final int TRY_COUNT = 4;
- private static final Logger LOGGER = LogUtil.get(LockKeeper.class);
-
private final static Map LOCKS = new HashMap<>();
public static boolean lockDir(Path dirPath) {
@@ -32,7 +29,7 @@ public class LockKeeper {
} catch (IOException e) {
return false;
}
- LOGGER.info("LOCKED " + fcStates.size() + " files in " + dirPath);
+ LogU.infoPlain("LOCKED " + fcStates.size() + " files in " + dirPath);
fcStates.forEach(fcState -> LOCKS.put(fcState.getPath(), fcState));
return fcStates.stream().noneMatch(FcState::isUnlocked);
}
@@ -40,7 +37,7 @@ public class LockKeeper {
public static void unlockAll() {
- LOGGER.info("UNLOCKING ALL.");
+ LogU.infoPlain("UNLOCKING ALL.");
LOCKS.values().forEach(
fcState -> LockUtil.unlockFile(fcState.getPath(), fcState.getFc(), 4)
);
diff --git a/src/main/java/com/olexyn/ensync/lock/LockUtil.java b/src/main/java/com/olexyn/ensync/lock/LockUtil.java
index 7bd2518..4d61a73 100644
--- a/src/main/java/com/olexyn/ensync/lock/LockUtil.java
+++ b/src/main/java/com/olexyn/ensync/lock/LockUtil.java
@@ -1,34 +1,28 @@
package com.olexyn.ensync.lock;
-import com.olexyn.ensync.LogUtil;
+import com.olexyn.min.log.LogU;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.nio.channels.OverlappingFileLockException;
import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import static java.nio.file.StandardOpenOption.APPEND;
import static java.nio.file.StandardOpenOption.CREATE_NEW;
import static java.nio.file.StandardOpenOption.READ;
import static java.nio.file.StandardOpenOption.WRITE;
-import static java.util.logging.Level.INFO;
public class LockUtil {
private static final int DEFAULT_LOCK_TRIES = 4;
private static final long SLEEP_DURATION = 1000;
- private static final Logger LOGGER = LogUtil.get(LockUtil.class);
public static FcState newFile(Path filePath) {
try {
var fc = FileChannel.open(filePath, CREATE_NEW, WRITE);
return new FcState(filePath, fc, false);
} catch (IOException | OverlappingFileLockException e) {
- LOGGER.log(INFO, "Could not NEW " + filePath, e);
+ LogU.warnPlain("Could not NEW %s\n%s", filePath, e.getMessage());
return new FcState(filePath, null, false);
}
}
@@ -47,13 +41,13 @@ public class LockUtil {
} catch (IOException | OverlappingFileLockException e) {
if (tryCount > 0) {
tryCount--;
- LOGGER.info("Could not lock " + filePath + " Will try " + tryCount + " times.");
+ LogU.warnPlain("Could not lock %s. Will try %s times.", filePath, tryCount);
try {
Thread.sleep(SLEEP_DURATION);
} catch (InterruptedException ignored) { }
return lockFile(filePath, tryCount);
}
- LOGGER.log(INFO, "Could not lock " + filePath, e);
+ LogU.warnPlain("Could not lock %s\n%s", filePath, e.getMessage());
return new FcState(filePath, null, false);
}
}
@@ -70,10 +64,11 @@ public class LockUtil {
} catch (IOException | OverlappingFileLockException e) {
if (tryCount > 0) {
tryCount--;
- LOGGER.info("Could not close " + fc + " Will try " + tryCount + " times.");
+ LogU.warnPlain("Could not close %s. Will try %s times.", fc, tryCount);
+
return unlockFile(filePath, fc, tryCount);
}
- LOGGER.info("Could not unlock " + fc);
+ LogU.warnPlain("Could not unlock %s", fc);
return new FcState(filePath, null, true);
}
}
diff --git a/src/main/resources/syncignore b/src/main/resources/syncignore
index a461512..943b6e6 100644
--- a/src/main/resources/syncignore
+++ b/src/main/resources/syncignore
@@ -4,4 +4,5 @@ collection/books
collection/movies
collection/music
collection/software
+collection/tv
collection/youtube
\ No newline at end of file
diff --git a/src/test/java/com/olexyn/ensync/files/FifteenTests.java b/src/test/java/com/olexyn/ensync/files/FifteenTests.java
index 159c8c9..46e2ae0 100644
--- a/src/test/java/com/olexyn/ensync/files/FifteenTests.java
+++ b/src/test/java/com/olexyn/ensync/files/FifteenTests.java
@@ -1,11 +1,11 @@
package com.olexyn.ensync.files;
import com.olexyn.ensync.Flow;
-import com.olexyn.ensync.LogUtil;
import com.olexyn.ensync.Tools;
import com.olexyn.ensync.artifacts.DataRoot;
import com.olexyn.ensync.artifacts.SyncBundle;
import com.olexyn.ensync.lock.LockUtil;
+import com.olexyn.min.log.LogU;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import org.junit.Assert;
@@ -20,7 +20,6 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
-import java.util.logging.Logger;
/**
@@ -29,7 +28,6 @@ import java.util.logging.Logger;
*/
public class FifteenTests {
- private static final Logger LOGGER = LogUtil.get(FifteenTests.class);
final public static Flow FLOW = new Flow();
@@ -48,40 +46,40 @@ public class FifteenTests {
private List createFile(File file) {
if (file.exists()) {
- LOGGER.info("TEST can not create existing: " + file.toPath());
+ LogU.infoPlain("TEST can not create existing: " + file.toPath());
Assert.fail();
}
List stringList = new ArrayList<>();
stringList.add(LocalDateTime.now().format(dateTimeFormatter) + " CREATED");
tools.writeStringListToFile(file.getAbsolutePath(), stringList);
- LOGGER.info("TEST CREATE: " + file.toPath());
+ LogU.infoPlain("TEST CREATE: " + file.toPath());
return stringList;
}
private List modifyFile(File file) {
- LOGGER.info("TEST TRY MODIFY: " + file.toPath());
+ LogU.infoPlain("TEST TRY MODIFY: " + file.toPath());
var fcState = LockUtil.lockFile(file.toPath(), 10);
var stringList = new ArrayList<>(tools.fileToLines(fcState.getFc()));
stringList.add(LocalDateTime.now().format(dateTimeFormatter) + " MODIFIED");
tools.writeStringListToFile(file.getAbsolutePath(), stringList);
- LOGGER.info("TEST MODIFY: " + file.toPath());
+ LogU.infoPlain("TEST MODIFY: " + file.toPath());
LockUtil.unlockFile(fcState, 10);
- LOGGER.info("TEST MODIFY UNLOCKED: " + file.toPath());
+ LogU.infoPlain("TEST MODIFY UNLOCKED: " + file.toPath());
return stringList;
}
private static void deleteFile(File file) {
- LOGGER.info("TEST TRY DELETE: " + file.toPath());
+ LogU.infoPlain("TEST TRY DELETE: " + file.toPath());
var fcState = LockUtil.lockFile(file.toPath(), 10);
try {
Files.delete(file.toPath());
- LOGGER.info("TEST DELETE: " + file.toPath());
+ LogU.infoPlain("TEST DELETE: " + file.toPath());
} catch (IOException e) {
- LOGGER.severe("Could not delete file." + file.toPath());
+ LogU.warnPlain("Could not delete file." + file.toPath());
}
LockUtil.unlockFile(fcState, 10);
- LOGGER.info("TEST DELETE UNLOCKED: " + file.toPath());
+ LogU.infoPlain("TEST DELETE UNLOCKED: " + file.toPath());
}
private void cleanDirs(Path... dirs) {
@@ -90,7 +88,7 @@ public class FifteenTests {
FileUtils.deleteDirectory(dir.toFile());
Files.createDirectory(dir);
} catch (IOException e) {
- LOGGER.severe("Could not clear dirs. " + dir + e.getMessage());
+ LogU.warnPlain("Could not clear dirs. " + dir + e.getMessage());
}
}
}
diff --git a/src/test/java/com/olexyn/ensync/files/TestFile.java b/src/test/java/com/olexyn/ensync/files/TestFile.java
index 9c3f901..0216f6c 100644
--- a/src/test/java/com/olexyn/ensync/files/TestFile.java
+++ b/src/test/java/com/olexyn/ensync/files/TestFile.java
@@ -1,21 +1,15 @@
package com.olexyn.ensync.files;
-import com.olexyn.ensync.LogUtil;
import com.olexyn.ensync.Tools;
-import com.olexyn.ensync.artifacts.SyncDirectory;
-import com.olexyn.ensync.lock.LockKeeper;
import com.olexyn.ensync.lock.LockUtil;
+import com.olexyn.min.log.LogU;
import java.io.File;
-import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
-import java.util.logging.Logger;
public class TestFile extends File {
- private static final Logger LOGGER = LogUtil.get(TestFile.class);
-
Tools tools = new Tools();
/**
@@ -26,7 +20,7 @@ public class TestFile extends File {
}
public List readContent() {
- LOGGER.info("TEST TRY READ: " + toPath());
+ LogU.infoPlain("TEST TRY READ: " + toPath());
var fcState = LockUtil.lockFile(toPath());
return tools.fileToLines(fcState.getFc());
}