toys: checkmissing: adapt to new schema

This commit is contained in:
Vincent Riquer 2025-11-08 19:41:35 +01:00
parent 57607552e4
commit 8efe73b0e5

View File

@ -62,27 +62,42 @@ getConfig
sanityCheck
openDatabase
echo 'SELECT id,filename FROM destination_files WHERE filename IS NOT NULL;' >&3
echo '
SELECT
destination_files.id,
destinations.name,
destination_files.filename
FROM destinations
INNER JOIN destination_files
ON destinations.id=destination_files.destination_id
WHERE filename IS NOT NULL;' >&3
echo 'SELECT "AtOM:NoMoreFiles";' >&3
read -u4 filename
until [[ $filename == AtOM:NoMoreFiles ]]
declare -a \
destination_names \
files
read -u4 line
until [[ $line == AtOM:NoMoreFiles ]]
do
files+=("$filename")
read -u4 filename
id=${line%%::AtOM:SQL:Sep::*}
rest=${line#*::AtOM:SQL:Sep::}
destination_names[id]=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
files[id]=${rest}
read -u4 line
done
echo 'BEGIN TRANSACTION;' >&3
echo -n "Checking for missing files... "
for filename in "${files[@]}"
for index in "${!files[@]}"
do
id=${filename%%::AtOM:SQL:Sep::*}
filename=${filename#*::AtOM:SQL:Sep::}
destination=${destination_names[index]}
filename="${destinationpath[$destination]}/${files[index]}"
if ! [ -f "$filename" ]
then
echo -e "\r$filename\033[K"
((regen))&&Update destination_files last_change 0 <<<"id = $id"
((regen))&&Update destination_files last_change 0 <<<"id = $index"
echo -n "Checking for missing files... "
(( missing++ ))
fi
@ -91,6 +106,6 @@ done
echo 'COMMIT;' >&3
echo -e "\r${missing:-0} missing files\033[K"
echo -e "\r${missing:-No} missing files\033[K"
closeDatabase