_ remove surplus logs

_ use SHA256
pull/1/head
io42630 3 years ago
parent 0dbcf8de45
commit c34e6d85aa

@ -39,7 +39,7 @@ public class Flow implements Runnable {
); );
} }
try { try {
LOGGER.info("Pausing... for " + POLLING_PAUSE + "ms."); LOGGER.info("Sleeping... for " + POLLING_PAUSE + "ms.");
Thread.sleep(POLLING_PAUSE); Thread.sleep(POLLING_PAUSE);
} catch (InterruptedException ignored) { } catch (InterruptedException ignored) {
LOGGER.info("Thread interrupted."); LOGGER.info("Thread interrupted.");

@ -124,9 +124,9 @@ public class SyncDirectory {
).collect(Collectors.toMap(Entry::getKey, Entry::getValue)); ).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
} }
private String getMd5(Path path) { private String getHash(Path path) {
try (var fos = new FileInputStream(path.toFile())) { try (var fos = new FileInputStream(path.toFile())) {
var m = MessageDigest.getInstance("MD5"); var m = MessageDigest.getInstance("SHA256");
byte[] data = fos.readAllBytes(); byte[] data = fos.readAllBytes();
m.update(data, 0, data.length); m.update(data, 0, data.length);
var i = new BigInteger(1, m.digest()); var i = new BigInteger(1, m.digest());
@ -155,7 +155,7 @@ public class SyncDirectory {
outputList.add(line); outputList.add(line);
}); });
LOGGER.info("Writing " + outputList.size() + " files to " + record.getPath()); LOGGER.info("Writing " + outputList.size() + " files to Record: " + record.getPath());
tools.writeStringListToFile(record.getPath().toString(), outputList); tools.writeStringListToFile(record.getPath().toString(), outputList);
} }
@ -233,14 +233,14 @@ public class SyncDirectory {
* Overwrite other file if this file is newer. * Overwrite other file if this file is newer.
*/ */
private void writeFileIfNewer(SyncFile thisFile, SyncFile otherFile) { private void writeFileIfNewer(SyncFile thisFile, SyncFile otherFile) {
LOGGER.info("Write from: " + thisFile.toPath()); LOGGER.info("Try write from: " + thisFile.toPath());
LOGGER.info(" to: " + otherFile.toPath()); LOGGER.info(" to: " + otherFile.toPath());
if (!thisFile.isFile()) { return; } if (!thisFile.isFile()) { return; }
if (otherFile.exists()) { if (otherFile.exists()) {
var thisMd5 = getMd5(thisFile.toPath()); var thisHash = getHash(thisFile.toPath());
var otherMd5 = getMd5(otherFile.toPath()); var otherHash = getHash(otherFile.toPath());
if (thisMd5 == null || otherMd5 == null) { return; } if (thisHash == null || otherHash == null) { return; }
if (thisMd5.equals(otherMd5)) { if (thisHash.equals(otherHash)) {
dropAge(thisFile, otherFile); dropAge(thisFile, otherFile);
return; return;
} else if (thisFile.isOlder(otherFile)) { } else if (thisFile.isOlder(otherFile)) {
@ -254,10 +254,10 @@ public class SyncDirectory {
private void dropAge(SyncFile thisFile, SyncFile otherFile) { private void dropAge(SyncFile thisFile, SyncFile otherFile) {
if (thisFile.isOlder(otherFile)) { if (thisFile.isOlder(otherFile)) {
otherFile.setLastModified(thisFile.lastModified()); otherFile.setLastModified(thisFile.lastModified());
LOGGER.info("Dropped age of OTHER: " + otherFile.toPath() + " to: " + otherFile.lastModified()); LOGGER.info("Dropped age of: " + otherFile.toPath() + " -> " + otherFile.lastModified());
} else { } else {
thisFile.setLastModified(otherFile.lastModified()); thisFile.setLastModified(otherFile.lastModified());
LOGGER.info("Dropped age of THIS: " + thisFile.toPath() + " to: " + thisFile.lastModified()); LOGGER.info("Dropped age of: " + thisFile.toPath() + " -> " + thisFile.lastModified());
} }
} }

@ -42,7 +42,6 @@ public class SyncFile extends File {
} }
public boolean isNewer(SyncFile otherFile) { public boolean isNewer(SyncFile otherFile) {
LOGGER.info("" + this.lastModified() + " >= " + otherFile.lastModified());
return this.lastModified() >= otherFile.lastModified(); return this.lastModified() >= otherFile.lastModified();
} }

Loading…
Cancel
Save