diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-29 12:19:25 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-08-31 15:55:26 -0700 |
commit | 98b727ae3d20a3447288254f421d9524ef8e6548 (patch) | |
tree | 4fa54e7aa7220a83f8501c11e6de33ce41b630bf /src/connection/shell-wrap.lisp | |
parent | 1f12dfda4aeb6d08af454d60caa5985b2bd5b1ba (diff) | |
download | consfigurator-98b727ae3d20a3447288254f421d9524ef8e6548.tar.gz |
add CONNECTION-READFILE-AND-REMOVE to improve RUN performance
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection/shell-wrap.lisp')
-rw-r--r-- | src/connection/shell-wrap.lisp | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/src/connection/shell-wrap.lisp b/src/connection/shell-wrap.lisp index d821f22..ba4312f 100644 --- a/src/connection/shell-wrap.lisp +++ b/src/connection/shell-wrap.lisp @@ -25,11 +25,21 @@ (defmethod connection-run ((c shell-wrap-connection) cmd input) (mrun :may-fail :input input (connection-shell-wrap c cmd))) -(defmethod connection-readfile ((c shell-wrap-connection) path) +(defun %readfile (c path &optional delete) (multiple-value-bind (out exit) - (let ((path (escape-sh-token path))) - (connection-run c #?"test -r ${path} && cat ${path}" nil)) - (if (zerop exit) out (error "File ~S not readable" path)))) + (let* ((path (escape-sh-token path)) + (base #?"test -r ${path} && cat ${path}") + (cmd (if delete (strcat base #?"&& rm ${path}") base))) + (connection-run c cmd nil)) + (if (zerop exit) + out + (error "Could not read~:[~; and/or remove~] ~S" delete path)))) + +(defmethod connection-readfile ((c shell-wrap-connection) path) + (%readfile c path)) + +(defmethod connection-readfile-and-remove ((c shell-wrap-connection) path) + (%readfile c path t)) (defmethod connection-writefile ((conn shell-wrap-connection) path |