runshell: Update files atomically when preparing to run git-annex

This does not make it entirely idempotent, but it's a start.
This commit is contained in:
Joey Hess 2020-10-05 13:38:34 -04:00
parent b91d97c3d2
commit e0ca1236ee
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 21 additions and 10 deletions

View file

@ -42,6 +42,7 @@ git-annex (8.20200909) UNRELEASED; urgency=medium
off when the criterion library is not installed.
* runshell: Fix a edge case where rm errors were sent to stdout, which
could confuse things parsing git-annex output.
* runshell: Update files atomically when preparing to run git-annex.
-- Joey Hess <id@joeyh.name> Mon, 14 Sep 2020 18:34:37 -0400

View file

@ -64,8 +64,9 @@ if [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
echo "else"
echo "exec '$base/runshell' git-annex-shell -c \"\$@\""
echo "fi"
) > "$HOME/.ssh/git-annex-shell"
chmod +x "$HOME/.ssh/git-annex-shell"
) > "$HOME/.ssh/git-annex-shell.$$"
chmod +x "$HOME/.ssh/git-annex-shell.$$"
mv -f "$HOME/.ssh/git-annex-shell.$$" "$HOME/.ssh/git-annex-shell"
fi
fi
@ -77,8 +78,9 @@ if [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
echo "#!/bin/sh"
echo "set -e"
echo "exec '$base/runshell' \"\$@\""
) > "$HOME/.ssh/git-annex-wrapper"
chmod +x "$HOME/.ssh/git-annex-wrapper"
) > "$HOME/.ssh/git-annex-wrapper.$$"
chmod +x "$HOME/.ssh/git-annex-wrapper.$$"
mv -f "$HOME/.ssh/git-annex-wrapper.$$" "$HOME/.ssh/git-annex-wrapper"
fi
fi
fi
@ -155,10 +157,16 @@ if [ -z "${LOCPATH+set}" ] && [ -z "$GIT_ANNEX_PACKAGE_INSTALL" ]; then
echo "Unable to write to $LOCPATH; can't continue!" >&2
exit 1
fi
echo "$base" > "$LOCPATH/base"
# This is updated each time, because the bundle could be moved to a
# different directory.
echo "$base" > "$LOCPATH/base.$$"
mv -f "$LOCPATH/base.$$" "$LOCPATH/base"
# This is updated each time, because the bundle could be updated
# in place to a new version.
# Not using cp to avoid using the one bundled with git-annex before
# the environment is set up to run it.
cat < "$base/buildid" > "$LOCPATH/buildid"
cat < "$base/buildid" > "$LOCPATH/buildid.$$"
mv -f "$LOCPATH/buildid.$$" "$LOCPATH/buildid"
# Generate locale definition files for the locales in use,
# using the localedef and locale files from the bundle.

View file

@ -45,8 +45,9 @@ if [ ! -e "$HOME/.ssh/git-annex-shell" ]; then
echo "else"
echo "exec '$base/runshell' git-annex-shell -c \"\$@\""
echo "fi"
) > "$HOME/.ssh/git-annex-shell"
chmod +x "$HOME/.ssh/git-annex-shell"
) > "$HOME/.ssh/git-annex-shell.$$"
chmod +x "$HOME/.ssh/git-annex-shell.$$"
mv "$HOME/.ssh/git-annex-shell.$$" "$HOME/.ssh/git-annex-shell"
fi
fi
@ -58,8 +59,9 @@ if [ ! -e "$HOME/.ssh/git-annex-wrapper" ]; then
echo "#!/bin/sh"
echo "set -e"
echo "exec '$base/runshell' \"\$@\""
) > "$HOME/.ssh/git-annex-wrapper"
chmod +x "$HOME/.ssh/git-annex-wrapper"
) > "$HOME/.ssh/git-annex-wrapper.$$"
chmod +x "$HOME/.ssh/git-annex-wrapper.$$"
mv "$HOME/.ssh/git-annex-wrapper.$$" "$HOME/.ssh/git-annex-wrapper"
fi
fi