move cache cleanup to avoid a race
authorJoey Hess <joeyh@joeyh.name>
Mon, 5 Oct 2020 18:07:27 +0000 (14:07 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 5 Oct 2020 18:07:27 +0000 (14:07 -0400)
This should fix doc/bugs/standalone_runshell_can_race_and_fail_to_remove___96____126____47__.cache__47__git-annex__47__locales__47____96___dirs
where 2 runshells were running and the second one tried to clean up
LOCPATH while the first one was still populating it.

By moving the cleanup until after LOCPATH is populated, we guarantee
it's populated, so don't need to worry about such a race with another
process populating our same LOCPATH.

standalone/linux/skel/runshell

index c63b05413c67b115cfb16f2dce973653ade96a17..08661d3e21349d4458720d5765c677cdb85fed7b 100755 (executable)
@@ -141,14 +141,6 @@ if [ -z "${LOCPATH+set}" ] && [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
        fi
        export LOCPATH
        
-       # Clean up locale caches when their standalone bundle no longer exists.
-       for localecache in $HOME/.cache/git-annex/locales/*; do
-               cachebase=$(cat "$localecache/base" 2>/dev/null || true)
-               if [ ! -d "$cachebase" ] || ! cmp "$localecache/buildid" "$cachebase/buildid" >/dev/null 2>&1 ; then
-                       rm -rf "$localecache" >/dev/null 2>&1 || true
-               fi
-       done
-       
        if [ ! -d "$LOCPATH" ]; then
                if ! mkdir -p "$LOCPATH"; then
                        echo "Unable to write to $LOCPATH; can't continue!" >&2
@@ -195,6 +187,14 @@ if [ -z "${LOCPATH+set}" ] && [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
                        fi
                fi
        done
+       
+       # Clean up locale caches when their standalone bundle no longer exists.
+       for localecache in $HOME/.cache/git-annex/locales/*; do
+               cachebase=$(cat "$localecache/base" 2>/dev/null || true)
+               if [ ! -d "$cachebase" ] || ! cmp "$localecache/buildid" "$cachebase/buildid" >/dev/null 2>&1 ; then
+                       rm -rf "$localecache" >/dev/null 2>&1 || true
+               fi
+       done
 fi
 
 useproot=""