Files
finit/test/tmpfiles-clean.sh
T
Joachim Wiberg 60cd11ab23 tmpfiles: keep what x and X entries name from being cleaned
The x and X entries were read and ignored, so a path that a package
had marked to be left alone was cleaned like the rest:

    d /var/tmp      - - - 30d
    x /var/tmp/keep

    tmpfiles --clean t.conf

This removed what was old in /var/tmp/keep.

Gather the x and X entries of all files in a pass before the cleaning,
they may come after the entry they apply to, or in another file.  x
keeps the path and what is in it, X the path alone.  A directory that
is not empty afterwards is no longer warned about.

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

56 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Verify tmpfiles --clean, removing what is older than the age of an entry
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/clean
CONF=/tmp/clean.conf
clean()
{
run "cat > $CONF"
run "/libexec/finit/tmpfiles --clean $CONF"
}
assert_left()
{
assert "Left in $1: $2" "$(texec ls "$1" | tr '\n' ' ')" = "$2"
}
test_teardown()
{
say "Running test teardown."
run "umount $DIR/old/mnt 2>/dev/null; rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "mkdir -p $DIR/old/mnt $DIR/old/sub $DIR/young; touch $DIR/old/file $DIR/old/sub/file $DIR/young/file"
run "mount -t tmpfs none $DIR/old/mnt; touch $DIR/old/mnt/file"
sleep 2
sep
say 'Only what is older than the age is removed, and nothing on another file system'
clean <<CONF
d $DIR/old - - - 1s
d $DIR/young - - - 1h
CONF
assert_left $DIR/young "file "
assert_left $DIR/old "mnt "
assert_left $DIR/old/mnt "file "
sep
say 'x keeps a path and what is in it, X only the path itself'
run "mkdir -p $DIR/keep/all $DIR/keep/dir; touch $DIR/keep/file $DIR/keep/all/file $DIR/keep/dir/file"
sleep 2
clean <<CONF
d $DIR/keep - - - 1s
x $DIR/keep/a*
X $DIR/keep/dir/
CONF
assert_left $DIR/keep "all dir "
assert_left $DIR/keep/all "file "
assert_left $DIR/keep/dir ""