From 37cbc12946f73c325b9bdeb17bf042384bab21c8 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Sat, 21 Nov 2026 17:01:40 +0100 Subject: [PATCH] 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 --- doc/ChangeLog.md | 2 ++ doc/tmpfiles-todo.md | 1 - src/tmpfiles.c | 2 +- test/tmpfiles-copy.sh | 11 ++++++++++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/ChangeLog.md b/doc/ChangeLog.md index 073e4272..13dfc517 100644 --- a/doc/ChangeLog.md +++ b/doc/ChangeLog.md @@ -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 by that age, as in `x /tmp/build 30d` below a `/tmp` cleaned after ten 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 it. `--prefix` and `--exclude-prefix` match whole path components, `--exclude-prefix=/dev` no longer skips `/devices` diff --git a/doc/tmpfiles-todo.md b/doc/tmpfiles-todo.md index 6c5dbc76..34adf624 100644 --- a/doc/tmpfiles-todo.md +++ b/doc/tmpfiles-todo.md @@ -11,7 +11,6 @@ files or common packages already rely on, last what few will miss. 1. Remaining types and modifiers -------------------------------- -* `C+`, which is read as `C` * `z` and `Z` only set the SELinux label when `restorecon` is installed * Modifier `=` (remove what is of another type). `-` (do not fail) has nothing to do, tmpfiles never exits with an error for an entry, and diff --git a/src/tmpfiles.c b/src/tmpfiles.c index 81375a1c..1564688e 100644 --- a/src/tmpfiles.c +++ b/src/tmpfiles.c @@ -1917,7 +1917,7 @@ static void tmpfiles(char *line) if (lstat(arg, &ast)) 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) && perm_path(path, &perm, strc, O_PATH)) warn("Failed setting mode/owner on %s", path); diff --git a/test/tmpfiles-copy.sh b/test/tmpfiles-copy.sh index 06ca4941..089d1323 100755 --- a/test/tmpfiles-copy.sh +++ b/test/tmpfiles-copy.sh @@ -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" <