94 lines
2.4 KiB
Bash
94 lines
2.4 KiB
Bash
#!/bin/bash
|
|
copyFiles_action() {
|
|
echo -n "Copying files... "
|
|
echo '
|
|
SELECT
|
|
source_files.filename,
|
|
source_files.last_change,
|
|
destinations.id,
|
|
destinations.name,
|
|
destination_files.id
|
|
FROM source_files
|
|
INNER JOIN destination_files
|
|
ON source_files.id
|
|
= destination_files.source_file_id
|
|
INNER JOIN destinations
|
|
ON destination_files.destination_id=destinations.id
|
|
INNER JOIN mime_type_actions
|
|
ON mime_type_actions.id = source_files.mime_type
|
|
WHERE CAST(destination_files.last_change AS TEXT)
|
|
<> CAST(source_files.last_change AS TEXT)
|
|
AND mime_type_actions.destination_id = destinations.id
|
|
AND mime_type_actions.action = 2;
|
|
|
|
SELECT "AtOM:NoMoreFiles";' >&3
|
|
read -u4 line
|
|
while ! [[ $line = AtOM:NoMoreFiles ]]
|
|
do
|
|
copyfiles+=("$line")
|
|
read -u4 line
|
|
done
|
|
|
|
echo 'BEGIN TRANSACTION;' >&3
|
|
for copyfile in "${copyfiles[@]}"
|
|
do
|
|
sourcefilename=${copyfile%%::AtOM:SQL:Sep::*}
|
|
sourcedir=${sourcefilename%/*}
|
|
rest="${copyfile#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::"
|
|
lastchange=${rest%%::AtOM:SQL:Sep::*}
|
|
rest=${rest#*::AtOM:SQL:Sep::}
|
|
destinationid=${rest%%::AtOM:SQL:Sep::*}
|
|
rest=${rest#*::AtOM:SQL:Sep::}
|
|
destination=${rest%%::AtOM:SQL:Sep::*}
|
|
rest=${rest#*::AtOM:SQL:Sep::}
|
|
destfileid=${rest%%::AtOM:SQL:Sep::*}
|
|
rest=${rest#*::AtOM:SQL:Sep::}
|
|
(( count++ ))
|
|
printf '\b\b\b\b%3i%%' $(( (count * 100) / ${#copyfiles[@]} ))
|
|
if [ -n "${renamepath["$destination"]}" ]
|
|
then
|
|
destdir="$(guessPath)" || continue
|
|
else
|
|
destdir="${destinationpath["$destination"]}/"
|
|
if [[ $sourcefilename =~ / ]]
|
|
then
|
|
destdir+=$(
|
|
sanitizeFile "${sourcefilename%%/*}" dir
|
|
)
|
|
part=${sourcefilename#*/}
|
|
while [[ $part =~ / ]]
|
|
do
|
|
destdir+="/$(
|
|
sanitizeFile "${part%%/*}" dir
|
|
)"
|
|
part=${part#*/}
|
|
done
|
|
if ! [ -d "$destdir" ]
|
|
then
|
|
mkdir -p "$destdir"
|
|
fi
|
|
fi
|
|
fi
|
|
if cp -al "$sourcepath/$sourcefilename" "$destdir" 2>/dev/null\
|
|
|| cp -a "$sourcepath/$sourcefilename" "$destdir"
|
|
then
|
|
Update destination_files \
|
|
filename "$destdir/${sourcefilename##*/}"\
|
|
rename_pattern "${destinationrenamepath[$destination]}/${destinationrename[$destination]}:${destinationfat32compat["$destination"]}"\
|
|
last_change $lastchange \
|
|
<<-EOWhere
|
|
id = $destfileid
|
|
EOWhere
|
|
(( done++ ))
|
|
fi
|
|
done
|
|
echo 'COMMIT;' >&3
|
|
if (( count ))
|
|
then
|
|
echo -e "\rCopied ${done:-0} of $count files.\033[K"
|
|
else
|
|
echo -e "\rNothing to copy.\033[K"
|
|
fi
|
|
unset count done
|
|
}
|