tmpfiles: check relative L? targets beside the link
Relative symlink targets are resolved from the directory containing the
link. Make the L? existence check use the same rule.
Reproducer:
tmp=$(mktemp -d /tmp/tmpfiles-link.XXXXXX)
conf=$(mktemp /tmp/tmpfiles-conf.XXXXXX)
printf data >"$tmp/target"
printf 'L? %s/link - - - - target\n' "$tmp" >"$conf"
systemd-tmpfiles --create --dry-run "$conf"
Before:
The target was checked root-relative, not beside the link.
Follow-up for b5dc805583.
This commit is contained in:
@@ -54,3 +54,36 @@ EOF
|
||||
)"
|
||||
[[ "$output" == *"Would create directory $root/run/test"* ]]
|
||||
[[ "$output" != *"$root$root"* ]]
|
||||
|
||||
# Check that L? resolves relative targets from the symlink's parent directory.
|
||||
root='/tmp/L/4'
|
||||
rm -rf "$root"
|
||||
mkdir -p "$root"
|
||||
touch "$root/target"
|
||||
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
L? $root/link - - - - target
|
||||
EOF
|
||||
test "$(readlink "$root/link")" = "target"
|
||||
|
||||
rm -f "$root/link" "$root/target"
|
||||
systemd-tmpfiles --create - <<EOF
|
||||
L? $root/link - - - - target
|
||||
EOF
|
||||
test ! -e "$root/link"
|
||||
|
||||
# Check the same relative target lookup with --root=.
|
||||
rm -rf "$root"
|
||||
mkdir -p "$root/dir"
|
||||
touch "$root/dir/target"
|
||||
|
||||
systemd-tmpfiles --create --root="$root" - <<EOF
|
||||
L? /dir/link - - - - target
|
||||
EOF
|
||||
test "$(readlink "$root/dir/link")" = "target"
|
||||
|
||||
rm -f "$root/dir/link" "$root/dir/target"
|
||||
systemd-tmpfiles --create --root="$root" - <<EOF
|
||||
L? /dir/link - - - - target
|
||||
EOF
|
||||
test ! -e "$root/dir/link"
|
||||
|
||||
Reference in New Issue
Block a user