test-fstab-generator: fix inverted /mnt symlink guard

The test-18-options.fstab.input scenario was guarded by
"$(readlink /mnt)" != "/mnt", which is true on any normal system
since readlink prints nothing for a plain directory. This meant the
scenario was always skipped, and its fixtures were never actually
compared against generator output.

Fix the guard to check whether /mnt is a symlink directly, and repair
the pre-existing fixtures that had drifted while the scenario was
dead:

  - mnt-wantedby-automount.mount had a stale Where= value and was
    missing the escaping the generator emits for the hyphen in
    /mnt/wantedby-automount.
  - mnt-requires.mount had Requires=/After= in the wrong order.

Also extend the backslash-stripping workaround loop (used because the
.deb packager dislikes files named with a backslash) to cover
.automount units in addition to .mount/.swap, and fix an ordering bug
where -f was checked before -L, which could leave a dangling symlink
when both a unit and its drop-in symlink needed stripping.
This commit is contained in:
nikhilnrr
2026-09-22 18:48:23 +02:00
committed by Luca Boccassi
parent 0827be05dd
commit 9d27286214
11 changed files with 11 additions and 12 deletions
+5 -6
View File
@@ -67,15 +67,15 @@ test_one() (
# .deb packager seems to dislike files named with backslash. So, as a workaround, we store files # .deb packager seems to dislike files named with backslash. So, as a workaround, we store files
# without backslash in .expected. # without backslash in .expected.
for i in "$out"/**/*\\*.{mount,swap}; do for i in "$out"/**/*\\*.{mount,swap,automount}; do
k="${i//\\/}" k="${i//\\/}"
if [[ "$i" != "$k" ]]; then if [[ "$i" != "$k" ]]; then
if [[ -f "$i" ]]; then if [[ -L "$i" ]]; then
mv "$i" "$k"
elif [[ -L "$i" ]]; then
dest=$(readlink "$i") dest=$(readlink "$i")
rm "$i" rm "$i"
ln -s "${dest//\\/}" "$k" ln -s "${dest//\\/}" "$k"
elif [[ -f "$i" ]]; then
mv "$i" "$k"
fi fi
fi fi
done done
@@ -130,8 +130,7 @@ test_one() (
for f in "$src"/test-*.input; do for f in "$src"/test-*.input; do
# If /mnt is a symlink, then the expected output from this # If /mnt is a symlink, then the expected output from this
# test scenario will not match the actual output # test scenario will not match the actual output
if test "$f" = "$src/test-18-options.fstab.input" -a "$(readlink /mnt)" != "/mnt" if [[ "$f" == "$src/test-18-options.fstab.input" && -L /mnt ]]; then
then
echo "Skip $f because /mnt is a symlink" echo "Skip $f because /mnt is a symlink"
continue continue
fi fi
@@ -1 +0,0 @@
../mnt-wantedby-automount.automount
@@ -0,0 +1 @@
../mnt-wantedbyx2dautomount.automount
@@ -3,8 +3,8 @@
[Unit] [Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8) Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab SourcePath=/etc/fstab
After=foo.service
Requires=foo.service Requires=foo.service
After=foo.service
Before=local-fs.target Before=local-fs.target
After=blockdev@dev-sdx5.target After=blockdev@dev-sdx5.target
@@ -10,5 +10,5 @@ After=blockdev@dev-sdx17.target
[Mount] [Mount]
What=/dev/sdx17 What=/dev/sdx17
Where=/mnt/wantedby Where=/mnt/wantedby-automount
Options=x-systemd.wanted-by=foo.service,x-systemd.automount Options=x-systemd.wanted-by=foo.service,x-systemd.automount
@@ -1 +0,0 @@
../mnt-wantedby-automount.automount
@@ -0,0 +1 @@
../mnt-wantedbyx2dautomount.automount
@@ -3,8 +3,8 @@
[Unit] [Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8) Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab SourcePath=/etc/fstab
After=foo.service
Requires=foo.service Requires=foo.service
After=foo.service
Before=local-fs.target Before=local-fs.target
After=blockdev@dev-sdx5.target After=blockdev@dev-sdx5.target
@@ -10,5 +10,5 @@ After=blockdev@dev-sdx17.target
[Mount] [Mount]
What=/dev/sdx17 What=/dev/sdx17
Where=/mnt/wantedby Where=/mnt/wantedby-automount
Options=x-systemd.wanted-by=foo.service,x-systemd.automount Options=x-systemd.wanted-by=foo.service,x-systemd.automount