Files
finit/test/tmpfiles-files.sh
T
Joachim Wiberg fa430d0a02 tmpfiles: read a file named - from standard input
A package script that has its entries at hand, and not yet in a file,
gives them to systemd-tmpfiles on standard input:

    echo 'd /var/lib/app 0750 app app' | tmpfiles --create -

Finit's tmpfiles took - as the name of a file and failed to open it.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-21 19:23:49 +01:00

53 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# Verify which tmpfiles.d files are read, in what order, and that the
# first entry for a path is the one that counts
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/files
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"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "mkdir -p $LIB $ETC"
run "cat > $LIB/50-test.conf" <<CONF
f $DIR/same - - - - lib
f $DIR/masked - - - - lib
CONF
run "cat > $ETC/50-test.conf" <<CONF
f $DIR/same - - - - etc
CONF
run "cat > $LIB/10-test.conf" <<CONF
f $DIR/first - - - - one
CONF
run "cat > $ETC/20-test.conf" <<CONF
f $DIR/first - - - - two
w+ $DIR/first - - - - +three
w+ $DIR/first - - - - +four
CONF
run "/libexec/finit/tmpfiles --create --prefix=$DIR"
say 'A file in /etc is read in place of one of the same name in /usr/lib'
assert "Entry from /etc" "$(texec cat $DIR/same)" = "etc"
assert "None from /usr/lib" "$(texec sh -c "ls $DIR | grep -c masked")" = "0"
sep
say 'Files are read by name, and the first entry for a path counts'
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 'A file named - is read from standard input'
run "echo 'f $DIR/stdin' | /libexec/finit/tmpfiles --create -"
assert "Entry on stdin" "$(texec sh -c "ls $DIR | grep -c stdin")" = "1"