_ 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 {
LOGGER.info("Pausing... for " + POLLING_PAUSE + "ms.");
LOGGER.info("Sleeping... for " + POLLING_PAUSE + "ms.");
Thread.sleep(POLLING_PAUSE);
} catch (InterruptedException ignored) {
LOGGER.info("Thread interrupted.");

@ -124,9 +124,9 @@ public class SyncDirectory {
).collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}
private String getMd5(Path path) {
private String getHash(Path path) {
try (var fos = new FileInputStream(path.toFile())) {
var m = MessageDigest.getInstance("MD5");
var m = MessageDigest.getInstance("SHA256");
byte[] data = fos.readAllBytes();
m.update(data, 0, data.length);
var i = new BigInteger(1, m.digest());
@ -155,7 +155,7 @@ public class SyncDirectory {
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);
}
@ -233,14 +233,14 @@ public class SyncDirectory {
* Overwrite other file if this file is newer.
*/
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());
if (!thisFile.isFile()) { return; }
if (otherFile.exists()) {
var thisMd5 = getMd5(thisFile.toPath());
var otherMd5 = getMd5(otherFile.toPath());
if (thisMd5 == null || otherMd5 == null) { return; }
if (thisMd5.equals(otherMd5)) {
var thisHash = getHash(thisFile.toPath());
var otherHash = getHash(otherFile.toPath());
if (thisHash == null || otherHash == null) { return; }
if (thisHash.equals(otherHash)) {
dropAge(thisFile, otherFile);
return;
} else if (thisFile.isOlder(otherFile)) {
@ -254,10 +254,10 @@ public class SyncDirectory {
private void dropAge(SyncFile thisFile, SyncFile otherFile) {
if (thisFile.isOlder(otherFile)) {
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 {
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) {
LOGGER.info("" + this.lastModified() + " >= " + otherFile.lastModified());
return this.lastModified() >= otherFile.lastModified();
}

Loading…
Cancel
Save