runshell: fix some mess left in a race

This seems to be the best way to deal with the race; if the first and
second runshell are running very close together, the first will generate
the locale directory, and a second test -d would still leave a race
window.
This commit is contained in:
Joey Hess 2020-10-05 13:42:43 -04:00
parent e0ca1236ee
commit 5863d14fd2
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -189,6 +189,9 @@ if [ -z "${LOCPATH+set}" ] && [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
# use LANG=C to avoid it reading the system locale archive.
I18NPATH="$base/i18n" LANG=C localedef -i "${localeenv%%.*}" -c -f UTF-8 "$LOCPATH/$localeenv.new.$$" &&
mv "$LOCPATH/$localeenv.new.$$" "$LOCPATH/$localeenv"
# In a race, LOCPATH may get created by another process,
# in which cache the mv above would put it here.
rm -rf "$LOCPATH/$localeenv/$localeenv.new.$$"
) >/dev/null 2>/dev/null || true
fi
fi