Files
finit/test/tmpfiles-attr.sh
T
Joachim Wiberg 3ff5c33217 tmpfiles: add the h and H entries, file attributes
tmpfiles.d(5) has h to set file attributes, as chattr(1) does, and H
for the path and everything below it:

    h /var/log/journal - - - - +C

tmpfiles skipped them as unsupported.

Add both.  The argument is the letters chattr(1) has, after a + to
add them, which is the default, a - to remove them, or a = to have
just these set.  Only files and directories have such attributes,
anything else is left alone.

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

72 lines
1.7 KiB
Bash
Executable File

#!/bin/sh
# Verify the t and T entries of tmpfiles, extended attributes, and the
# h and H entries, file attributes. On the file system of the sysroot,
# not all attributes work on tmpfs.
set -eu
TEST_DIR=$(dirname "$0")
DIR=/attr-test
CONF=/tmp/attr.conf
tmpfiles()
{
run "cat > $CONF"
run "/libexec/finit/tmpfiles --create $CONF"
}
# The sysroot has setfattr but no getfattr, removing one that is not
# set fails
assert_xattr()
{
assert "$1 has $2" "$(texec sh -c "setfattr -x $2 $1 && echo yes || echo no")" = "yes"
}
assert_attr()
{
assert "Attributes of $1 have $2: $3" \
"$(texec sh -c "lsattr -d $1 | cut -d' ' -f1 | grep -q $2 && echo yes || echo no")" = "$3"
}
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
run "mkdir -p $DIR/tree/sub; touch $DIR/file $DIR/tree/sub/file"
sep
say 't sets extended attributes, T on everything below the path too'
tmpfiles <<CONF
t $DIR/file - - - - user.one=1 user.two="two words"
T $DIR/tree - - - - user.tree=yes
CONF
assert_xattr $DIR/file user.one
assert_xattr $DIR/file user.two
assert_xattr $DIR/tree user.tree
assert_xattr $DIR/tree/sub/file user.tree
sep
say 'h sets file attributes, H on everything below the path too'
tmpfiles <<CONF
h $DIR/file - - - - +dA
H $DIR/tree - - - - d
CONF
assert_attr $DIR/file d yes
assert_attr $DIR/file A yes
assert_attr $DIR/tree/sub/file d yes
say 'With - they are taken away, with = only those named are left'
tmpfiles <<CONF
h $DIR/file - - - - -d
H $DIR/tree - - - - =A
CONF
assert_attr $DIR/file d no
assert_attr $DIR/file A yes
assert_attr $DIR/tree/sub/file d no
assert_attr $DIR/tree/sub/file A yes