aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2022-11-04 15:32:17 -0700
committerSean Whitton <spwhitton@spwhitton.name>2022-11-29 11:00:47 -0700
commit60da5db58bb50764ede4d3c37ea2416153774958 (patch)
treec452ec7f9dd7da943284f87d4ee8642d5c6523b4 /src
parent900c622272c0592d06b1c347c32c783da1309bca (diff)
downloadconsfigurator-60da5db58bb50764ede4d3c37ea2416153774958.tar.gz
FILE:HAS-OWNERSHIP: avoid chown'ing when no ownership change needed
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
Diffstat (limited to 'src')
-rw-r--r--src/connection.lisp8
-rw-r--r--src/property/file.lisp14
2 files changed, 15 insertions, 7 deletions
diff --git a/src/connection.lisp b/src/connection.lisp
index b03e33e..d051ad6 100644
--- a/src/connection.lisp
+++ b/src/connection.lisp
@@ -550,8 +550,8 @@ PATH may be any kind of file, including directories."
when (cdr path) collect "-a")))
(defun remote-file-stats (path)
- "Get the numeric mode, size in bytes and mtime of PATH, or NIL if it does not
-exist.
+ "Get the numeric mode, size in bytes, mtime, owner and group of PATH, or NIL if
+it does not exist.
The mtime is only accurate to the nearest UTC day, rounding down, if the file
was modified in the past six months or its mtime is in the future, and only
@@ -593,7 +593,9 @@ specification of POSIX ls(1))."
date month (nth-value 5 (get-decoded-time))
0))
(encode-universal-time
- 0 0 0 date month (parse-integer (nth 7 ls)) 0))))))))
+ 0 0 0 date month (parse-integer (nth 7 ls)) 0)))
+ (nth 2 ls)
+ (nth 3 ls))))))
(defun remote-last-reboot ()
"Get the time of the last reboot, rounded down to the nearest minute."
diff --git a/src/property/file.lisp b/src/property/file.lisp
index 9712571..2612805 100644
--- a/src/property/file.lisp
+++ b/src/property/file.lisp
@@ -111,11 +111,17 @@ any of the regular expressions PATTERNS."
(:hostattrs
(unless (or user group)
(inapplicable-property "Not enough arguments.")))
+ ;; We don't want to execute chown(1) unless we're sure it's needed because
+ ;; in some circumstances doing so also changes the file mode.
+ (:check (multiple-value-bind (mode size mtime owner gowner)
+ (remote-file-stats path)
+ (declare (ignore mode size mtime))
+ (and (or (not user) (string= user owner))
+ (or (not group) (string= group gowner)))))
(:apply
- (with-change-if-changes-file (path)
- (if user
- (mrun "chown" "-h" (format nil "~A~:[~;:~:*~A~]" user group) path)
- (mrun "chgrp" "-h" group path)))))
+ (if user
+ (mrun "chown" "-h" (format nil "~A~:[~;:~:*~A~]" user group) path)
+ (mrun "chgrp" "-h" group path))))
(defprop does-not-exist :posix (&rest paths)
"Ensure that files do not exist."