tmpfiles: remove before creating when asked to do both

With both --create and --remove each entry was removed and then
created before the next one was read.  An r entry took what an entry
above it had just created:

    f /tmp/file - - - - new
    r /tmp/file

    tmpfiles --create --remove t.conf

This left no /tmp/file.  The same goes for --clean.

Run all the files twice in that case, first to remove and clean, then
to create.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 18:02:34 +01:00
1 parent 3a283d40b5
commit 9195d145d1
4 files changed
+95 -51

No files matched your search

+2
View File
@@ -84,6 +84,7 @@ EXTRA_DIST += testserv.sh
EXTRA_DIST += tmpfiles-acl.sh
EXTRA_DIST += tmpfiles-arg.sh
EXTRA_DIST += tmpfiles-perm.sh
EXTRA_DIST += tmpfiles-order.sh
EXTRA_DIST += unexpected-restart.sh
EXTRA_DIST += dbus-auth.sh
EXTRA_DIST += dbus-authz.sh
@@ -164,6 +165,7 @@ TESTS += testserv.sh
TESTS += tmpfiles-acl.sh
TESTS += tmpfiles-arg.sh
TESTS += tmpfiles-perm.sh
TESTS += tmpfiles-order.sh
endif
TESTS += unexpected-restart.sh
if DBUS
+27
View File
@@ -0,0 +1,27 @@
#!/bin/sh
# Verify that tmpfiles removes before it creates when asked to do both
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/order
CONF=/tmp/order.conf
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "cat > $CONF" <<CONF
d $DIR
f $DIR/file - - - - new
r $DIR/file
CONF
run "mkdir $DIR; echo old > $DIR/file"
run "/libexec/finit/tmpfiles --create --remove $CONF"
assert "The old file is removed, a new one created" "$(texec cat $DIR/file)" = "new"