From fa779b300e237e79d5b487ab4bd0e7e0ae6362a2 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Tue, 28 Aug 2018 14:55:08 -0700 Subject: [PATCH] Move duplicate (case difference) files into corrupt/ Signed-off-by: James Ketrenos --- server/scanner.js | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/server/scanner.js b/server/scanner.js index c525fcb..e16f4fc 100644 --- a/server/scanner.js +++ b/server/scanner.js @@ -13,6 +13,26 @@ const picturesPath = config.get("picturesPath"); const processQueue = [], triedClean = []; +function removeNewerFile(path, fileA, fileB) { + fs.stat(path + "/" + fileA, function(err, statsA) { + if (err) { + return; + } + fs.stat(path + "/" + fileB, function(err, statsB) { + if (err) { + return; + } + if (statsA.mtime > statsB.mtime) { + console.log("Removing file by moving to 'corrupt':" + fileA); + moveCorrupt(path, fileA); + } else { + console.log("Removing file by moving to 'corrupt':" + fileB); + moveCorrupt(path, fileB); + } + }); + }); +} + function scanDir(parent, path) { let extensions = [ "jpg", "jpeg", "png", "gif", "nef" ], re = new RegExp("\.((" + extensions.join(")|(") + "))$", "i"), @@ -73,11 +93,18 @@ function scanDir(parent, path) { /* Remove 'thumbs' and 'raw' directories from being processed */ files = files.filter(function(file) { for (var i = 0; i < files.length; i++) { - /* If this file has an original NEF on the system, don't add the JPG to the - * DB */ + /* If this file has an original NEF on the system, don't add the JPG to the DB */ if (/\.nef$/i.exec(files[i]) && file == files[i].replace(/\.nef$/i, ".jpg")) { return false; } + + /* If there is a different CASE (eg. JPG vs jpg) don't add it, and remove the 'lower case' + * version from disk. */ + if (file != files[i] && file.toUpperCase() == files[i]) { + removeNewerFile(path, file, files[i]); + console.log("Duplicate file in " + path + ": ", file, files[i]); + return false; + } } return file != "raw" && file != "thumbs" && file != ".git" && file != "corrupt"; @@ -225,7 +252,10 @@ function convertNefToJpg(path, file) { } function moveCorrupt(path, file) { - path = picturesPath + path; + if (path.indexOf(picturesPath) != 0) { + path = picturesPath + path; + } + console.warn("Moving corrupt file '" + file + "' to " + path + "/corrupt"); return mkdirPromise(path + "/corrupt").then(function() {