move cache cleanup to avoid a race

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.
This commit is contained in:
Joey Hess 2020-10-05 14:07:27 -04:00
parent f0ec725234
commit 12a248f823
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -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=""