mirror of
https://github.com/troglobit/finit.git
synced 2026-11-23 20:11:44 +00:00
An x or X entry can have an age of its own in tmpfiles.d(5). What it
keeps from the cleaning of the directory above is then cleaned by that
age instead:
d /tmp 1777 root root 10d
x /tmp/build - - - 30d
tmpfiles does not read the age, so /tmp/build is never cleaned.
Clean the paths of such an entry by its age, with the entry itself
left out of what is kept.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
118 lines
3.0 KiB
Bash
Executable File
118 lines
3.0 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 ""
|
|
|
|
sep
|
|
say 'Age 0 removes everything, no age nothing'
|
|
run "mkdir -p $DIR/zero $DIR/none; touch $DIR/zero/file $DIR/none/file"
|
|
clean <<CONF
|
|
d $DIR/zero - - - 0
|
|
d $DIR/none - - - -
|
|
d $DIR/none
|
|
CONF
|
|
assert_left $DIR/zero ""
|
|
assert_left $DIR/none "file "
|
|
|
|
sep
|
|
say 'Ages with several units, ms, and what a path matched by e holds'
|
|
run "mkdir -p $DIR/units $DIR/msec $DIR/long $DIR/glob-1 $DIR/glob-2 $DIR/level/sub $DIR/by-all $DIR/by-m"
|
|
run "touch $DIR/units/file $DIR/msec/file $DIR/long/file $DIR/glob-1/file $DIR/glob-2/file"
|
|
run "touch $DIR/level/file $DIR/level/sub/file $DIR/by-all/file $DIR/by-m/file"
|
|
sleep 2
|
|
clean <<CONF
|
|
d $DIR/units - - - 0m1s
|
|
d $DIR/msec - - - 1500ms
|
|
d $DIR/long - - - 1h1s
|
|
e $DIR/glob-* - - - 1s
|
|
CONF
|
|
assert_left $DIR/units ""
|
|
assert_left $DIR/msec ""
|
|
assert_left $DIR/long "file "
|
|
assert_left $DIR/glob-1 ""
|
|
assert_left $DIR/glob-2 ""
|
|
|
|
sep
|
|
say 'With ~ what is right in the directory is kept'
|
|
clean <<CONF
|
|
d $DIR/level - - - ~1s
|
|
CONF
|
|
assert_left $DIR/level "file sub "
|
|
assert_left $DIR/level/sub ""
|
|
|
|
sep
|
|
say 'The timestamps to go by can be chosen, here not the change time'
|
|
run "cat > $CONF" <<CONF
|
|
d $DIR/by-all - - - 1s
|
|
d $DIR/by-m - - - am:1s
|
|
d $DIR/by-all - - - AM:1s
|
|
d $DIR/by-all - - - :1s
|
|
CONF
|
|
run "chmod 600 $DIR/by-all/file $DIR/by-m/file; /libexec/finit/tmpfiles --clean $CONF"
|
|
assert_left $DIR/by-all "file "
|
|
assert_left $DIR/by-m ""
|
|
|
|
sep
|
|
say 'An x entry with an age of its own has what it keeps cleaned by that age'
|
|
run "mkdir -p $DIR/own/keep $DIR/own/long; touch $DIR/own/file $DIR/own/keep/file $DIR/own/long/file"
|
|
sleep 2
|
|
clean <<CONF
|
|
d $DIR/own - - - 1s
|
|
x $DIR/own/keep - - - 1h
|
|
x $DIR/own/lon* - - - 1s
|
|
CONF
|
|
assert_left $DIR/own "keep long "
|
|
assert_left $DIR/own/keep "file "
|
|
assert_left $DIR/own/long ""
|