Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function

2018-08-09 Thread Michał Górny
W dniu czw, 09.08.2018 o godzinie 07∶05 +0200, użytkownik Ulrich Mueller
napisał:
> > > > > > On Wed, 8 Aug 2018, Michał Górny wrote:
> > Alternatively, we could remove the function entirely and inline its
> > use in the three packages that need it.
> 
> Sounds like a better plan. Removing the options is an incompatible
> change anyway, so maybe removing the function would be a cleaner
> solution? Especially if it's so little used.
> 

Sure.  Will prepare another patch series soonish.

-- 
Best regards,
Michał Górny


signature.asc
Description: This is a digitally signed message part


Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function

2018-08-08 Thread M. J. Everitt
On 08/08/18 22:34, Michał Górny wrote [excerpted]:
> +# Example:
> +# @CODE
> +# if path_exists "${ROOT}"/etc/foo.d/*.conf; then
> +#   do_something
> +# fi
> +# @CODE
>  path_exists() {
> - local opt=$1
> - [[ ${opt} == -[ao] ]] && shift || opt="-a"
> -
> - # no paths -> return false
> - # same behavior as: [[ -e "" ]]
> - [[ $# -eq 0 ]] && return 1
> -
> - local p r=0
> - for p in "$@" ; do
> - [[ -e ${p} ]]
> - : $(( r += $? ))
> + local p
> + for p; do
> + [[ -e ${p} ]] && return 0
>   done
You seem to have lost the inclusion of the function parameters in the
execution code - was this intentional?!
Regards,
Michael.



signature.asc
Description: OpenPGP digital signature


Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function

2018-08-08 Thread Ulrich Mueller
> On Wed, 8 Aug 2018, Michał Górny wrote:

> Alternatively, we could remove the function entirely and inline its
> use in the three packages that need it.

Sounds like a better plan. Removing the options is an incompatible
change anyway, so maybe removing the function would be a cleaner
solution? Especially if it's so little used.

Ulrich



[gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function

2018-08-08 Thread Michał Górny
The original path_exists function as submitted by me was a trivial
function to facilitate for file existence checks with wildcards.
However, its purpose was defeated by meaningless featurism.
As a result, half of the current uses was entirely mistaken (it's *not*
a replacement for trivial -e/-f tests!) and the other half needlessly
specified a meaningless -a/-o option which did not affect the result.

After fixing all the (few) uses, remove the complexity and restore
the original API.  This also fixes its behavior when it happens to match
a multiple of 256 files.

As a fun fact, the new 'or' default behavior would also keep the old
uses working (since the option would be ignored as first unmatched file
and the function would proceed with the next parameter).

Alternatively, we could remove the function entirely and inline its use
in the three packages that need it.
---
 eclass/eutils.eclass   | 41 ++
 eclass/tests/eutils_path_exists.sh | 35 -
 2 files changed, 19 insertions(+), 57 deletions(-)
 delete mode 100755 eclass/tests/eutils_path_exists.sh

diff --git a/eclass/eutils.eclass b/eclass/eutils.eclass
index 9b4767e1874a..98a1bc7bf56e 100644
--- a/eclass/eutils.eclass
+++ b/eclass/eutils.eclass
@@ -182,32 +182,29 @@ make_wrapper() {
 }
 
 # @FUNCTION: path_exists
-# @USAGE: [-a|-o] 
+# @USAGE: 
 # @DESCRIPTION:
-# Check if the specified paths exist.  Works for all types of paths
-# (files/dirs/etc...).  The -a and -o flags control the requirements
-# of the paths.  They correspond to "and" and "or" logic.  So the -a
-# flag means all the paths must exist while the -o flag means at least
-# one of the paths must exist.  The default behavior is "and".  If no
-# paths are specified, then the return value is "false".
+# Check if the specified paths exist.  This is intended to be used
+# with filename expansion when the built-in bash tests can't work
+# and not as a generic replacement.
+#
+# Returns true if at least one path exists (matched the pattern).
+# Returns false otherwise (pattern did not match and was passed
+# verbatim or expanded into an empty list).
+#
+# Example:
+# @CODE
+# if path_exists "${ROOT}"/etc/foo.d/*.conf; then
+#   do_something
+# fi
+# @CODE
 path_exists() {
-   local opt=$1
-   [[ ${opt} == -[ao] ]] && shift || opt="-a"
-
-   # no paths -> return false
-   # same behavior as: [[ -e "" ]]
-   [[ $# -eq 0 ]] && return 1
-
-   local p r=0
-   for p in "$@" ; do
-   [[ -e ${p} ]]
-   : $(( r += $? ))
+   local p
+   for p; do
+   [[ -e ${p} ]] && return 0
done
 
-   case ${opt} in
-   -a) return $(( r != 0 )) ;;
-   -o) return $(( r == $# )) ;;
-   esac
+   return 1
 }
 
 # @FUNCTION: use_if_iuse
diff --git a/eclass/tests/eutils_path_exists.sh 
b/eclass/tests/eutils_path_exists.sh
deleted file mode 100755
index 00a89c7e446d..
--- a/eclass/tests/eutils_path_exists.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-# Copyright 1999-2015 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-
-source tests-common.sh
-
-inherit eutils
-
-test-path_exists() {
-   local exp=$1; shift
-   tbegin "path_exists($*) == ${exp}"
-   path_exists "$@"
-   [[ ${exp} -eq $? ]]
-   tend $?
-}
-
-test-path_exists 1
-test-path_exists 1 -a
-test-path_exists 1 -o
-
-good="/ . tests-common.sh /bin/bash"
-test-path_exists 0 ${good}
-test-path_exists 0 -a ${good}
-test-path_exists 0 -o ${good}
-
-bad="/asjdkfljasdlfkja jlakjdsflkasjdflkasdjflkasdjflaskdjf"
-test-path_exists 1 ${bad}
-test-path_exists 1 -a ${bad}
-test-path_exists 1 -o ${bad}
-
-test-path_exists 1 ${good} ${bad}
-test-path_exists 1 -a ${good} ${bad}
-test-path_exists 0 -o ${good} ${bad}
-
-texit
-- 
2.18.0