aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-06 15:14:38 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-06 15:57:19 -0700
commitd240487a486a3f3dd1905b827716b5b13323ca43 (patch)
treef92c97cbb46cc2253074e1c71c65f4696333a918
parent88d1bf3abac5529cfb1950cb49ec0d61e2384382 (diff)
downloadconsfigurator-d240487a486a3f3dd1905b827716b5b13323ca43.tar.gz
combine CONNECTION-WRITEFILE implementations for :LOCAL
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r--src/connection/local.lisp36
1 files changed, 13 insertions, 23 deletions
diff --git a/src/connection/local.lisp b/src/connection/local.lisp
index f181922..5a7da2d 100644
--- a/src/connection/local.lisp
+++ b/src/connection/local.lisp
@@ -44,36 +44,26 @@ root Lisp is running on, as the root Lisp's uid."))
(defmethod connection-readfile ((connection local-connection) path)
(read-file-string path))
-;; in the following two functions, we cannot use UIOP:WITH-TEMPORARY-FILE
-;; etc., because those do not ensure the file is only readable by us, and we
-;; might be writing a secret key
-
(defmethod connection-writefile ((connection local-connection)
path
- (content string)
+ content
mode)
+ ;; we cannot use UIOP:WITH-TEMPORARY-FILE etc., because those do not ensure
+ ;; the file is only readable by us, and we might be writing a secret key
(with-remote-temporary-file
(temp :connection connection
:directory (pathname-directory-pathname path))
(run-program `("chmod" ,(format nil "~O" mode) ,temp))
- (with-open-file (stream temp :direction :output :if-exists :supersede)
- (write-string content stream))
- (run-program `("mv" ,temp ,path))))
-
-(defmethod connection-writefile ((connection local-connection)
- path
- (content stream)
- mode
- &aux
- (type (stream-element-type content)))
- (with-remote-temporary-file
- (temp :connection connection
- :directory (pathname-directory-pathname path))
- (run-program `("chmod" ,(format nil "~O" mode) ,temp))
- (with-open-file (stream temp :direction :output
- :if-exists :supersede
- :element-type type)
- (copy-stream-to-stream content stream :element-type type))
+ (etypecase content
+ (string
+ (with-open-file (stream temp :direction :output :if-exists :supersede)
+ (write-string content stream)))
+ (stream
+ (let ((type (stream-element-type content)))
+ (with-open-file (stream temp :direction :output
+ :if-exists :supersede
+ :element-type type)
+ (copy-stream-to-stream content stream :element-type type)))))
(run-program `("mv" ,temp ,path))))
(defmethod connection-upload ((connection local-connection) from to)