tmpfiles: add the C+ entry, copy to a directory that is not empty

A C entry leaves a directory alone when there is something in it.  In
tmpfiles.d(5) a C+ entry copies to it anyway: what the directory lacks
is added, and what it has is not overwritten.

    C+ /etc/skel - - - - /usr/share/factory/etc/skel

tmpfiles reads C+ as C.  Let the + through to copy_tree().

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 7b3b217e60
commit 37cbc12946
4 files changed
+13 -3

No files matched your search

+10 -1
View File
@@ -1,5 +1,5 @@
#!/bin/sh
# Verify the C entry of tmpfiles, copy a file or a tree
# Verify the C and C+ entries of tmpfiles, copy a file or a tree
set -eu
TEST_DIR=$(dirname "$0")
@@ -25,11 +25,13 @@ test_teardown()
run "mkdir -p $SRC/sub $DIR/empty $DIR/full/sub $DIR/merge/sub"
run "echo new > $SRC/file; echo new > $SRC/sub/file; echo new > $SRC/sub/other; ln -s file $SRC/link; chmod 640 $SRC/file"
run "echo old > $DIR/full/file; echo old > $DIR/merge/sub/file; echo old > $DIR/one-old"
run "mkdir $SRC/away $DIR/out; echo new > $SRC/away/file; ln -s ../out $DIR/merge/away"
run "cat > $CONF" <<CONF
C $DIR/tree - - - - $SRC
C $DIR/empty - - - - $SRC
C $DIR/full - - - - $SRC
C+ $DIR/merge - - - - $SRC
C $DIR/one 0600 - - - $SRC/file
C $DIR/one-old - - - - $SRC/file
C $DIR/missing - - - - /no/such/path
@@ -48,6 +50,13 @@ assert "Empty directory" "$(content $DIR/empty/sub/file)" = "new"
assert "Existing file" "$(content $DIR/full/file)" = "old"
assert "Nothing added" "$(content $DIR/full/sub/file)" = "none"
sep
say 'C+ adds what is missing and overwrites nothing'
assert "Existing file" "$(content $DIR/merge/sub/file)" = "old"
assert "Missing file" "$(content $DIR/merge/sub/other)" = "new"
assert "Missing at top" "$(content $DIR/merge/file)" = "new"
assert "Not through a link" "$(content $DIR/out/file)" = "none"
sep
say 'C copies a file, unless it is there'
assert "New file" "$(content $DIR/one)" = "new"