From 055ba6dec09e499b6a2f8bbcd5f88858b95d8374 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Sat, 25 May 2013 15:35:04 +0200 Subject: [PATCH] Copy more reliably when path change is not set --- lib/copy/copyFiles_action | 63 ++++++++++++++++++--------------------- lib/copy/guessPath | 28 +++++++++++++++++ 2 files changed, 57 insertions(+), 34 deletions(-) create mode 100644 lib/copy/guessPath diff --git a/lib/copy/copyFiles_action b/lib/copy/copyFiles_action index a944ef8..0134eb5 100644 --- a/lib/copy/copyFiles_action +++ b/lib/copy/copyFiles_action @@ -43,42 +43,37 @@ copyFiles_action() { rest=${rest#*::AtOM:SQL:Sep::} destfileid=${rest%%::AtOM:SQL:Sep::*} rest=${rest#*::AtOM:SQL:Sep::} - echo 'SELECT IFNULL( ( - SELECT destination_files.filename - 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 mime_type_actions.action = 1 - LIMIT 1 - ),"AtOM:NotFound"); - '>&3 - read -u4 filename - if [[ $filename != AtOM:NotFound ]] - then - destdir=${filename%/*} - if cp -al "$sourcepath/$sourcefilename" "$destdir" 2>/dev/null\ - || cp -a "$sourcepath/$sourcefilename" "$destdir" - then - Update destination_files \ - filename "$destdir/${sourcefilename##*/}"\ - rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}:${destinationfat32compat["$destination"]}"\ - last_change $lastchange \ - <<-EOWhere - id = $destfileid - EOWhere - (( done++ )) - fi - fi (( count++ )) printf '\b\b\b\b%3i%%' $(( (count * 100) / ${#copyfiles[@]} )) + if [ -n "${renamepath["$destination"]}" ] + then + destdir="$(guessPath)" || continue + else + destdir="${destinationpath["$destination"]}/" + destdir+=$(sanitizeFile "${sourcefilename%%/*}" dir) + part=${sourcefilename#*/} + while [[ $part =~ / ]] + do + destdir+="/$(sanitizeFile "${part%%/*}" dir)" + part=${part#*/} + done + if ! [ -d "$destdir" ] + then + mkdir -p "$destdir" + fi + fi + if cp -al "$sourcepath/$sourcefilename" "$destdir" 2>/dev/null\ + || cp -a "$sourcepath/$sourcefilename" "$destdir" + then + Update destination_files \ + filename "$destdir/${sourcefilename##*/}"\ + rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}:${destinationfat32compat["$destination"]}"\ + last_change $lastchange \ + <<-EOWhere + id = $destfileid + EOWhere + (( done++ )) + fi done echo 'COMMIT;' >&3 echo -e "\rCopied ${done:-0} of $count files.\033[K" diff --git a/lib/copy/guessPath b/lib/copy/guessPath new file mode 100644 index 0000000..ccb0e4b --- /dev/null +++ b/lib/copy/guessPath @@ -0,0 +1,28 @@ +#!/bin/bash + +guessPath() { + echo 'SELECT IFNULL( ( + SELECT destination_files.filename + 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 mime_type_actions.action = 1 + LIMIT 1 + ),"AtOM:NotFound"); + '>&3 + read -u4 filename + if [[ $filename != AtOM:NotFound ]] + then + echo "${filename%/*}" + else + return 1 + fi +}