diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-26 17:15:30 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-02-27 08:33:17 -0700 |
commit | b2e153e2ec9add0dbec673283ebd58b7d13d7456 (patch) | |
tree | be0058157e479418ec7d2315935f85b34047a7bd /src/connection/local.lisp | |
parent | e79092a8b245a2064ebc3759a2b1543ba36f950f (diff) | |
download | consfigurator-b2e153e2ec9add0dbec673283ebd58b7d13d7456.tar.gz |
simplify control flow by specialising on INPUT in CONNECTION-RUN
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/local.lisp')
-rw-r--r-- | src/connection/local.lisp | 48 |
1 files changed, 18 insertions, 30 deletions
diff --git a/src/connection/local.lisp b/src/connection/local.lisp index e78cee6..06b4e67 100644 --- a/src/connection/local.lisp +++ b/src/connection/local.lisp @@ -25,36 +25,24 @@ (:documentation "The root deployment: applying properties to the machine the root Lisp is running on, as the root Lisp's uid.")) -;; assumes a POSIX shell (otherwise we could wrap in 'sh -c') -(defmethod connection-run ((connection local-connection) - shell-cmd - &optional - input) - ;; if INPUT is a stream, RUN-PROGRAM will empty it into a temporary file - ;; anyway, but it will not do so successfully if INPUT is a binary stream -- - ;; in particular, it will try to call COPY-STREAM-TO-STREAM with - ;; :ELEMENT-TYPE CHARACTER. so empty it into a temporary file ourselves. - (with-temporary-file (:pathname temp) - (etypecase input - (string - (with-output-to-file (s temp :if-exists :supersede) - (write-sequence input s))) - (stream - (with-open-file (s temp :element-type (stream-element-type input) - :direction :output - :if-exists :supersede) - (copy-stream-to-stream input s - :element-type (stream-element-type input)))) - (null nil)) - (multiple-value-bind (output _ exit-code) - (run-program shell-cmd - :force-shell t - :input temp - :output :string - :error-output :output - :ignore-error-status t) - (declare (ignore _)) - (values output exit-code)))) +(defmethod connection-run ((c local-connection) cmd (s stream)) + ;; see https://gitlab.common-lisp.net/asdf/asdf/-/issues/59 + (call-next-method c cmd `(,s :element-type ,(stream-element-type s)))) + +(defmethod connection-run ((c local-connection) cmd (s string)) + (call-next-method c cmd (make-string-input-stream s))) + +(defmethod connection-run ((connection local-connection) shell-cmd input) + (multiple-value-bind (output _ exit-code) + ;; assumes a POSIX shell (otherwise we could wrap in 'sh -c') + (run-program shell-cmd + :force-shell t + :input input + :output :string + :error-output :output + :ignore-error-status t) + (declare (ignore _)) + (values output exit-code))) (defmethod connection-readfile ((connection local-connection) path) (read-file-string path)) |