diff --git a/atom b/atom index 1f392d3..63271e9 100755 --- a/atom +++ b/atom @@ -239,8 +239,8 @@ do done done -deleted=0 -removed=0 +unset deleted +unset removed echo 'BEGIN TRANSACTION;' >&3 for id in ${!removefile[@]} do @@ -264,7 +264,7 @@ do done echo 'COMMIT;' >&3 (( cron )) || echo -n $'\r' -echo -n "Suppressed $deleted files, $removed removed from database" +echo -n "${deleted+$deleted files deleted${removed:+, }}${removed:+$removed removed from database}" (( cron )) || echo -ne "\033[K" echo unset removecount deleted removed removefile @@ -280,7 +280,8 @@ do Update destination_files last_change 0 \ <<<"destination_id = $forcedestid" else - echo "Destination $forcedest does not exist!" >&2 + echo "Full rebuild of destination $forcedest was requested," \ + "but it does not exist!" >&2 fi done @@ -449,7 +450,7 @@ do decodefiles+=("$line::AtOM:SQL:Sep::") read -u4 line done -(( cron )) || echo -n 'Creating tasks... ' +(( cron )) || echo -n $'Creating tasks...\033[K' (( textunidecodeneeded )) && ascii @@ -555,8 +556,11 @@ do tmpfile done echo 'COMMIT;' >&3 -(( cron )) || echo -n $'\r' -echo "Created ${count:-0} tasks for $filecount files ${togo:+($togo left) }(${copies:-0} immediate copies)" +(( cron )) || echo -n $'\r\033[K' +(( count )) \ +&& echo "Created $count tasks for $filecount files \ + ${togo:+($togo left) } \ + ${copies:+($copies immediate copies)}" # remove perl unicode to ascii coprocess (( textunidecodeneeded )) && eval exec "${toascii[1]}>&-" @@ -571,7 +575,7 @@ remaining=$taskcount failed=0 echo 'BEGIN TRANSACTION;' >&3 committime=$EPOCHSECONDS -while (( (remaining || ${#workers[@]}) && ! quit )) +while (( remaining || ${#workers[@]} )) do timestamp=$EPOCHSECONDS if (( $timestamp - committime >= 60 )) @@ -585,12 +589,10 @@ do then concurrency="$fixed_workers" else - if [ -z "$quit" ] \ - && (( ! pause )) \ - && (( timestamp - concurrencychange >= loadinterval )) + if (( timestamp - concurrencychange >= loadinterval )) then - if (( concurrency > 1 )) \ - && (( load > maxload )) + if (( concurrency > 1 || allow_zero_running )) \ + && (( load > maxload && concurrency > 0 )) then concurrencychange=$timestamp (( --concurrency )) @@ -603,16 +605,11 @@ do fi checkworkers cleaner - (( pause )) || master + master if (( ran - failed )) then currenttime=$timestamp - if (( pause )) - then - (( runtime = pausestart - starttime - pausedtime )) - else - (( runtime = currenttime - starttime - pausedtime )) - fi + (( runtime = currenttime - starttime )) avgduration=$(( ( runtime * 1000) / @@ -648,11 +645,7 @@ do fmtprogress="T:%${#taskcount}i/%i (F:%i) %3i%%" fmttime='%2id %2ih%02im%02is (A:%4.1fs/task)' eta="ETA:$( - date -d "${days:-0} days - ${hours:-0} hours - ${minutes:-0} minutes - ${seconds:-0} seconds" \ - +'%d/%m %H:%M:%S' + printf "%(%c)T" "$(( currenttime + secsremaining )) )" (( cron )) || printf \ "\r$fmtload $fmtworkers $fmtprogress $fmttime $eta\033[K"\ @@ -669,7 +662,7 @@ do ${minutes:-0} \ ${seconds:-0} \ ${avgdsec:-0}.${avgdmsec:-0} - if (( pause )) + if ! (( concurrency )) then if (( active )) then @@ -684,22 +677,25 @@ unset count endtime=$EPOCHSECONDS -(( elapsedseconds = endtime - starttime - pausedtime )) +(( elapsedseconds = endtime - starttime )) (( days = elapsedseconds / ( 24*60*60 ) )) || true +(( days )) || unset days (( hours = ( elapsedseconds - ( days*24*60*60 ) ) / ( 60*60 ) )) || true +(( days && hours )) || unset hours (( minutes = ( elapsedseconds - ( ( days*24 + hours ) *60*60 ) ) / 60 )) || true +(( days && hours && minutes )) || unset minutes (( seconds = elapsedseconds - @@ -707,8 +703,12 @@ endtime=$EPOCHSECONDS )) || true (( cron )) || echo -n $'\r' -echo -n "Ran ${ran:=0} tasks, $failed of which failed, in $days" \ - "days, $hours hours, $minutes minutes and $seconds seconds." +(( ran )) \ +&& echo -n "Ran $ran tasks${failed:+, $failed of which failed,} \ + in ${days:+$days days,} \ + ${hours:+$hours hours,} \ + ${minutes:+$minutes minutes and} \ + $seconds seconds." (( cron )) || echo -en "\033[K" echo if (( failed )) @@ -793,17 +793,10 @@ then echo "${line%%::AtOM:SQL:Sep::*}" line="${line#*::AtOM:SQL:Sep::}" line="${line//::AtOM:SQL:Sep::/ }" - echo $'\t'"${line/+( )$/}" - echo + echo $'\t'"${line/+( )$/}"$'\n' done fi -if [ -n "$quit" ] -then - closeDatabase - exit -fi - for destination in "${!destinationpath[@]}" do echo ' @@ -917,7 +910,7 @@ do "${destinationfat32compat["$destination"]}," \ " ascii=" \ "${destinationascii["$destination"]}" \ - "WHERE id=$destfileid;" \ + "WHERE id=$destfileid;" \ >&3 if (( commit )) then @@ -930,7 +923,8 @@ do (( textunidecodeneeded )) && eval exec "${toascii[1]}>&-" echo 'COMMIT;' >&3 (( cron )) || echo -n $'\r' - echo -n "$destination: Renamed ${changedcount:-0} files" + (( changedcount )) \ + && echo -n "$destination: Renamed $changedcount files" (( cron )) || echo -en "\033[K" echo fi @@ -953,7 +947,7 @@ echo ' SELECT "AtOM:NoMoreFiles"; ' >&3 -(( cron )) || echo -n 'Removing obsolete files... ' +(( cron )) || echo -n 'Removing obsolete files...'$'\033[K' lines=() read -u4 line while [[ $line != AtOM:NoMoreFiles ]] @@ -980,11 +974,12 @@ do done echo 'COMMIT;' >&3 (( cron )) || echo -n $'\r' -echo -n "Removed ${count:-0} obsolete files." +(( count )) \ +&& echo -n "Removed $count obsolete files." (( cron )) || echo -en "\033[K" echo -echo "Purging empty directories." +echo "Purging empty directories..." for path in "${destinationpath[@]}" do find "$path" -type d -empty -delete