From 60da5db58bb50764ede4d3c37ea2416153774958 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Fri, 4 Nov 2022 15:32:17 -0700 Subject: FILE:HAS-OWNERSHIP: avoid chown'ing when no ownership change needed Signed-off-by: Sean Whitton --- src/property/file.lisp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/property') 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." -- cgit v1.2.3