aboutsummaryrefslogtreecommitdiff
path: root/src/connection.lisp
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2021-03-19 17:05:37 -0700
committerSean Whitton <spwhitton@spwhitton.name>2021-03-19 18:56:59 -0700
commitb55ee656a4474fda81a6ecde2d074fef11cedb8a (patch)
tree7f41924e9970acd905166be3c27dbba56a64ea85 /src/connection.lisp
parent9ec5f3c42d4850419da119005aae1da2db707e3c (diff)
downloadconsfigurator-b55ee656a4474fda81a6ecde2d074fef11cedb8a.tar.gz
WRITEFILE: handle pathnames passed as arguments
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection.lisp')
-rw-r--r--src/connection.lisp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/connection.lisp b/src/connection.lisp
index a8a14a2..f23947e 100644
--- a/src/connection.lisp
+++ b/src/connection.lisp
@@ -320,7 +320,11 @@ start with RUN."
(defun readfile (&rest args)
(apply #'connection-readfile *connection* args))
-(defun writefile (path content &key (mode #o644 mode-supplied-p))
+(defun writefile (path content
+ &key (mode #o644 mode-supplied-p)
+ &aux (namestring (etypecase path
+ (pathname (unix-namestring path))
+ (string path))))
;; If (lisp-connection-p), the file already exists, and it's not owned by
;; us, we could (have a keyword argument to) bypass CONNECTION-WRITEFILE and
;; just WRITE-STRING to the file. That way we don't replace the file with
@@ -334,11 +338,14 @@ start with RUN."
(((lambda (s) (delete #\- s)) umode gmode omode) uid gid)
(#?/^.(...)(...)(...).[0-9]+ ([0-9]+) ([0-9]+) /
(mrun "ls" "-nd" path) :sharedp t)
- (connection-writefile *connection* path content mode)
- (let ((path (escape-sh-token path)))
+ (connection-writefile *connection*
+ namestring
+ content
+ mode)
+ (let ((namestring (escape-sh-token namestring)))
(unless mode-supplied-p
;; assume that if we can write it we can chmod it
- (mrun #?"chmod u=${umode},g=${gmode},o=${omode} ${path}"))
+ (mrun #?"chmod u=${umode},g=${gmode},o=${omode} ${namestring}"))
;; we may not be able to chown; that's okay
(mrun :may-fail #?"chown ${uid}:${gid} ${path}")))
- (connection-writefile *connection* path content mode)))
+ (connection-writefile *connection* namestring content mode)))