From 30e26c16266130446b4aa4ae3356bdb5df1dcb83 Mon Sep 17 00:00:00 2001 From: 6543 Date: Fri, 8 Feb 2019 00:43:40 +0100 Subject: [PATCH] imprufe db/import-md5-list --- tools/db/import-md5-list | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/db/import-md5-list b/tools/db/import-md5-list index 0875792..d058b0f 100755 --- a/tools/db/import-md5-list +++ b/tools/db/import-md5-list @@ -78,7 +78,9 @@ function md5_in_add() { local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) local name=$(echo $relrevpath | cut -d '/' -f 1 | rev) local folder=$(echo $relrevpath | cut -d '/' -f 2- | rev) - db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_EXIST );" #-> handle in future: ";'()" + [ "$(db_query "SELECT COUNT(ID) FROM File WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';")" == "0" ] && { #wenn KEIN gleicher Eintrag Vorhanden + db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_EXIST );" #-> handle in future: ";'()" + } done exit 0 @@ -104,7 +106,12 @@ function md5_in_del() { local relrevpath=$(echo $path | sed "s|^$moviedir||g" | sed 's|^/||g' | sed 's|/$||g' | rev) local name=$(echo $relrevpath | cut -d '/' -f 1 | rev) local folder=$(echo $relrevpath | cut -d '/' -f 2- | rev) - db_query "UPDATE File SET TTSync=$TTSYNC_DEL WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';" #-> handle in future: ";'()" + + if [ "$(db_query "SELECT COUNT(ID) FROM File WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';")" -gt "0" ]; then #wenn gleicher Eintrag Vorhanden + db_query "UPDATE File SET TTSync=$TTSYNC_DEL WHERE MD5='$md5' AND Folder='$folder' AND Name='$name';" #-> handle in future: ";'()" + else #Ansonsten Erstelle Del eintrag + db_query "INSERT INTO File (MD5, Folder, Name, TTSync) VALUES ('$md5', '$folder', '$name', $TTSYNC_DEL );" #-> handle in future: ";'()" + fi done exit 0