# one downside of this approach is it will result in redownloading files already
# on disk instead of moving them
while read -r m; do
- if [[ ${m:0:2} = "++" ]] || [[ ${m:0:2} = "--" ]] || [[ ${m:0:2} = "@@" ]]; then
+ if [[ "${m:0:2}" = "++" ]] || [[ "${m:0:2}" = "--" ]] || [[ "${m:0:2}" = "@@" ]]; then
continue
fi
- hash=$(echo $m | cut -sd ' ' -f1)
+ hash=$(echo "$m" | cut -sd ' ' -f1)
hash="${hash:1}"
- path=$(echo $m | cut -sd / -f5,6)
+ path=$(echo "$m" | cut -sd / -f5,6)
- if [[ ${m:0:1} = "+" ]]; then
+ if [[ "${m:0:1}" = "+" ]]; then
if ! [ -z "${adds[${path}]}" ]; then
echo "More than one SM file in ${path}, aborting"
exit
adds["${path}"]+="$hash"
fi
- if [[ ${m:0:1} = "-" ]]; then
+ if [[ "${m:0:1}" = "-" ]]; then
# It can happan that a path is already in removes if there are multiple SM files in a directory
# this should not really happen since there's the check above that refuses to add any files with that
# problem. However when I do the initial sync on our machines they will have problematic files.
# So just ignore it, the path is already in the removes list, so it will be nuked.
#
# I suppose it could happen that one of these borked paths were moved to a different location, but
- # in that case there'd be multiple sms in the adds path. So... I guess it's OK.
+ # in that case thered be multiple sms in the adds path. So... I guess its OK.
if [ -z "${removes[${path}]}" ]; then
removes["${path}"]+="$hash"
fi
for removal_path in "${!removes[@]}"; do
if [ -d "/tmp/${removes[$removal_path]}" ]; then
echo "need to rm /tmp/${removes[$removal_path]}"
- rm "/tmp/${removes[$removal_path]}"
+ rm -rf "/tmp/${removes[$removal_path]}"
fi
echo "Moving ${removal_path} to /tmp/${removes[$removal_path]}"
done
for add_path in "${!adds[@]}"; do
- pack_dir=$(echo $add_path | cut -sd / -f1)
+ pack_dir=$(echo "$add_path" | cut -sd / -f1)
if ! [ -z "${removes[${add_path}]}" ]; then
crc32="$(echo -n "/Songs/${add_path}/" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')"
echo "CACHE INVALIDATION NEEDED FOR ${add_path} : ${crc32}"
eval "$scp_command"
done
- rm ${old_songs_file}
+ rm "${old_songs_file}"
fi