From b55ee656a4474fda81a6ecde2d074fef11cedb8a Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 19 Mar 2021 17:05:37 -0700 Subject: WRITEFILE: handle pathnames passed as arguments Signed-off-by: Sean Whitton --- src/connection.lisp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src/connection.lisp') 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))) -- cgit v1.2.3