Commit 5397db25d46d1ebf47d3c6c6b039bf476c280f0c

Thomas de Grivel 2018-07-26T14:33:13

fix stat under linux

diff --git a/unix/linux.lisp b/unix/linux.lisp
index 39e8f08..be4b6b3 100644
--- a/unix/linux.lisp
+++ b/unix/linux.lisp
@@ -43,3 +43,32 @@
                   ensure :present)
             (return (values mode links owner group size mtime))))
       (properties* ensure mode links owner group size mtime))))
+
+(defun parse-hex (string)
+  (parse-integer string :radix 16))
+
+(define-syntax stat<1>-t (file
+                          (#'sh-parse-integer size blksize)
+                          (#'parse-hex mode)
+                          (#'sh-parse-integer uid gid)
+                          (#'parse-hex dev)
+                          (#'sh-parse-integer ino links)
+                          (#'parse-hex major minor)
+			  (#'parse-unix-timestamp atime mtime ctime
+                                                  birthtime)
+			  (#'sh-parse-integer optimal-io))
+    #~|^(.*) ([0-9]+) ([0-9]+) ([A-Fa-f0-9]+) ([0-9]+) ([0-9]+) ([A-Fa-f0-9]+) ([0-9]+) ([0-9]+) ([A-Fa-f0-9]+) ([A-Fa-f0-9]+) ([0-9.]+) ([0-9.]+) ([0-9.]+) ([0-9.]+) ([0-9]+)$|
+  "Syntax for terse stat(1) output on Linux.")
+
+(defmethod probe-vnode-using-stat ((vnode vnode) (os os-linux))
+  (let ((id (resource-id vnode))
+        (ensure :absent))
+    (multiple-value-bind #1=(size blksize mode uid gid dev ino links
+                                  major minor atime mtime ctime
+                                  birthtime optimal-io)
+        (with-stat<1>-t (name . #1#) (stat "-t" (sh-quote id))
+          (when (and name (string= id (the string name)))
+            (setq mode (mode (mode-permissions mode))
+                  ensure :present)
+            (return (values* #1#))))
+        (properties* (ensure . #1#)))))