tmpfiles: use fd_get_path() even less excessively

A follow-up for commit 9d874aec45.

This patch makes "path" parameter mandatory in fd_set_*() helpers removing the
need to use fd_get_path() when NULL was passed. The caller is supposed to pass
the fd anyway so assuming that it also knows the path should be safe.

Actually, the only case where this was useful (or used) was when we were
walking through directory trees (in item_do()). But even in those cases the
paths could be constructed trivially, which is still better than relying on
fd_get_path() (which is an ugly API).

A very succinct test case is also added for 'z/Z' operators so the code dealing
with recursive operators is tested minimally.
This commit is contained in:
Franck Bui
2018-08-21 19:48:08 +02:00
committed by Zbigniew Jędrzejewski-Szmek
parent 0566668016
commit 4dc7bfdf4f
2 changed files with 63 additions and 41 deletions
+45
View File
@@ -0,0 +1,45 @@
#! /bin/bash
set -e
set -x
rm -fr /tmp/{z,Z}
mkdir /tmp/{z,Z}
#
# 'z'
#
mkdir /tmp/z/d{1,2}
touch /tmp/z/f1 /tmp/z/d1/f11 /tmp/z/d2/f21
systemd-tmpfiles --create - <<EOF
z /tmp/z/f1 0755 daemon daemon - -
z /tmp/z/d1 0755 daemon daemon - -
EOF
test $(stat -c %U:%G /tmp/z/f1) = "daemon:daemon"
test $(stat -c %U:%G /tmp/z/d1) = "daemon:daemon"
test $(stat -c %U:%G /tmp/z/d1/f11) = "root:root"
systemd-tmpfiles --create - <<EOF
z /tmp/z/d2/* 0755 daemon daemon - -
EOF
test $(stat -c %U:%G /tmp/z/d2/f21) = "daemon:daemon"
#
# 'Z'
#
mkdir /tmp/Z/d1 /tmp/Z/d1/d11
touch /tmp/Z/f1 /tmp/Z/d1/f11 /tmp/Z/d1/d11/f111
systemd-tmpfiles --create - <<EOF
Z /tmp/Z/f1 0755 daemon daemon - -
Z /tmp/Z/d1 0755 daemon daemon - -
EOF
test $(stat -c %U:%G /tmp/Z/f1) = "daemon:daemon"
test $(stat -c %U:%G /tmp/Z/d1) = "daemon:daemon"
test $(stat -c %U:%G /tmp/Z/d1/d11) = "daemon:daemon"
test $(stat -c %U:%G /tmp/Z/d1/f11) = "daemon:daemon"
test $(stat -c %U:%G /tmp/Z/d1/d11/f111) = "daemon:daemon"