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

+2
View File
@@ -43,6 +43,8 @@ All relevant changes are documented in this file.
- tmpfiles: an `x` or `X` entry with an age now has what it keeps cleaned - tmpfiles: an `x` or `X` entry with an age now has what it keeps cleaned
by that age, as in `x /tmp/build 30d` below a `/tmp` cleaned after ten by that age, as in `x /tmp/build 30d` below a `/tmp` cleaned after ten
days. Before the age was not read days. Before the age was not read
- tmpfiles: add the `C+` entry, which also copies to a directory that has
something in it. What is missing is added, nothing is overwritten
- tmpfiles: add `--prefix=PATH`, to only run the entries for paths below - tmpfiles: add `--prefix=PATH`, to only run the entries for paths below
it. `--prefix` and `--exclude-prefix` match whole path components, it. `--prefix` and `--exclude-prefix` match whole path components,
`--exclude-prefix=/dev` no longer skips `/devices` `--exclude-prefix=/dev` no longer skips `/devices`
-1
View File
@@ -11,7 +11,6 @@ files or common packages already rely on, last what few will miss.
1. Remaining types and modifiers 1. Remaining types and modifiers
-------------------------------- --------------------------------
* `C+`, which is read as `C`
* `z` and `Z` only set the SELinux label when `restorecon` is installed * `z` and `Z` only set the SELinux label when `restorecon` is installed
* Modifier `=` (remove what is of another type). `-` (do not fail) has * Modifier `=` (remove what is of another type). `-` (do not fail) has
nothing to do, tmpfiles never exits with an error for an entry, and nothing to do, tmpfiles never exits with an error for an entry, and
+1 -1
View File
@@ -1917,7 +1917,7 @@ static void tmpfiles(char *line)
if (lstat(arg, &ast)) if (lstat(arg, &ast))
break; break;
rc = copy_tree(arg, &ast, path, 0); rc = copy_tree(arg, &ast, path, plus);
if (!rc && !lstat(path, &st) && !S_ISLNK(st.st_mode) && !((st.st_mode ^ ast.st_mode) & S_IFMT) && if (!rc && !lstat(path, &st) && !S_ISLNK(st.st_mode) && !((st.st_mode ^ ast.st_mode) & S_IFMT) &&
perm_path(path, &perm, strc, O_PATH)) perm_path(path, &perm, strc, O_PATH))
warn("Failed setting mode/owner on %s", path); warn("Failed setting mode/owner on %s", path);
+10 -1
View File
@@ -1,5 +1,5 @@
#!/bin/sh #!/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 set -eu
TEST_DIR=$(dirname "$0") TEST_DIR=$(dirname "$0")
@@ -25,11 +25,13 @@ test_teardown()
run "mkdir -p $SRC/sub $DIR/empty $DIR/full/sub $DIR/merge/sub" 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 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 "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 run "cat > $CONF" <<CONF
C $DIR/tree - - - - $SRC C $DIR/tree - - - - $SRC
C $DIR/empty - - - - $SRC C $DIR/empty - - - - $SRC
C $DIR/full - - - - $SRC C $DIR/full - - - - $SRC
C+ $DIR/merge - - - - $SRC
C $DIR/one 0600 - - - $SRC/file C $DIR/one 0600 - - - $SRC/file
C $DIR/one-old - - - - $SRC/file C $DIR/one-old - - - - $SRC/file
C $DIR/missing - - - - /no/such/path 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 "Existing file" "$(content $DIR/full/file)" = "old"
assert "Nothing added" "$(content $DIR/full/sub/file)" = "none" 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 sep
say 'C copies a file, unless it is there' say 'C copies a file, unless it is there'
assert "New file" "$(content $DIR/one)" = "new" assert "New file" "$(content $DIR/one)" = "new"