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