Skip to content

Commit

Permalink
sideload-repo-systemd: Set 'nullglob' option
Browse files Browse the repository at this point in the history
Previously, if there were no existing symlinks, this script would fail:

    wjt@camille:~$ LANG=en_GB.utf8 bash -x /usr/libexec/flatpak-create-sideload-symlinks.sh /run/media/wjt
    + test 1 -eq 1
    + test -d /run/media/wjt
    + for f in "$1"/*
    + test -d '/run/media/wjt/*'
    + continue
    + for f in /run/flatpak/sideload-repos/automount-*
    + test -e '/run/flatpak/sideload-repos/automount-*'
    + rm '/run/flatpak/sideload-repos/automount-*'
    rm: cannot remove '/run/flatpak/sideload-repos/automount-*': No such file or directory

This is due to the surprising POSIX shell behaviour that a glob that
matches no files expands to itself, rather than to the empty list.

http:https://mywiki.wooledge.org/BashFAQ/004

The POSIX solution is to add 'test -L $f' inside the loop to check if
the variable actually exists.  The first loop in this script uses this
technique: it has a 'test -d "$f"', seen in the trace above.

Bash implements a 'nullglob' feature which gives globs the behaviour you
might hope for. Set it in this script.
  • Loading branch information
wjt committed Sep 18, 2020
1 parent 6b46d9a commit 8c61324
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions sideload-repos-systemd/flatpak-create-sideload-symlinks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# This script is intended to be run by flatpak-sideload-usb-repo.service
shopt -s nullglob

if ! test $# -eq 1 || ! test -d "$1"; then
echo "Error: first argument must be a directory"
Expand Down

0 comments on commit 8c61324

Please sign in to comment.