From e0ca1236ee908b1626971f4bfb07770d175b3f29 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 5 Oct 2020 13:38:34 -0400 Subject: [PATCH] runshell: Update files atomically when preparing to run git-annex This does not make it entirely idempotent, but it's a start. --- CHANGELOG | 1 + standalone/linux/skel/runshell | 20 +++++++++++++------ .../osx/git-annex.app/Contents/MacOS/runshell | 10 ++++++---- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 0854abaa0b..4801d7f0a9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Mon, 14 Sep 2020 18:34:37 -0400 diff --git a/standalone/linux/skel/runshell b/standalone/linux/skel/runshell index 3c60ce1e43..c730153deb 100755 --- a/standalone/linux/skel/runshell +++ b/standalone/linux/skel/runshell @@ -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. diff --git a/standalone/osx/git-annex.app/Contents/MacOS/runshell b/standalone/osx/git-annex.app/Contents/MacOS/runshell index 5572a9fd65..4a3b504020 100755 --- a/standalone/osx/git-annex.app/Contents/MacOS/runshell +++ b/standalone/osx/git-annex.app/Contents/MacOS/runshell @@ -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 -- 2.30.2