Files
finit/test/tmpfiles-arg.sh
T
Joachim Wiberg 0a2beb9b6d tmpfiles: add --prefix, to only run entries below a path
A package that ships a tmpfiles.d file wants its own paths created
when it is installed, without running every other entry on the
system:

    tmpfiles --create --prefix=/var/lib/app

Add the option, it can be given more than once.  It and
--exclude-prefix compare whole path components now, before
--exclude-prefix=/dev also left out /devices.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 18:35:36 +01:00

43 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Verify how tmpfiles reads the argument, the last field of an entry
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/arg
CONF=/tmp/arg.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 - - - - -
L $DIR/aligned - - - - /dev/null
f $DIR/dash - - - - -
f $DIR/text - - - - two words
CONF
run "/libexec/finit/tmpfiles --create $CONF"
say 'Space between the age and the argument is not part of the argument'
assert "Link target" "$(texec readlink $DIR/aligned)" = "/dev/null"
assert "File content" "$(texec cat $DIR/text)" = "two words"
say 'A lone - is no argument'
assert "Empty file" "$(texec stat -c %s $DIR/dash)" = "0"
sep
say 'With --prefix only the entries below it are run'
run "cat > $CONF" <<CONF
f $DIR/in/file
f $DIR/out/file
f $DIR/input
CONF
run "/libexec/finit/tmpfiles --create --prefix=$DIR/in $CONF"
assert "Only below the prefix" "$(texec sh -c "ls -d $DIR/in* $DIR/out* 2>/dev/null" | tr '\n' ' ')" = "$DIR/in "