Files
finit/test/tmpfiles-order.sh
T
Joachim Wiberg ddb4f18fa9 tmpfiles: add --dry-run, to show what would be run
There was no way to see what the tmpfiles.d files on a system amount
to, short of running them:

    tmpfiles --dry-run --create --remove --boot

With -n or --dry-run each entry that would be run is printed, with
what would be done, remove, clean, or create, in the order it would
be.  Nothing is changed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
2026-11-20 19:10:04 +01:00

39 lines
1000 B
Bash
Executable File

#!/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"
sep
say 'With --dry-run it only tells what it would do, in that order'
run "cat > $CONF" <<CONF
f $DIR/dry - - - - text
r $DIR/file
d $DIR/sub - - - 1d
CONF
out=$(texec /libexec/finit/tmpfiles --dry-run --create --remove --clean "$CONF")
assert "What it would do" "$(echo "$out" | tr '\n' ';')" = "remove r $DIR/file;clean d $DIR/sub, older than 1d;create f $DIR/dry text;create d $DIR/sub;"
assert "Nothing is done" "$(texec ls $DIR)" = "file"