runshell: Update files atomically when preparing to run git-annex
authorJoey Hess <joeyh@joeyh.name>
Mon, 5 Oct 2020 17:38:34 +0000 (13:38 -0400)
committerJoey Hess <joeyh@joeyh.name>
Mon, 5 Oct 2020 17:38:34 +0000 (13:38 -0400)
This does not make it entirely idempotent, but it's a start.

CHANGELOG
standalone/linux/skel/runshell
standalone/osx/git-annex.app/Contents/MacOS/runshell

index 0854abaa0b3fd537c4ffff2e12184f3156c40328..4801d7f0a90976ade940612254b4776c0af7cc40 100644 (file)
--- 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 <id@joeyh.name>  Mon, 14 Sep 2020 18:34:37 -0400
 
index 3c60ce1e4314aa20bd60d16c7d92fe61fc57aba8..c730153deb0d77096a1201093e0e43d99cc767eb 100755 (executable)
@@ -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.
index 5572a9fd65150f28af46da8a1d0dd5057b4f8707..4a3b50402006927a10c825111932416bf646d389 100755 (executable)
@@ -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