Commit 802fc32c authored by Mark Hills's avatar Mark Hills
Browse files

Prevent an empty match being seen as an error condition

Because grep returns non-zero error code if no matches were found,
the script considers this an error condition.

Switch to using "find -regex". I chose the posix-egrep syntax as this
seems to be one of the standard formats which gives the most concise
syntax for the regex itself.

When this code was originally put in place there was some debate, and
I wrote on the mailing list (29 Jan 2012):

> I merged the changes just now, but I did it using grep instead of
> iregex. And found that grep does not do a full-string match by default.
>
> I chose grep -E for a couple of minor reasons:
>
> * more widely available
>
> * matching in a separate thread to the 'find' could give marginally
>   better performance
>
> Nothing seriously wrong with the other method though :-) Anyway, it's in
> the beta now, so everyone can give it a test.

In light of the information on error conditions, switch to the regex
case. This breaks compatibility with non-GNU find implementations.
parent 29bec72e
......@@ -15,8 +15,8 @@ set -eu -o pipefail # pipefail requires bash, not sh
PATHNAME="$1"
if [ -d "$PATHNAME" ]; then
find -L "$PATHNAME" -type f |
grep -iE '\.(ogg|oga|aac|cdaudio|mp3|flac|wav|aif|aiff|m4a|wma)$'
find -L "$PATHNAME" -type f -regextype posix-egrep \
-iregex '.*\.(ogg|oga|aac|cdaudio|mp3|flac|wav|aif|aiff|m4a|wma)'
else
cat "$PATHNAME"
fi |
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment