Move duplicate (case difference) files into corrupt/
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
57bd5a7683
commit
fa779b300e
@ -13,6 +13,26 @@ const picturesPath = config.get("picturesPath");
|
|||||||
|
|
||||||
const processQueue = [], triedClean = [];
|
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) {
|
function scanDir(parent, path) {
|
||||||
let extensions = [ "jpg", "jpeg", "png", "gif", "nef" ],
|
let extensions = [ "jpg", "jpeg", "png", "gif", "nef" ],
|
||||||
re = new RegExp("\.((" + extensions.join(")|(") + "))$", "i"),
|
re = new RegExp("\.((" + extensions.join(")|(") + "))$", "i"),
|
||||||
@ -73,11 +93,18 @@ function scanDir(parent, path) {
|
|||||||
/* Remove 'thumbs' and 'raw' directories from being processed */
|
/* Remove 'thumbs' and 'raw' directories from being processed */
|
||||||
files = files.filter(function(file) {
|
files = files.filter(function(file) {
|
||||||
for (var i = 0; i < files.length; i++) {
|
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
|
/* If this file has an original NEF on the system, don't add the JPG to the DB */
|
||||||
* DB */
|
|
||||||
if (/\.nef$/i.exec(files[i]) && file == files[i].replace(/\.nef$/i, ".jpg")) {
|
if (/\.nef$/i.exec(files[i]) && file == files[i].replace(/\.nef$/i, ".jpg")) {
|
||||||
return false;
|
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";
|
return file != "raw" && file != "thumbs" && file != ".git" && file != "corrupt";
|
||||||
@ -225,7 +252,10 @@ function convertNefToJpg(path, file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function moveCorrupt(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");
|
console.warn("Moving corrupt file '" + file + "' to " + path + "/corrupt");
|
||||||
|
|
||||||
return mkdirPromise(path + "/corrupt").then(function() {
|
return mkdirPromise(path + "/corrupt").then(function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user