aboutsummaryrefslogtreecommitdiff
path: root/src/property
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/property
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/property')
-rw-r--r--src/property/file.lisp14
1 files changed, 10 insertions, 4 deletions
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."