tmpfiles: add the = modifier, remove a path of another kind

When there is a file where an entry wants a directory, or the other
way around, the entry fails or leaves the path as it is.  In
tmpfiles.d(5) an = after the type has the path removed first when it
is of another kind than the entry makes:

    d= /var/lib/foo 0755 foo foo

The same goes for the directories above the path, anything else in
place of one is removed.  tmpfiles ignores the =.

Remove what does not match before the b, c, d, D, f, F, L, and p
entries, the ones that make a path of one kind.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-21 17:14:12 +01:00
1 parent 37cbc12946
commit f2c0888375
5 files changed
+125 -4

No files matched your search

+2
View File
@@ -88,6 +88,7 @@ EXTRA_DIST += tmpfiles-perm.sh
EXTRA_DIST += tmpfiles-boot.sh
EXTRA_DIST += tmpfiles-clean.sh
EXTRA_DIST += tmpfiles-copy.sh
EXTRA_DIST += tmpfiles-match.sh
EXTRA_DIST += tmpfiles-order.sh
EXTRA_DIST += tmpfiles-specifier.sh
EXTRA_DIST += tmpfiles-unsupported.sh
@@ -175,6 +176,7 @@ TESTS += tmpfiles-perm.sh
TESTS += tmpfiles-boot.sh
TESTS += tmpfiles-clean.sh
TESTS += tmpfiles-copy.sh
TESTS += tmpfiles-match.sh
TESTS += tmpfiles-order.sh
TESTS += tmpfiles-specifier.sh
TESTS += tmpfiles-unsupported.sh
+63
View File
@@ -0,0 +1,63 @@
#!/bin/sh
# Verify the = modifier of tmpfiles, what is of another kind than the
# entry makes is removed first
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/match
CONF=/tmp/match.conf
kind()
{
texec stat -c %F "$1"
}
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
setup()
{
run "rm -rf $DIR; mkdir -p $DIR/dir/sub $DIR/same; mkfifo $DIR/fifo $DIR/parent; echo old > $DIR/file; echo old > $DIR/keep; echo old > $DIR/link; echo same > $DIR/same/file"
}
conf()
{
run "cat > $CONF" <<CONF
d$1 $DIR/fifo
f$1 $DIR/dir - - - - new
d$1 $DIR/file
f$1 $DIR/parent/file - - - - new
p$1 $DIR/keep
L$1 $DIR/link - - - - /dev/null
d$1 $DIR/same
f$1 $DIR/same/file
CONF
run "/libexec/finit/tmpfiles --create $CONF"
}
setup
conf ""
say 'Without = a path of another kind is left alone'
assert "Pipe for d" "$(kind $DIR/fifo)" = "fifo"
assert "Directory for f" "$(kind $DIR/dir)" = "directory"
assert "File for d" "$(kind $DIR/file)" = "regular file"
assert "Pipe as parent" "$(kind $DIR/parent)" = "fifo"
setup
conf "="
sep
say 'With = it is removed, and made anew'
assert "Pipe for d" "$(kind $DIR/fifo)" = "directory"
assert "Directory for f" "$(texec cat $DIR/dir)" = "new"
assert "File for d" "$(kind $DIR/file)" = "directory"
assert "Pipe as parent" "$(texec cat $DIR/parent/file)" = "new"
assert "File for p" "$(kind $DIR/keep)" = "fifo"
assert "File for L" "$(texec readlink $DIR/link)" = "/dev/null"
assert "Same kind is left alone" "$(texec cat $DIR/same/file)" = "same"