misc: listfiles: improve argument passing, simplify it and make it more robust

This commit is contained in:
Nicolas Mailhot 2018-11-08 19:21:06 +01:00 committed by Igor Gnatenko
parent 61ec2ef5ba
commit c6773c14ed

View File

@ -1,15 +1,21 @@
# Some miscellaneous Fedora-related macros
# List files matching inclusion globs, excluding files matching exclusion blogs
# Parameters:
# -i "<globs>" include shell globs (also takes all other macro arguments)
# -x "<globs>" exclude shell globs
# Optional parameters:
# -i "<globs>" inclusion globs
# -x "<globs>" exclusion globs
# Globs are space-separated lists of shell globs. Such lists require %{quote:}
# use for safe rpm argument passing.
# Alternatively, set the following rpm variables before calling the macro:
# “listfiles_include” inclusion globs
# — “listfiles_exclude” exclusion globs
# Arguments passed to the macro without flags will be interpreted as inclusion
# globs.
%listfiles(i:x:) %{expand:
while IFS= read -r -d $'\\n' finc ; do
printf "%s\\n" %{?-x*} \\
| xargs -i realpath --relative-base=. '{}' \\
| grep "${finc}" >/dev/null || echo "${finc}"
done <<< $(printf "%s\\n" %{?-i*} %* | xargs -i realpath --relative-base=. '{}' | sort -u)
while IFS= read -r finc ; do
realpath -qe --relative-base=. "" %{?-x*} %{?listfiles_exclude} \\
| sort -u | grep -q "${finc}" || echo "${finc}"
done <<< $(realpath -e --relative-base=. %{?-i*} %{?listfiles_include} %* | sort -u)
}
# https://github.com/rpm-software-management/rpm/issues/581