aboutsummaryrefslogtreecommitdiff
path: root/src/connection
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-08-29 12:19:25 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-08-31 15:55:26 -0700
commit98b727ae3d20a3447288254f421d9524ef8e6548 (patch)
tree4fa54e7aa7220a83f8501c11e6de33ce41b630bf /src/connection
parent1f12dfda4aeb6d08af454d60caa5985b2bd5b1ba (diff)
downloadconsfigurator-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')
-rw-r--r--src/connection/local.lisp3
-rw-r--r--src/connection/shell-wrap.lisp18
2 files changed, 17 insertions, 4 deletions
diff --git a/src/connection/local.lisp b/src/connection/local.lisp
index 4bd272e..6645178 100644
--- a/src/connection/local.lisp
+++ b/src/connection/local.lisp
@@ -45,6 +45,9 @@ root Lisp is running on, as the root Lisp's uid."))
(defmethod connection-readfile ((connection local-connection) path)
(read-file-string path))
+(defmethod connection-readfile-and-remove ((connection local-connection) path)
+ (prog1 (read-file-string path) (delete-file path)))
+
(defmethod connection-writefile ((connection local-connection)
path
content
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