[pacman-dev] [PATCH 7/7] libmakepkg: disallow using 'any' with other arches

Eli Schwartz eschwartz at archlinux.org
Wed Jun 13 01:30:58 UTC 2018


On 06/11/2018 06:57 PM, Morgan Adamiec wrote:
> On Mon, 11 Jun 2018 at 22:27, Eli Schwartz <eschwartz at archlinux.org> wrote:
>>
>> On 06/11/2018 04:53 PM, morganamilo wrote:
>>> Error if the arch array contains any and any other values. This also
>>> fixes a bug where the check for `$arch == 'any'` which only evaluated
>>> the first value in the array, meaning the rest of the values would not
>>> be linted.
>>>
>>> Signed-off-by: morganamilo <morganamilo at gmail.com>
>>> ---
>>>  scripts/libmakepkg/lint_pkgbuild/arch.sh.in | 7 ++++++-
>>>  1 file changed, 6 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
>>> index f2c80c73..8a1d2c11 100644
>>> --- a/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
>>> +++ b/scripts/libmakepkg/lint_pkgbuild/arch.sh.in
>>> @@ -38,11 +38,16 @@ lint_arch() {
>>>               return 1
>>>       fi
>>>
>>> -     if [[ $arch == 'any' ]]; then
>>> +     if [[ $arch == 'any' && ${#arch[@]} == 1 ]]; then
>>
>>
>> [[ ${#arch[@]} = 1 ]] is a string comparison (the test keyword or
>> builtin uses -eq to handle numeric values).
>>
>> (( ${#arch[@]} == 1 )) is an integer comparison (shell arithmetic is
>> generally superior when available).
>>
>> I specifically mentioned the latter in my previous email.
>>
>> --
>> Eli Schwartz
>> Bug Wrangler and Trusted User
>>
> 
> Yeah I see that now. Bash Isn't really my thing so I didn't really
> take note of the (( ))
> 
> Just to be sure before I send another patch it would be
> if [[ $arch == 'any' && (( ${#arch[@]} == 1 )) ]];
> right? With the (( )) nested in the [[ ]].
> 
> Thanks for the feedback by the way, It helps a lot.

$ set -x
$ [[ $arch = 'any' && (( ${#arch[@]} == 1 )) ]]
+ [[ any = \a\n\y ]]
+ [[ 1 == 1 ]]

The () inside an [[ ]] results in logical grouping (twice), but it's
still the test operator, not shell arithmetic.

So just use:

[[ $arch = any ]] && (( ${#arch[@]} == 1 ))

-- 
Eli Schwartz
Bug Wrangler and Trusted User

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20180612/3f690393/attachment-0001.asc>


More information about the pacman-dev mailing list