Handle case when same hash and path appears in both adds and removes
authorCameron Ball <cameron@cameron1729.xyz>
Mon, 8 Apr 2019 16:14:02 +0000 (00:14 +0800)
committerCameron Ball <cameron@cameron1729.xyz>
Mon, 8 Apr 2019 16:36:36 +0000 (00:36 +0800)
SongSync.sh

index 54868e2..afe993b 100755 (executable)
@@ -52,6 +52,13 @@ if [ "$1" = "apply" ]; then
                 echo "More than one SM file in ${path}, aborting"
                 exit
             fi
+
+            if [ "${removes[${path}]}" = "$hash" ]; then
+                echo "Same hash ($hash) and path ($path) in adds and removes. Ignoring."
+                unset removes["$hash"]
+                continue
+            fi
+
             adds["${path}"]+="$hash"
         fi
 
@@ -65,6 +72,12 @@ if [ "$1" = "apply" ]; then
             # I suppose it could happen that one of these borked paths were moved to a different location, but
             # in that case thered be multiple sms in the adds path. So... I guess its OK.
             if [ -z "${removes[${path}]}" ]; then
+                if [ "${adds[${path}]}" = "$hash" ]; then
+                    echo "Same hash ($hash) and path ($path) in adds and removes. Ignoring."
+                    unset adds["$hash"]
+                    continue
+                fi
+
                removes["${path}"]+="$hash"
             fi
         fi