Commit 3a09fb0d2f0fe416b0374c42396a84f52433e42b

Thomas de Grivel 2020-03-10T18:35:56

fix file resources

diff --git a/unix/defs.lisp b/unix/defs.lisp
index 8592d5a..e845d66 100644
--- a/unix/defs.lisp
+++ b/unix/defs.lisp
@@ -86,11 +86,13 @@
                     :properties (,algorithm))
                  algorithms))
          (nreverse algorithms)))
-  ((op-file-ensure :properties (:ensure)))
-  ((:op-properties (:ensure :mode :uid :gid :owner :group))))
+  ((op-file-ensure :properties (:ensure))
+   (op-file-content :properties (:content)))
+  ((:op-properties (:content :ensure :mode :uid :gid :owner :group))))
 
 (defgeneric probe-file-content (resource os))
 (defgeneric op-file-ensure (resource os &key ensure))
+(defgeneric op-file-content (resource os &key content))
 
 ;;  Directory
 
diff --git a/unix/operations.lisp b/unix/operations.lisp
index ecfdfea..9c833c7 100644
--- a/unix/operations.lisp
+++ b/unix/operations.lisp
@@ -78,7 +78,11 @@
                uid))
         (g (or (when group (resource-id group))
                gid)))
-    (run "chown " u (when g `(":" ,g)) " " (resource-id res))))
+    (run "chown "
+         (sh-quote u)
+         (when g `(":" ,(sh-quote g)))
+         " "
+         (sh-quote (resource-id res)))))
 
 (defmethod op-chmod ((res vnode) (os os-unix) &key mode
                                                 &allow-other-keys)
@@ -95,6 +99,11 @@
       ((:present) (run "touch " sh-id))
       ((nil)))))
 
+(defmethod op-file-content ((res file) (os os-unix) &key content)
+  (let ((id (resource-id res)))
+    (run "echo -n " (sh-quote content) " > " (sh-quote id))
+    (clear-probed res)))
+
 ;;  Directory
 
 (defmethod op-directory-ensure ((res directory) (os os-unix)
diff --git a/unix/probes.lisp b/unix/probes.lisp
index 4ea3209..6645196 100644
--- a/unix/probes.lisp
+++ b/unix/probes.lisp
@@ -83,6 +83,7 @@
             (setq mode (mode (mode-permissions mode))
                   owner (resource 'user owner)
                   group (resource 'group group)
+                  size (parse-integer size)
                   ensure :present)
             (return (values* #1#))))
       (properties* (ensure . #1#)))))
@@ -95,6 +96,7 @@
         (with-stat<1>-r (name . #1#) (stat "-r" (sh-quote id))
           (when (and name (string= id (the string name)))
             (setq mode (mode (mode-permissions mode))
+                  size (parse-integer size)
                   ensure :present)
             (return (values* #1#))))
         (properties* (ensure . #1#)))))
@@ -138,7 +140,7 @@
   (let* ((size (get-probed file :size))
          (content (when size
                     (if (< size *probe-file-content-size-limit*)
-                        (run "cat " (sh-quote (resource-id file)))
+                        (str (run "cat " (sh-quote (resource-id file))))
                         :file-too-large))))
     (properties* content)))