diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-27 09:44:26 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-27 13:39:57 -0700 |
commit | 4f3672536a9c96476aa5576beeeb446086ef64e7 (patch) | |
tree | 208837cd6cc6551ea362c1e7a2ef9d94e8e76bb7 | |
parent | 838d7aac806e2ebd8f2971c8774598f688191a9a (diff) | |
download | consfigurator-4f3672536a9c96476aa5576beeeb446086ef64e7.tar.gz |
fix :SHELL-WRAP's CONNECTION-WRITEFILE
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r-- | src/connection.lisp | 23 | ||||
-rw-r--r-- | src/connection/shell-wrap.lisp | 9 |
2 files changed, 16 insertions, 16 deletions
diff --git a/src/connection.lisp b/src/connection.lisp index 47356c0..b33d814 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -145,16 +145,17 @@ the root Lisp's machine. For example, using rsync(1) over SSH.")) (stderr :initarg :stderr :reader failed-stderr) (exit-code :initarg :exit-code :reader failed-exit-code))) -(defmacro with-remote-temporary-file ((file) &body body) - `(let ((,file (mktemp))) - (unwind-protect - (progn ,@body) - (connection-run *connection* - (format nil "rm -f ~A" - (escape-sh-token ,file)) - nil)))) - -(defun mktemp () +(defmacro with-remote-temporary-file ((file &key (connection '*connection*)) + &body body) + (once-only (connection) + `(let ((,file (mktemp ,connection))) + (unwind-protect + (progn ,@body) + (connection-run ,connection + (format nil "rm -f ~A" (escape-sh-token ,file)) + nil))))) + +(defun mktemp (&optional (connection *connection*)) "Make a temporary file on the remote side." (multiple-value-bind (out exit) ;; mktemp(1) is not POSIX; the only POSIX way is this m4 way, @@ -162,7 +163,7 @@ the root Lisp's machine. For example, using rsync(1) over SSH.")) ;; often be absent, so have a fallback. Avoid passing any arguments to ;; mktemp(1) as these may differ on different platforms. (connection-run - *connection* + connection "echo 'mkstemp('${TMPDIR:-/tmp}'/tmp.XXXXXX)' | m4 2>/dev/null || mktemp" nil) (if (= exit 0) diff --git a/src/connection/shell-wrap.lisp b/src/connection/shell-wrap.lisp index 70d094c..9619cc1 100644 --- a/src/connection/shell-wrap.lisp +++ b/src/connection/shell-wrap.lisp @@ -35,11 +35,10 @@ path contents umask) - (with-remote-temporary-file (temp) - (connection-run conn - (if umask - (format nil "( umask ~O; cat >~A )" umask temp) - #?"cat >${temp}") + (with-remote-temporary-file (temp :connection conn) + (connection-run conn (if umask + (format nil "( umask ~O; cat >~A )" umask temp) + #?"cat >${temp}") contents) (connection-run conn #?"mv ${(escape-sh-token temp)} ${(escape-sh-token path)}" |