tmpfiles: add --replace, files on the command line in place of one

A package script may run before the package's tmpfiles.d file is on
disk, and gives the entries on the command line or on standard input.
Then only those entries were read, so one that the admin has changed
in /etc/tmpfiles.d was run as the package has it.

With --replace=PATH all the tmpfiles.d files are read, and the ones on
the command line are read where the file PATH would be, as in
systemd-tmpfiles:

    tmpfiles --create --replace=/usr/lib/tmpfiles.d/app.conf -

They are not read at all when a later directory has a file of that
name, as with a file that is installed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 19:23:50 +01:00
1 parent fa430d0a02
commit 575267f09b
4 files changed
+99 -30

No files matched your search

+18 -1
View File
@@ -6,13 +6,14 @@ set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/files
CONF=/tmp/files.conf
LIB=/usr/lib/tmpfiles.d
ETC=/etc/tmpfiles.d
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $LIB/[0-9]0-test.conf $ETC/[0-9]0-test.conf"
run "rm -rf $DIR $CONF $LIB/[0-9]0-test.conf $ETC/[0-9]0-test.conf"
}
# shellcheck source=/dev/null
@@ -31,6 +32,7 @@ f $DIR/first - - - - one
CONF
run "cat > $ETC/20-test.conf" <<CONF
f $DIR/first - - - - two
f $DIR/second - - - - two
w+ $DIR/first - - - - +three
w+ $DIR/first - - - - +four
CONF
@@ -46,6 +48,21 @@ assert "First by file name" "$(texec cat $DIR/first)" = "one+three+four"
assert "Told about in a dry run" \
"$(texec sh -c "/libexec/finit/tmpfiles -n --create --prefix=$DIR 2>&1 | grep -c 'already has an entry'")" = "1"
sep
say 'With --replace a file on the command line is read as if it was the one named'
run "cat > $CONF" <<CONF
f $DIR/replace - - - - new
f $DIR/first - - - - new
f $DIR/second - - - - new
CONF
run "rm -rf $DIR; /libexec/finit/tmpfiles --create --prefix=$DIR --replace=$LIB/15-test.conf $CONF"
assert "Read" "$(texec cat $DIR/replace)" = "new"
assert "After the files before its name" "$(texec cat $DIR/first)" = "one+three+four"
assert "Before the ones after it" "$(texec cat $DIR/second)" = "new"
assert "With the other files" "$(texec cat $DIR/same)" = "etc"
run "rm -rf $DIR; /libexec/finit/tmpfiles --create --prefix=$DIR --replace=$LIB/50-test.conf $CONF"
assert "Not when /etc has that name" "$(texec sh -c "ls $DIR | grep -c replace")" = "0"
sep
say 'A file named - is read from standard input'
run "echo 'f $DIR/stdin' | /libexec/finit/tmpfiles --create -"