tmpfiles: fix C entries, never copy over what exists

A C entry for a directory does the opposite of tmpfiles.d(5):

    C /etc/pam.d - - - -

When /etc/pam.d does not exist the entry fails with "Not a directory",
the files of the source are copied to a file with the name of the
path, one over the other.  When it is an empty directory nothing is
copied.  When it has files in it, they are overwritten with the ones
from /usr/share/factory, at every boot.  For a file, an existing one
is overwritten as well.

is_dir_empty() returns true for a directory that is not empty, and
rsync() from libite copies over what is there and needs a slash at the
end of a destination directory that is missing.

Copy with a tree walk of our own instead.  It copies to a path that
is missing or an empty directory, overwrites nothing, and does not
follow links.  Mode, owner, and modification time are those of the
source.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 17:14:04 +01:00
1 parent 9160ca3ddf
commit 7b3b217e60
4 files changed
+258 -29

No files matched your search

+2
View File
@@ -87,6 +87,7 @@ EXTRA_DIST += tmpfiles-attr.sh
EXTRA_DIST += tmpfiles-perm.sh
EXTRA_DIST += tmpfiles-boot.sh
EXTRA_DIST += tmpfiles-clean.sh
EXTRA_DIST += tmpfiles-copy.sh
EXTRA_DIST += tmpfiles-order.sh
EXTRA_DIST += tmpfiles-specifier.sh
EXTRA_DIST += tmpfiles-unsupported.sh
@@ -173,6 +174,7 @@ TESTS += tmpfiles-attr.sh
TESTS += tmpfiles-perm.sh
TESTS += tmpfiles-boot.sh
TESTS += tmpfiles-clean.sh
TESTS += tmpfiles-copy.sh
TESTS += tmpfiles-order.sh
TESTS += tmpfiles-specifier.sh
TESTS += tmpfiles-unsupported.sh