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 sanityCheck
openDatabase 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 echo 'SELECT "AtOM:NoMoreFiles";' >&3
read -u4 filename declare -a \
until [[ $filename == AtOM:NoMoreFiles ]] destination_names \
files
read -u4 line
until [[ $line == AtOM:NoMoreFiles ]]
do do
files+=("$filename") id=${line%%::AtOM:SQL:Sep::*}
read -u4 filename rest=${line#*::AtOM:SQL:Sep::}
destination_names[id]=${rest%%::AtOM:SQL:Sep::*}
rest=${rest#*::AtOM:SQL:Sep::}
files[id]=${rest}
read -u4 line
done done
echo 'BEGIN TRANSACTION;' >&3 echo 'BEGIN TRANSACTION;' >&3
echo -n "Checking for missing files... " echo -n "Checking for missing files... "
for filename in "${files[@]}" for index in "${!files[@]}"
do do
id=${filename%%::AtOM:SQL:Sep::*} destination=${destination_names[index]}
filename=${filename#*::AtOM:SQL:Sep::} filename="${destinationpath[$destination]}/${files[index]}"
if ! [ -f "$filename" ] if ! [ -f "$filename" ]
then then
echo -e "\r$filename\033[K" 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... " echo -n "Checking for missing files... "
(( missing++ )) (( missing++ ))
fi fi
@ -91,6 +106,6 @@ done
echo 'COMMIT;' >&3 echo 'COMMIT;' >&3
echo -e "\r${missing:-0} missing files\033[K" echo -e "\r${missing:-No} missing files\033[K"
closeDatabase closeDatabase