diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-06 17:12:33 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-05-06 17:12:33 -0700 |
commit | f14a9b47e3b588e9ab8c7bd9609c76ec493b4e61 (patch) | |
tree | 3cf71c4b24155495a6d441440ba521a2dcc2abe3 /src/connection.lisp | |
parent | 4ed2a639d8e085d54ddedcb73d93e28754aa239b (diff) | |
download | consfigurator-f14a9b47e3b588e9ab8c7bd9609c76ec493b4e61.tar.gz |
FILE:HAS-CONTENT: avoid writing the file if content unchanged
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src/connection.lisp')
-rw-r--r-- | src/connection.lisp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/connection.lisp b/src/connection.lisp index 75617cf..d7caadf 100644 --- a/src/connection.lisp +++ b/src/connection.lisp @@ -390,6 +390,26 @@ PATH may be any kind of file, including directories." nconc (list "-e" (car path)) when (cdr path) collect "-a"))) +(defun remote-file-mode-and-size (path) + "Get the numeric mode and size in bytes of PATH, or NIL if it does not exist." + (flet ((sum (chars order) + (+ (if (char= (elt chars 0) #\r) (* order 4) 0) + (if (char= (elt chars 1) #\w) (* order 2) 0) + (eswitch ((elt chars 2) :test #'char=) + (#\S (if (= order #o100) #o4000 #o2000)) + (#\s (if (= order #o100) #o4100 #o2010)) + (#\T #o1000) + (#\t (+ order #o1000)) + (#\x order) + (#\- 0))))) + (and (remote-exists-p path) + (let* ((ls (split-string (run "ls" "-ld" path))) + (lscar (car ls))) + (values (+ (sum (subseq lscar 1 4) #o100) + (sum (subseq lscar 4 7) #o10) + (sum (subseq lscar 7 10) 1)) + (parse-integer (nth 4 ls))))))) + (defun readfile (path) (connection-readfile *connection* |