install: avoid redundant metadata updates with -C

"install -C" (--compare) has always called chown/chmod on the
destination even after determining that copying was unnecessary,
ever since --compare was added in commit v7.0-182-gdac5f12c6.
need_copy() already verifies that the destination's mode, owner, and
group match (and, with --preserve-context, that the SELinux context
matches too) before skipping the copy, so re-applying them is
redundant, and can needlessly fail on a destination that cannot be
chown/chmod'd even though nothing would actually change, e.g. one
marked immutable with chattr +i.

* src/install.c (install_file_in_file): Skip metadata updates
if we already skipped the data, as previous checks ensure
that the metadata is already as required.
* tests/install/install-C-immutable.sh: Add a test.
(based on tests/rm/empty-immutable-skip.sh).
* tests/local.mk: Reference the new test.
* NEWS: Mention the improvement.
This commit is contained in:
Mateusz Nosek authored and Pádraig Brady committed 2026-07-16 12:28:03 +01:00
1 parent 09f3fc5f70
commit b4bc8f361b
4 files changed
+65 -1

No files matched your search

+3 -1
View File
@@ -737,7 +737,9 @@ install_file_in_file (char const *from, char const *to,
|| ! S_ISREG (from_sb.st_mode))
&& ! change_timestamps (&from_sb, to, to_dirfd, to_relname))
return false;
return change_attributes (to, to_dirfd, to_relname);
return copy_status == COPY_SKIPPED
|| change_attributes (to, to_dirfd, to_relname);
}
/* Create any missing parent directories of TO,