getFiles() { scantime=$(date +%s) for prune_expression in "${skippeddirectories[@]}" do prunes+="-path $sourcepath$prune_expression -prune -o " done echo -n "Scanning $sourcepath... " # We probably have thousands of files, don't waste time on disk writes echo 'BEGIN TRANSACTION;' >&3 while read time size filename do if ! Select source_files id >/dev/null <<-EOWhere filename = $filename mime_type > 0 last_change = $time EOWhere then mimetype=$(file -b --mime-type "$sourcepath/$filename") if [[ $mimetype == application/ogg ]] then case "$(head -n1 "$sourcepath/$filename")" in *'vorbis'*) mimetype+=' vorbis' ;; *'OpusHead'*) mimetype+=' opus' ;; esac fi mimetypeid=$( InsertIfUnset mime_types <<-EOInsert mime_text $mimetype EOInsert ) InsertOrUpdate source_files \ last_change $time \ size $size \ last_seen $scantime \ mime_type $mimetypeid \ >/dev/null \ <<-EOWhere filename $filename EOWhere (( ++new )) if (( new % 1000 == 0 )) then echo 'COMMIT;BEGIN TRANSACTION;' >&3 (( debug )) \ && echo -ne "\bCommitted $count files... " fi else Update source_files last_seen $scantime <<-EOWhere filename = $filename EOWhere fi progressSpin done < <( find "$sourcepath" $prunes -type f -printf "%T@ %s %P\n" ) echo 'COMMIT;' >&3 echo -e "\r${count:-0} files found, ${new:=0} new or changed." unset count }