diff --git a/CHANGELOG.md b/CHANGELOG.md index fb56627..699d062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Don't print useless information (stuff that handled 0 files and such) * Store transcoded file paths relative to their destination's root * Add missing error codes (used but not declared) +* Support for newline character in filenames # 1.0.4 ## `BREAKING CHANGES` diff --git a/atom b/atom index ef380a3..08c20b2 100755 --- a/atom +++ b/atom @@ -202,7 +202,7 @@ echo ' FROM destination_files WHERE source_file_id is NULL;' >&3 -read -u4 -d$'\0' removecount +read -u4 -d $'\0' removecount until (( ${#removefile[@]} == removecount )) do echo ' @@ -219,7 +219,7 @@ do SELECT "AtOM:NoMoreFiles"; ' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do removeFileId=${line%%::AtOM:SQL:Sep::*} @@ -227,7 +227,7 @@ do removeFileDestName=${line%%::AtOM:SQL:Sep::*} rest=${line#*::AtOM:SQL:Sep::} removefile[$removeFileId]="${destinationpath["$removeFileDestName"]}/${rest%%::AtOM:SQL:Sep::*}" - read -u4 -d$'\0' line + read -u4 -d $'\0' line done done @@ -387,7 +387,7 @@ echo ' <> CAST(source_files.last_change AS TEXT) AND mime_type_actions.destination_id = destinations.id AND mime_type_actions.action = 1;' >&3 -read -u4 -d$'\0' filecount +read -u4 -d $'\0' filecount if [ -n "$maxbatch" ] && (( maxbatch < filecount )) then (( togo = filecount - maxbatch )) @@ -436,11 +436,11 @@ echo ' (( maxbatch )) && echo "LIMIT $maxbatch" >&3 echo '; SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 -d$'\0' line +read -u4 -d $'\0' line while ! [[ $line = AtOM:NoMoreFiles ]] do decodefiles+=("$line::AtOM:SQL:Sep::") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done (( cron )) || echo -n $'Creating tasks...\033[K' @@ -776,11 +776,11 @@ then WHERE tasks.status = 2; SELECT "AtOM:NoMoreFiles";' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line while ! [[ $line = AtOM:NoMoreFiles ]] do failedtasks+=("$line") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done for line in "${failedtasks[@]}" do @@ -836,11 +836,11 @@ do SELECT "AtOM:NoMoreFiles"; ' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line while [[ $line != AtOM:NoMoreFiles ]] do renamefiles+=("$line") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done if (( ${#renamefiles[@]} )) then @@ -943,11 +943,11 @@ echo ' (( cron )) || echo -n 'Removing obsolete files...'$'\033[K' lines=() -read -u4 -d$'\0' line +read -u4 -d $'\0' line while [[ $line != AtOM:NoMoreFiles ]] do lines+=("$line") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done echo 'BEGIN TRANSACTION;' >&3 for line in "${lines[@]}" diff --git a/lib/copy/action b/lib/copy/action index f87f130..6911fab 100644 --- a/lib/copy/action +++ b/lib/copy/action @@ -22,11 +22,11 @@ copyFiles_action() { AND mime_type_actions.action = 2; SELECT "AtOM:NoMoreFiles";' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line while ! [[ $line = AtOM:NoMoreFiles ]] do copyfiles+=("$line") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done echo 'BEGIN TRANSACTION;' >&3 diff --git a/lib/copy/guessPath b/lib/copy/guessPath index 3b9705f..5e4fbc0 100644 --- a/lib/copy/guessPath +++ b/lib/copy/guessPath @@ -21,7 +21,7 @@ guessPath() { LIMIT 1 ),"0.0"); '>&3 - read -u4 -d$'\0' timestamp + read -u4 -d $'\0' timestamp if (( ${timestamp/./} == 0 )) then return 2 @@ -46,7 +46,7 @@ guessPath() { LIMIT 1 ),"AtOM:NotFound"); '>&3 - read -u4 -d$'\0' filename + read -u4 -d $'\0' filename if [[ $filename != AtOM:NotFound ]] then echo "${filename%/*}" diff --git a/lib/database/Select b/lib/database/Select index d2715d3..da0513d 100644 --- a/lib/database/Select +++ b/lib/database/Select @@ -26,7 +26,7 @@ Select() { "WHERE ${where_statement[@]})" \ ",'SQL::Select:not found'" \ ");" >&3 - read -u 4 -d$'\0' results + read -u 4 -r -d $'\0' results if ! [[ $results == "SQL::Select:not found" ]] then echo "$results" diff --git a/lib/database/open b/lib/database/open index f193a07..b287314 100644 --- a/lib/database/open +++ b/lib/database/open @@ -3,9 +3,12 @@ openDatabase() { [[ -f "$database" ]] || populate_db=1 rm -f "$tempdir"/sqlite.{in,out} mkfifo "$tempdir"/sqlite.{in,out} - sqlite3 -bail -newline $'\0' \ - "$database" \ - < "$tempdir/sqlite.in" \ + stdbuf -o0 sqlite3 -bail \ + -newline $'::AtOM:SQL:EOL::\n' \ + "$database" \ + < "$tempdir/sqlite.in" \ + | stdbuf -o0 \ + sed 's/::AtOM:SQL:EOL::/\x0/g;s/\(\x0\)\xA/\1/g' \ > "$tempdir/sqlite.out" & exec 3> "$tempdir"/sqlite.in exec 4< "$tempdir"/sqlite.out @@ -21,7 +24,7 @@ openDatabase() { echo 'PRAGMA recursive_triggers = ON;' >&3 echo 'PRAGMA temp_store = 2;' >&3 echo 'PRAGMA locking_mode = EXCLUSIVE;' >&3 - read -u4 -d $'\0' + read -u4 -r -d $'\0' unset REPLY checkDatabaseVersion } diff --git a/lib/database/upgradedatabase_1_2 b/lib/database/upgradedatabase_1_2 index d3268eb..7372630 100644 --- a/lib/database/upgradedatabase_1_2 +++ b/lib/database/upgradedatabase_1_2 @@ -18,11 +18,11 @@ FROM destination_files; SELECT "AtOM::NoMoreData";' >&3 - read -u4 -d$'\0' data + read -u4 -d $'\0' data while [[ $data != AtOM::NoMoreData ]] do datas+=( "$data" ) - read -u4 -d$'\0' data + read -u4 -d $'\0' data done echo 'BEGIN TRANSACTION;' >&3 for data in "${datas[@]}" diff --git a/lib/tags/update b/lib/tags/update index e6fe830..72f42a5 100644 --- a/lib/tags/update +++ b/lib/tags/update @@ -52,12 +52,12 @@ echo ' ; SELECT "AtOM:NoMoreFiles";' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line while ! [[ $line = AtOM:NoMoreFiles ]] do tagfiles+=("$line") (( filecount++ )) - read -u4 -d$'\0' line + read -u4 -d $'\0' line done echo 'BEGIN TRANSACTION;' >&3 for line in "${tagfiles[@]}" diff --git a/lib/tasks/gettaskinfos b/lib/tasks/gettaskinfos index 7604735..c8c85b0 100644 --- a/lib/tasks/gettaskinfos +++ b/lib/tasks/gettaskinfos @@ -10,7 +10,7 @@ gettaskinfos() { FROM tasks WHERE id='$1'; ' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line taskid=${line%%::AtOM:SQL:Sep::*} rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" sourcefileid=${rest%%::AtOM:SQL:Sep::*} diff --git a/lib/workers/create b/lib/workers/create index 02f69fb..084e269 100644 --- a/lib/workers/create +++ b/lib/workers/create @@ -2,7 +2,7 @@ createworker() { (( ++active )) - read -u4 -d$'\0' line + read -u4 -d $'\0' line taskid=${line%%::AtOM:SQL:Sep::*} rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" sourcefileid=${rest%%::AtOM:SQL:Sep::*} diff --git a/lib/workers/master b/lib/workers/master index c88a9d8..09b05bc 100644 --- a/lib/workers/master +++ b/lib/workers/master @@ -10,7 +10,7 @@ master() { WHERE status = 0; '>&3 - read -u4 -d$'\0' remaining + read -u4 -d $'\0' remaining if (( remaining == 0 )) then sleep 0.1 @@ -108,7 +108,7 @@ master() { LIMIT 1; '>&3 - read -u4 -d$'\0' ready + read -u4 -d $'\0' ready if (( ready > 0 )) then createworker @@ -194,7 +194,7 @@ master() { LIMIT 1; ' >&3 - read -u4 -d$'\0' ready + read -u4 -d $'\0' ready if (( active == 0 && ready == 0 )) then @@ -234,7 +234,7 @@ master() { WHERE status = 0; '>&3 - read -u4 -d$'\0' remaining + read -u4 -d $'\0' remaining done fi } diff --git a/toys/checkextensions b/toys/checkextensions index 6a59119..0c75217 100755 --- a/toys/checkextensions +++ b/toys/checkextensions @@ -121,7 +121,7 @@ getdstfiles() { ; SELECT "AtOM:NoMoreFiles"; '>&3 - while read -u4 -d$'\0' line + while read -u4 -d $'\0' line do if [[ $line == AtOM:NoMoreFiles ]] then @@ -159,7 +159,7 @@ renameFile() { fi } -while read -u4 -d$'\0' line +while read -u4 -d $'\0' line do if [[ $line == AtOM:NoMoreFiles ]] then diff --git a/toys/checkmissing b/toys/checkmissing index 8fd8010..2f75fe1 100755 --- a/toys/checkmissing +++ b/toys/checkmissing @@ -79,7 +79,7 @@ echo 'SELECT "AtOM:NoMoreFiles";' >&3 declare -a \ destination_names \ files -read -u4 -d$'\0' line +read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do id=${line%%::AtOM:SQL:Sep::*} diff --git a/toys/createindex b/toys/createindex index e934599..72066c8 100755 --- a/toys/createindex +++ b/toys/createindex @@ -274,7 +274,7 @@ fi echo 'SELECT IFNULL( (SELECT last_seen FROM source_files ORDER BY last_seen DESC LIMIT 1), 0);' >&3 -read -u4 -d$'\0' lastupdate +read -u4 -d $'\0' lastupdate if ! [[ "$output" == - ]] then @@ -369,11 +369,11 @@ COLLATE NOCASE; SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 -d$'\0' line +read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do files+=("$line") - read -u4 -d$'\0' line + read -u4 -d $'\0' line done for line in "${files[@]}" @@ -675,7 +675,7 @@ echo ' SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 -d$'\0' line +read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do artist="${line%%::AtOM:SQL:Sep::*}" @@ -685,7 +685,7 @@ do artists+=( "$artist" ) maxcountlen=$(( ${#count} > maxcountlen ? ${#count} : maxcountlen )) maxartistlen=$(( ${#artist} > maxartistlen ? ${#artist} : maxartistlen )) - read -u4 -d$'\0' line + read -u4 -d $'\0' line done head=$( printf "| # | %'${maxcoutlen}s | %-${maxartistlen}s |" \ @@ -714,7 +714,7 @@ echo ' FROM source_files INNER JOIN mime_types ON source_files.mime_type=mime_types.id;' >&3 -read -u4 -d$'\0' line +read -u4 -d $'\0' line totalcount="${line%%::AtOM:SQL:Sep::*}" maxcountlen=$(printf "%'i" $totalcount) maxcountlen=${#maxcountlen} @@ -743,7 +743,7 @@ do INNER JOIN mime_types ON source_files.mime_type=mime_types.id WHERE mime_text LIKE "'"$format"'";' >&3 - read -u4 -d$'\0' line + read -u4 -d $'\0' line count="${line%%::AtOM:SQL:Sep::*}" rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" size="${rest%%::AtOM:SQL:Sep::*}" diff --git a/toys/lowquality b/toys/lowquality index f194997..43b1a79 100755 --- a/toys/lowquality +++ b/toys/lowquality @@ -131,11 +131,11 @@ echo ') ORDER BY bitrate;' >&3 echo 'SELECT "AtOM:NoMoreFiles";' >&3 -read -u4 -d$'\0' line +read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do echo "${line//::AtOM:SQL:Sep::/$'\t'}" - read -u4 -d$'\0' line + read -u4 -d $'\0' line done closeDatabase diff --git a/toys/missingtags b/toys/missingtags index 743d020..e6f956b 100755 --- a/toys/missingtags +++ b/toys/missingtags @@ -149,11 +149,11 @@ cat >&3 <<-EOSelect SELECT "AtOM:NoMoreFiles"; EOSelect -read -u4 -d$'\0' line +read -u4 -d $'\0' line until [[ $line == AtOM:NoMoreFiles ]] do lines+=( "$line" ) - read -u4 -d$'\0' line + read -u4 -d $'\0' line done for line in "${lines[@]}"