From 3d715ef18e426e63a77e35a8e53854f5edc27c17 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 20 Nov 2013 13:02:38 +0100 Subject: [PATCH] fix file copy: don't copy files if we can't guess the destination path --- lib/copy/action | 17 ++++++++++++++--- lib/copy/guessPath | 28 ++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/copy/action b/lib/copy/action index 401f080..63e7d75 100644 --- a/lib/copy/action +++ b/lib/copy/action @@ -45,9 +45,19 @@ copyFiles_action() { rest=${rest#*::AtOM:SQL:Sep::} (( count++ )) (( cron )) || printf '\b\b\b\b%3i%%' $(( (count * 100) / ${#copyfiles[@]} )) - if [ -n "${renamepath["$destination"]}" ] + if [ -n "${destinationrenamepath["$destination"]}" ] then - destdir="$(guessPath)" || continue + destdir="$(guessPath)" + guessstatus=$? + case $guessstatus in + 1) + continue + ;; + 2) + (( postponed++ )) + continue + ;; + esac else destdir="${destinationpath["$destination"]}/" if [[ $sourcefilename =~ / ]] @@ -88,7 +98,8 @@ copyFiles_action() { if (( count )) then (( cron )) || echo -n $'\r' - echo -n "Copied ${done:-0} of $count files." + echo -n "Copied ${done:-0} of $count" \ + "files${postponed+ ($postponed postponed)}." (( cron )) || echo -en "\033[K" echo else diff --git a/lib/copy/guessPath b/lib/copy/guessPath index ccb0e4b..75e1914 100644 --- a/lib/copy/guessPath +++ b/lib/copy/guessPath @@ -1,6 +1,31 @@ #!/bin/bash guessPath() { + echo 'SELECT IFNULL( ( + SELECT destination_files.last_change + FROM destination_files + INNER JOIN source_files + ON destination_files.source_file_id=source_files.id + INNER JOIN mime_type_actions + ON + mime_type_actions.id=source_files.mime_type + INNER JOIN destinations + ON destinations.id=destination_files.destination_id + WHERE destinations.id = '$destinationid' + AND source_files.filename LIKE + "'"${sourcedir//\"/\"\"}"'/%" + AND NOT source_files.filename LIKE + "'"${sourcedir//\"/\"\"}"'/%/%" + AND mime_type_actions.action = 1 + ORDER BY destination_files.last_change DESC + LIMIT 1 + ),"0.0"); + '>&3 + read -u4 timestamp + if (( ${timestamp/./} == 0 )) + then + return 2 + fi echo 'SELECT IFNULL( ( SELECT destination_files.filename FROM destination_files @@ -14,7 +39,10 @@ guessPath() { WHERE destinations.id = '$destinationid' AND source_files.filename LIKE "'"${sourcedir//\"/\"\"}"'/%" + AND NOT source_files.filename LIKE + "'"${sourcedir//\"/\"\"}"'/%/%" AND mime_type_actions.action = 1 + ORDER BY destination_files.last_change DESC LIMIT 1 ),"AtOM:NotFound"); '>&3