diff --git a/tools/db/update-file-state b/tools/db/update-file-state index 7edc73f..1c1dbc0 100644 --- a/tools/db/update-file-state +++ b/tools/db/update-file-state @@ -77,7 +77,7 @@ function main() { 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 + if [ -f "$FILE" ]; then SIZE=$(db_query "SELECT Size FROM File WHERE ID=$ID;") SIZE_new="$(file_size "$FILE")" [ "$SIZE" != "$SIZE_new" ] && { @@ -85,7 +85,7 @@ function main() { if [ "0" == "$SIZE_new" ]; then #file exist but empty #rm "$FILE" <- secure? 2check - db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck=$DATE WHERE ID=$ID;" + db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck='$DATE' WHERE ID=$ID;" else #recalc md5 ... + check #update DB @@ -93,18 +93,18 @@ function main() { MD5=$(db_query "SELECT MD5 FROM File WHERE ID=$ID;") if [ "$MD5" == "$MD5_new" ]; then - db_query "UPDATE File SET Size=$SIZE_new,TTCheck=$DATE WHERE ID=$ID;" + db_query "UPDATE File SET Size=$SIZE_new,TTCheck='$DATE' WHERE ID=$ID;" else #new file/file changed! - db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck=$DATE WHERE ID=$ID;" - file_add "$(db_query "SELECT CONCAT(Folder, '/', Name) FROM File WHERE ID=$ID;")" + db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck='$DATE' WHERE ID=$ID;" + file_add "$(db_query "SELECT CONCAT(Folder, '/', Name) FROM File WHERE ID=$ID;")" "$MD5_new" fi fi } else # file dont exist - db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck=$DATE WHERE ID=$ID;" + db_query "UPDATE File SET TTSync=$TTSYNC_DEL,TTCheck='$DATE' WHERE ID=$ID;" fi done @@ -146,15 +146,16 @@ function file_size() { fi } +# file_add [rel.path] (md5) function file_add() { - echo 2DO - local relrevpath="$(echo $1 | sed 's|^/||g' | sed 's|/$||g' | rev | sed "s/'/''/g")" #last statement set ' as '' so it wont have an evect in the sql statement - local name="$(echo $relrevpath | cut -d '/' -f 1 | rev)" - local folder="$(echo $relrevpath | cut -d '/' -f 2- | rev)" - local FILE="$moviedir/$(echo $relrevpath | rev)" + local MD5="$2" + local relrevpath="$(echo "$1" | sed 's|^/||g' | sed 's|/$||g' | rev | sed "s/'/''/g")" #last statement set ' as '' so it wont have an evect in the sql statement + 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 - local MD5_new=$(md5sum "$FILE" | cut -c -32) - local SIZE_new="$(file_size "$FILE")" + [ -z "$MD5" ] && MD5="$(md5sum "$FILE" | cut -c -32)" + local SIZE="$(file_size "$FILE")" #db path exist && md5 same -> update this entry #db path exist && ttsync=exist/backup && md5 !same -> ttsync=del + new db entry