deal with the persistent locpath issue

linux standalone: Generate locale files in ~/.cache/git-annex/locales/ so
they're available even when the standalone tarball is installed in a
directory owned by root.

This avoids a full-on reference counting cleanup hell, by letting old
locale caches linger as long as the standalone bundle directory associated
with them is still around. Old ones get cleaned up.

In the case where the directory has a new bundle unpacked over top of it,
the old locale cache is invalidated and rebuilt. Of course, running
programs using that may get confused, but this was already the case, and
unpacking over top of a bundle is probably not a good idea anyhow.

To support that, added a buildid file, which only needs to be unique across
builds of git-annex with different libc versions. sha1sum of git-annex
seems good enough for that.

Removed debian/patches/standalone-no-LOCPATH as it's no longer
necessary.

This commit was supported by the NSF-funded DataLad project.
This commit is contained in:
Joey Hess 2018-07-10 12:13:14 -04:00
parent ac228fa723
commit e802323071
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 31 additions and 65 deletions

View file

@ -118,16 +118,32 @@ export ORIG_MANPATH
MANPATH="$base/usr/share/man:$MANPATH"
export MANPATH
# Avoid using system locales, which may interact badly with bundled libc.
ORIG_LOCPATH="$LOCPATH"
export ORIG_LOCPATH
LOCPATH="$base/locales"
export LOCPATH
# LD_PRELOAD may interact badly with the bundled libc and other libraries,
# which may have a different subarchitecture than the preloaded library.
unset LD_PRELOAD
# Avoid using system locales, which may interact badly with bundled libc.
ORIG_LOCPATH="$LOCPATH"
export ORIG_LOCPATH
LOCPATH="$HOME/.cache/git-annex/locales/$(echo "$base" | tr / _ )"
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 ; then
rm -rf "$localecache"
fi
done
# If the locale cache for this bundle is out of date, refresh it.
if [ -e "$LOCPATH/buildid" ] && ! cmp "$LOCPATH/buildid" "$base/buildid" >/dev/null ; then
rm -rf "$LOCPATH"
fi
mkdir -p "$LOCPATH"
echo "$base" > "$LOCPATH/base"
cp "$base/buildid" "$LOCPATH/buildid"
# Generate locale definition files for the locales in use,
# using the localedef and locale files from the bundle.
# Currently only utf-8 locales are handled.
@ -138,17 +154,17 @@ for localeenv in "$LANG" "$LANGUAGE" "$LC_CTYPE" "$LC_NUMERIC" "$LC_TIME" \
"$LC_IDENTIFICATION" "$LC_ALL"; do
if [ "$localeenv" != "$lastlocaleenv" ]; then
lastlocaleenv="$localeenv"
if [ ! -d "$base/locales/$localeenv" ]; then
if [ ! -d "$LOCPATH/$localeenv" ]; then
if [ "${localeenv##[!.]*.}" = "utf8" ] || [ "${localeenv##[!.]*.}" = "UTF-8" ]; then
(
rm -rf "$base/locales/$localeenv.new.$$" &&
mkdir -p "$base/locales/$localeenv.new.$$" &&
rm -rf "$LOCPATH/$localeenv.new.$$" &&
mkdir -p "$LOCPATH/$localeenv.new.$$" &&
# cd to $base since localedef reads files from pwd
cd "$base" &&
# Run localedef using the bundled i18n files;
# use LANG=C to avoid it reading the system locale archive.
I18NPATH="$base/i18n" LANG=C localedef -i "${localeenv%%.*}" -c -f UTF-8 "$base/locales/$localeenv.new.$$" &&
mv "$base/locales/$localeenv.new.$$" "$base/locales/$localeenv"
I18NPATH="$base/i18n" LANG=C localedef -i "${localeenv%%.*}" -c -f UTF-8 "$LOCPATH/$localeenv.new.$$" &&
mv "$LOCPATH/$localeenv.new.$$" "$LOCPATH/$localeenv"
) >/dev/null 2>/dev/null || true
fi
fi