From: Cameron Ball Date: Thu, 11 Apr 2019 02:45:15 +0000 (+0800) Subject: Handle some extra cases (dirs being empty or not existing) X-Git-Url: http://git.cameron1729.xyz/?a=commitdiff_plain;h=c20f4b31f944732de4f27b27f7c09d23cdd7de4b;p=GrooveNet.git Handle some extra cases (dirs being empty or not existing) --- diff --git a/SongSync.sh b/SongSync.sh index 30304ef..c8f96be 100755 --- a/SongSync.sh +++ b/SongSync.sh @@ -91,6 +91,16 @@ if [ "$1" = "apply" ]; then echo "Moving ${removal_path} to /tmp/${removes[$removal_path]}" mv "${path_to_songs}/${removal_path}" "/tmp/${removes[$removal_path]}" + crc32="$(echo -n "/Songs/${removal_path}/" | gzip -c | tail -c8 | hexdump -n4 -e '"%u"')" + rm "${path_to_song_cache}/${crc32}" + + pack_dir=$(echo "$removal_path" | cut -sd / -f1) + count="$( find "${path_to_songs}/${pack_dir}" -mindepth 1 -maxdepth 1 | wc -l )" + if [ $count -eq 0 ] ; then + echo "${pack_dir} is now empty, deleting" + rmdir "${path_to_songs}/${pack_dir}" + fi + done for add_path in "${!adds[@]}"; do @@ -101,6 +111,11 @@ if [ "$1" = "apply" ]; then rm "${path_to_song_cache}/${crc32}" fi + if ! [ -d "${path_to_songs}/${add_path}" ]; then + echo "Creating dir for: ${add_path}" + mkdir -p "${path_to_songs}/${pack_dir}" + fi + # The file existed previously, just move that over. if [ -d "/tmp/${adds[$add_path]}" ]; then echo "Moving /tmp/${adds[$add_path]} to ${path_to_songs}/${add_path}" @@ -108,8 +123,6 @@ if [ "$1" = "apply" ]; then continue fi - echo "Creating dir for: ${add_path}" - mkdir -p "${path_to_songs}/${pack_dir}" echo "Downloading files" escaped_add_path="/mnt/media/Simfiles/"$(echo "$add_path" | sed 's/ /\\\\\\ /g' | sed "s/'/\\\\\\\\\\\'/g" | sed "s/(/\\\\\\\\\\\\(/g" | sed "s/)/\\\\\\\\\\\\\\)/g" | sed "s/&/\\\\\\\\\\\&/g" | sed "s/\`/\\\\\\\\\\\\\`/g") scp_command="scp -r groovenet@cameron1729.xyz:$escaped_add_path \"${path_to_songs}/${pack_dir}\""