From 00de0a03cc9f5c8d8011820c5000c285dc1b49d3 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 11 May 2019 02:58:47 +0200 Subject: [PATCH] WIP --- tools/db/update-file-state | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/db/update-file-state b/tools/db/update-file-state index 0ee8313..f6f3b8e 100644 --- a/tools/db/update-file-state +++ b/tools/db/update-file-state @@ -78,7 +78,6 @@ function main() { db_query "SELECT ID FROM File Where TTCheck < '$DATE' OR TTCheck IS NULL;" | while read line; do #for each ID with an old check date ... ID=$line - TTSync=$(db_query "SELECT TTSync FROM File WHERE ID=$ID;") FILE=$(db_query "SELECT CONCAT('$moviedir/', Folder, '/', Name) FROM File WHERE ID=$ID;") if [ -f "$FILE" ]; then SIZE=$(db_query "SELECT Size FROM File WHERE ID=$ID;") @@ -156,10 +155,25 @@ function file_add() { local name="$(echo "$relrevpath" | cut -d '/' -f 1 | rev)" local folder="$(echo "$relrevpath" | cut -d '/' -f 2- | rev)" local FILE="$moviedir/$(echo "$relrevpath" | rev)" - [ -f "$FILE" ] || return 1 #errer file not exist + [ -f "$FILE" ] || { + echo "ERROR: file_add: file not exist: $FILE" + return 1 + } [ -z "$MD5" ] && MD5="$(md5sum "$FILE" | cut -c -32)" local SIZE="$(file_size "$FILE")" + #check if already exist + IDs=($(db_query "SELECT ID FROM File WHERE Name='$name' AND Folder='$folder' AND MD5='$MD5';")) + #wenn einmal existiert ... + [ "${#IDs[@]}" == 1 ] && { + [ "$(db_query "SELECT TTSync From File WHERE ID='${IDs[0]}';")" == $TTSYNC_DEL ] && db_query "UPDATE File SET TTSync=$TTSYNC_EXIST WHERE ID='${IDs[0]}';" + db_query "UPDATE File SET TTCheck='$DATE' WHERE ID='${IDs[0]}';" + } + [ "${#IDs[@]}" -gt 1 ] && + ID=$i + echo "INFO: exists ... " + + done #db path exist && md5 same -> update this entry #db path exist && ttsync=exist/backup && md5 !same -> ttsync=del + new db entry #or new db entry