From 6f2a29f0d520e6eaa3af77bdf707b74c0ee0b862 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Wed, 9 Oct 2013 17:24:08 +0200 Subject: [PATCH] Implement ascii-only --- atom | 24 ++++++++++++++++++------ lib/copy/matching | 40 ++++++++++++++++++++-------------------- lib/files/getDestDir | 5 +++++ lib/files/getDestFile | 6 ++++++ 4 files changed, 49 insertions(+), 26 deletions(-) diff --git a/atom b/atom index bcacbf4..03b417d 100755 --- a/atom +++ b/atom @@ -301,6 +301,7 @@ then Renaming to ASCII-only disabled" >&2 unset destinationascii destinationascii=0 + textunidecodeneeded=0 (( sanitywarn++ )) fi if (( sanityfail )) @@ -503,6 +504,8 @@ do done (( cron )) || echo -n 'Creating tasks... ' +(( textunidecodeneeded )) && ascii + echo 'BEGIN TRANSACTION;' >&3 for line in "${decodefiles[@]}" do @@ -591,6 +594,9 @@ echo 'COMMIT;' >&3 (( cron )) || echo -n $'\r' echo "Created ${count:-0} tasks for $filecount files ${togo:+($togo left) }(${copies:-0} immediate copies)" +# remove perl unicode to ascii coprocess +(( textunidecodeneeded )) && eval exec "${toascii[1]}>&-" + concurrency=$(( maxload / 2 )) (( concurrency )) || concurrency=1 active=0 @@ -764,7 +770,6 @@ then exit fi -#set -x for destination in "${!destinationpath[@]}" do echo ' @@ -792,14 +797,18 @@ do INNER JOIN source_files ON destination_files.source_file_id =source_files.id + INNER JOIN mime_actions + ON source_files.mime_type + =mime_actions.mime_type WHERE destinations.name="'"$destination"'" AND (destination_files.rename_pattern != "'"${destinationrenamepath[$destination]}/${destinationrename[$destination]}"'" - OR fat32compat != ${destinationfat32compat["$destination"]} - OR ascii != ${destinationascii["$destination"]} + OR fat32compat != '${destinationfat32compat["$destination"]}' + OR ascii != '${destinationascii["$destination"]}' OR destination_files.rename_pattern is NULL) AND destination_files.last_change > 0 + AND mime_actions.action=1 ; SELECT "AtOM:NoMoreFiles"; @@ -819,6 +828,7 @@ do 'vorbis') extension=ogg ;; esac (( cron )) || echo -n "$destination: rename pattern changed, renaming files... " + (( textunidecodeneeded )) && ascii echo 'BEGIN TRANSACTION;' >&3 for line in "${renamefiles[@]}" do @@ -863,9 +873,9 @@ do echo "UPDATE destination_files" \ "SET filename=\"${destfilename//\"/\"\"}\"," \ " rename_pattern=" \ -"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}" \ - " fat32compat=" -"${destinationfat32compat["$destination"]}\"" \ +"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\","\ + " fat32compat=" \ +"${destinationfat32compat["$destination"]}," \ " ascii=" \ "${destinationascii["$destination"]}" \ "WHERE id=$destfileid;" \ @@ -877,6 +887,8 @@ do fi fi done + # remove perl unicode to ascii coprocess + (( textunidecodeneeded )) && eval exec "${toascii[1]}>&-" echo 'COMMIT;' >&3 (( cron )) || echo -n $'\r' echo -n "$destination: Renamed ${changedcount:-0} files" diff --git a/lib/copy/matching b/lib/copy/matching index 6c52329..b0f6516 100644 --- a/lib/copy/matching +++ b/lib/copy/matching @@ -8,26 +8,26 @@ copyFiles_matching() { || cp -a \ "$sourcepath/$filename" \ "$destdir/$destfile.$extension" - echo \ - "UPDATE destination_files" \ - "SET filename=" \ - "\"${destdir//\"/\"\"}/${destfile//\"/\"\"}.$extension\"," \ - " last_change=(" \ - " SELECT last_change" \ - " FROM source_files" \ - " WHERE id=$fileid" \ - " )," \ - " old_filename=(" \ - " SELECT filename" \ - " FROM destination_files" \ - " WHERE id=$destfileid" \ - " )," \ - " rename_pattern" \ -"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\""\ - " fat32compat" \ - " ${destinationfat32compat["$destination"]}"\ - " ascii ${destinationascii["$destination"]}"\ - "WHERE id=$destfileid;" \ + echo \ + "UPDATE destination_files" \ + "SET filename=" \ + "\"${destdir//\"/\"\"}/${destfile//\"/\"\"}.$extension\"," \ + " last_change=(" \ + " SELECT last_change" \ + " FROM source_files" \ + " WHERE id=$fileid" \ + " )," \ + " old_filename=(" \ + " SELECT filename" \ + " FROM destination_files" \ + " WHERE id=$destfileid" \ + " )," \ + " rename_pattern=" \ +"\"${destinationrenamepath[$destination]}/${destinationrename[$destination]}\","\ + " fat32compat=" \ + "${destinationfat32compat["$destination"]}," \ + " ascii=${destinationascii["$destination"]}" \ + "WHERE id=$destfileid;" \ >&3 (( ++copies )) } diff --git a/lib/files/getDestDir b/lib/files/getDestDir index f28fb49..8ac3714 100644 --- a/lib/files/getDestDir +++ b/lib/files/getDestDir @@ -64,6 +64,11 @@ getDestDir() { part=${part#*/} done fi + if (( ${destinationascii["$destination"]} )) + then + echo "$destdir" >&${toascii[1]} + read -r -u${toascii[0]} destdir + fi if ! [ -d "$destdir" ] then mkdir -p "$destdir" diff --git a/lib/files/getDestFile b/lib/files/getDestFile index 41c2003..aae78b8 100644 --- a/lib/files/getDestFile +++ b/lib/files/getDestFile @@ -36,6 +36,7 @@ getDestFile() { && [ -n "$disc" ] ) ) + then destfile="${destinationrename[$destination]//?(\[)%\{album\}?(\])/$album}" destfile="${destfile//?(\[)%\{albumartist\}?(\])/$albumartist}" destfile="${destfile//?(\[)%\{artist\}?(\])/$artist}" @@ -49,5 +50,10 @@ getDestFile() { destfile="${filename##*/}" destfile="${destfile%.*}" fi + if (( ${destinationascii["$destination"]} )) + then + echo "$destfile" >&${toascii[1]} + read -r -u${toascii[0]} destfile + fi destfile=$(sanitizeFile "$destfile") }