From f14a9b47e3b588e9ab8c7bd9609c76ec493b4e61 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Thu, 6 May 2021 17:12:33 -0700 Subject: FILE:HAS-CONTENT: avoid writing the file if content unchanged Signed-off-by: Sean Whitton --- src/connection.lisp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/connection.lisp') 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* -- cgit v1.2.3