From 4079d523b0b036f03269d94b64f3d92b96eaa887 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 29 Aug 2021 15:19:05 -0700 Subject: SHELL-WRAP-CONNECTION CONNECTION-WRITEFILE: execute just one command Should improve performance, especially when connection latency is high. Signed-off-by: Sean Whitton --- src/connection/shell-wrap.lisp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/connection') 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))))) -- cgit v1.2.3