diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-29 15:19:05 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-31 22:35:31 -0700 |
commit | 4079d523b0b036f03269d94b64f3d92b96eaa887 (patch) | |
tree | 7b789b524e6bc9d64be80266d4f4e5107d8f34c8 /src/connection | |
parent | 78aeec9bcea6bec274120bbd8824e251697a372e (diff) | |
download | consfigurator-4079d523b0b036f03269d94b64f3d92b96eaa887.tar.gz |
SHELL-WRAP-CONNECTION CONNECTION-WRITEFILE: execute just one command
Should improve performance, especially when connection latency is high.
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection')
-rw-r--r-- | src/connection/shell-wrap.lisp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/src/connection/shell-wrap.lisp b/src/connection/shell-wrap.lisp index ba4312f..f247a14 100644 --- a/src/connection/shell-wrap.lisp +++ b/src/connection/shell-wrap.lisp @@ -45,21 +45,18 @@ path content mode) - (with-remote-temporary-file - (temp :connection conn :directory (pathname-directory-pathname path)) - ;; TODO do we want a CONNECTION-ERROR condition to tidy this up? - (multiple-value-bind (out exit) - (connection-run conn - (format nil "chmod ~O ~A" mode - (escape-sh-token temp)) - nil) - (unless (zerop exit) (error "Failed to chmod ~A: ~A" temp out))) - (multiple-value-bind (out exit) - (connection-run conn #?"cat >${temp}" content) - (unless (zerop exit) (error "Failed to write ~A: ~A" temp out))) - (multiple-value-bind (out exit) - (connection-run - conn - #?"mv ${(escape-sh-token temp)} ${(escape-sh-token (unix-namestring path))}" - nil) - (unless (zerop exit) (error "Failed to write ~A: ~A" path out))))) + (let ((cmd + (format + nil "set -e +tmpf=$(~A) +trap \"rm -f '$tmpf'\" EXIT HUP KILL TERM INT +chmod ~O \"$tmpf\" +cat >\"$tmpf\" +mv \"$tmpf\" ~A" + (mkstemp-cmd + (merge-pathnames "tmp.XXXXXX" (pathname-directory-pathname path))) + mode + (escape-sh-token (unix-namestring path))))) + (multiple-value-bind (out exit) (connection-run conn cmd content) + (unless (zerop exit) + (error "Failed to write ~A: ~A" path out))))) |