public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls
@ 2018-08-08 21:34 Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 2/5] media-plugins/vdr-vdrmanager: Replace unnecessary path_exists call Michał Górny
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Michał Górny @ 2018-08-08 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Replace the unnecessary path_exists calls with plain bash -f test.
The path_exists function was only intended to be used when necessary
to deal with wildcards.

Bug: https://bugs.gentoo.org/662178
---
 media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r1.ebuild | 2 +-
 media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r2.ebuild | 2 +-
 media-plugins/vdr-live/vdr-live-2.3.1.ebuild              | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r1.ebuild b/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r1.ebuild
index 6041faafd99e..24ec6897b14f 100644
--- a/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r1.ebuild
+++ b/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r1.ebuild
@@ -90,7 +90,7 @@ pkg_postinst() {
 	elog "\tadmin:live"
 
 	if use ssl ; then
-		if path_exists -a "${ROOT}"/etc/vdr/plugins/live/live.pem; then
+		if [[ -f ${ROOT}/etc/vdr/plugins/live/live.pem ]]; then
 			einfo "found an existing SSL cert, to create a new SSL cert, run:\n"
 			einfo "emerge --config ${PN}"
 		else
diff --git a/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r2.ebuild b/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r2.ebuild
index 0dbcc0a04730..9ecf777aa274 100644
--- a/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r2.ebuild
+++ b/media-plugins/vdr-live/vdr-live-0.3.0_p20130504-r2.ebuild
@@ -93,7 +93,7 @@ pkg_postinst() {
 	elog "\tadmin:live"
 
 	if use ssl ; then
-		if path_exists -a "${ROOT}"/etc/vdr/plugins/live/live.pem; then
+		if [[ -f ${ROOT}/etc/vdr/plugins/live/live.pem ]]; then
 			einfo "found an existing SSL cert, to create a new SSL cert, run:\n"
 			einfo "emerge --config ${PN}"
 		else
diff --git a/media-plugins/vdr-live/vdr-live-2.3.1.ebuild b/media-plugins/vdr-live/vdr-live-2.3.1.ebuild
index f46cff93c6de..6a0ea6d24b88 100644
--- a/media-plugins/vdr-live/vdr-live-2.3.1.ebuild
+++ b/media-plugins/vdr-live/vdr-live-2.3.1.ebuild
@@ -86,7 +86,7 @@ pkg_postinst() {
 	elog "\tadmin:live"
 
 	if use ssl ; then
-		if path_exists -a "${ROOT}"/etc/vdr/plugins/live/live.pem; then
+		if [[ -f ${ROOT}/etc/vdr/plugins/live/live.pem ]]; then
 			einfo "found an existing SSL cert, to create a new SSL cert, run:\n"
 			einfo "emerge --config ${PN}"
 		else
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 2/5] media-plugins/vdr-vdrmanager: Replace unnecessary path_exists call
  2018-08-08 21:34 [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls Michał Górny
@ 2018-08-08 21:34 ` Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists Michał Górny
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2018-08-08 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

Replace the unnecessary path_exists calls with plain bash -f test.
The path_exists function was only intended to be used when necessary
to deal with wildcards.

Closes: https://bugs.gentoo.org/662178
---
 media-plugins/vdr-vdrmanager/vdr-vdrmanager-0.14.ebuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/media-plugins/vdr-vdrmanager/vdr-vdrmanager-0.14.ebuild b/media-plugins/vdr-vdrmanager/vdr-vdrmanager-0.14.ebuild
index 8639a6df48d1..6f324f6bcdc8 100644
--- a/media-plugins/vdr-vdrmanager/vdr-vdrmanager-0.14.ebuild
+++ b/media-plugins/vdr-vdrmanager/vdr-vdrmanager-0.14.ebuild
@@ -63,7 +63,7 @@ pkg_postinst() {
 	einfo "Add a password to /etc/conf.d/vdr.vdrmanager"
 
 	if use ssl ; then
-		if path_exists -a "${ROOT}${VDRMANAGER_SSL_KEY_FILE}.pem"; then
+		if [[ -f ${ROOT}${VDRMANAGER_SSL_KEY_FILE}.pem ]]; then
 			einfo "found an existing SSL cert, to create a new SSL cert, run:\n"
 			einfo "emerge --config ${PN}"
 		else
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists
  2018-08-08 21:34 [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 2/5] media-plugins/vdr-vdrmanager: Replace unnecessary path_exists call Michał Górny
@ 2018-08-08 21:34 ` Michał Górny
  2018-08-09 12:39   ` Michael Orlitzky
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 4/5] sys-apps/openrc: " Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function Michał Górny
  3 siblings, 1 reply; 9+ messages in thread
From: Michał Górny @ 2018-08-08 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

The option switch is meaningless for this path_exists call, so remove it
and stay with the implicit default.
---
 net-vpn/openvpn/openvpn-2.4.4.ebuild | 2 +-
 net-vpn/openvpn/openvpn-2.4.5.ebuild | 2 +-
 net-vpn/openvpn/openvpn-2.4.6.ebuild | 2 +-
 net-vpn/openvpn/openvpn-9999.ebuild  | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net-vpn/openvpn/openvpn-2.4.4.ebuild b/net-vpn/openvpn/openvpn-2.4.4.ebuild
index 16fa5b91ead4..e0f612dd20d3 100644
--- a/net-vpn/openvpn/openvpn-2.4.4.ebuild
+++ b/net-vpn/openvpn/openvpn-2.4.4.ebuild
@@ -123,7 +123,7 @@ pkg_postinst() {
 	enewgroup openvpn
 	enewuser openvpn "" "" "" openvpn
 
-	if path_exists -o "${EROOT%/}"/etc/openvpn/*/local.conf ; then
+	if path_exists "${EROOT%/}"/etc/openvpn/*/local.conf ; then
 		ewarn "WARNING: The openvpn init script has changed"
 		ewarn ""
 	fi
diff --git a/net-vpn/openvpn/openvpn-2.4.5.ebuild b/net-vpn/openvpn/openvpn-2.4.5.ebuild
index ce60c5a55f98..f5bdd9ee542c 100644
--- a/net-vpn/openvpn/openvpn-2.4.5.ebuild
+++ b/net-vpn/openvpn/openvpn-2.4.5.ebuild
@@ -124,7 +124,7 @@ pkg_postinst() {
 	enewgroup openvpn
 	enewuser openvpn "" "" "" openvpn
 
-	if path_exists -o "${EROOT%/}"/etc/openvpn/*/local.conf ; then
+	if path_exists "${EROOT%/}"/etc/openvpn/*/local.conf ; then
 		ewarn "WARNING: The openvpn init script has changed"
 		ewarn ""
 	fi
diff --git a/net-vpn/openvpn/openvpn-2.4.6.ebuild b/net-vpn/openvpn/openvpn-2.4.6.ebuild
index a52f8d6e4a8b..d2f338dc73d8 100644
--- a/net-vpn/openvpn/openvpn-2.4.6.ebuild
+++ b/net-vpn/openvpn/openvpn-2.4.6.ebuild
@@ -124,7 +124,7 @@ pkg_postinst() {
 	enewgroup openvpn
 	enewuser openvpn "" "" "" openvpn
 
-	if path_exists -o "${EROOT%/}"/etc/openvpn/*/local.conf ; then
+	if path_exists "${EROOT%/}"/etc/openvpn/*/local.conf ; then
 		ewarn "WARNING: The openvpn init script has changed"
 		ewarn ""
 	fi
diff --git a/net-vpn/openvpn/openvpn-9999.ebuild b/net-vpn/openvpn/openvpn-9999.ebuild
index 4f6a5737ccd7..54605833f397 100644
--- a/net-vpn/openvpn/openvpn-9999.ebuild
+++ b/net-vpn/openvpn/openvpn-9999.ebuild
@@ -120,7 +120,7 @@ pkg_postinst() {
 	enewgroup openvpn
 	enewuser openvpn "" "" "" openvpn
 
-	if path_exists -o "${EROOT%/}"/etc/openvpn/*/local.conf ; then
+	if path_exists "${EROOT%/}"/etc/openvpn/*/local.conf ; then
 		ewarn "WARNING: The openvpn init script has changed"
 		ewarn ""
 	fi
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 4/5] sys-apps/openrc: Remove unnecessary option switch to path_exists
  2018-08-08 21:34 [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 2/5] media-plugins/vdr-vdrmanager: Replace unnecessary path_exists call Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists Michał Górny
@ 2018-08-08 21:34 ` Michał Górny
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function Michał Górny
  3 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2018-08-08 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

The option switch is meaningless for this path_exists call, so remove it
and stay with the implicit default.
---
 sys-apps/openrc/openrc-0.34.11.ebuild | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-apps/openrc/openrc-0.34.11.ebuild b/sys-apps/openrc/openrc-0.34.11.ebuild
index 4e2ed59e45f4..dd3704b2427e 100644
--- a/sys-apps/openrc/openrc-0.34.11.ebuild
+++ b/sys-apps/openrc/openrc-0.34.11.ebuild
@@ -289,7 +289,7 @@ pkg_postinst() {
 	fi
 
 	# Handle the conf.d/local.{start,stop} -> local.d transition
-	if path_exists -o "${EROOT}"etc/conf.d/local.{start,stop} ; then
+	if path_exists "${EROOT}"etc/conf.d/local.{start,stop} ; then
 		elog "Moving your ${EROOT}etc/conf.d/local.{start,stop}"
 		elog "files to ${EROOT}etc/local.d"
 		mv "${EROOT}"etc/conf.d/local.start "${EROOT}"etc/local.d/baselayout1.start
-- 
2.18.0



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function
  2018-08-08 21:34 [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls Michał Górny
                   ` (2 preceding siblings ...)
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 4/5] sys-apps/openrc: " Michał Górny
@ 2018-08-08 21:34 ` Michał Górny
  2018-08-09  5:05   ` Ulrich Mueller
  2018-08-09  6:13   ` M. J. Everitt
  3 siblings, 2 replies; 9+ messages in thread
From: Michał Górny @ 2018-08-08 21:34 UTC (permalink / raw
  To: gentoo-dev; +Cc: 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] <paths>
+# @USAGE: <paths>
 # @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..000000000000
--- 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



^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function Michał Górny
@ 2018-08-09  5:05   ` Ulrich Mueller
  2018-08-09  7:34     ` Michał Górny
  2018-08-09  6:13   ` M. J. Everitt
  1 sibling, 1 reply; 9+ messages in thread
From: Ulrich Mueller @ 2018-08-09  5:05 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

>>>>> 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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function Michał Górny
  2018-08-09  5:05   ` Ulrich Mueller
@ 2018-08-09  6:13   ` M. J. Everitt
  1 sibling, 0 replies; 9+ messages in thread
From: M. J. Everitt @ 2018-08-09  6:13 UTC (permalink / raw
  To: gentoo-dev, Michał Górny


[-- Attachment #1.1: Type: text/plain, Size: 662 bytes --]

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.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function
  2018-08-09  5:05   ` Ulrich Mueller
@ 2018-08-09  7:34     ` Michał Górny
  0 siblings, 0 replies; 9+ messages in thread
From: Michał Górny @ 2018-08-09  7:34 UTC (permalink / raw
  To: gentoo-dev

[-- Attachment #1: Type: text/plain, Size: 548 bytes --]

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

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 963 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists
  2018-08-08 21:34 ` [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists Michał Górny
@ 2018-08-09 12:39   ` Michael Orlitzky
  0 siblings, 0 replies; 9+ messages in thread
From: Michael Orlitzky @ 2018-08-09 12:39 UTC (permalink / raw
  To: gentoo-dev

On 08/08/2018 05:34 PM, Michał Górny wrote:
>  
> -	if path_exists -o "${EROOT%/}"/etc/openvpn/*/local.conf ; then
> +	if path_exists "${EROOT%/}"/etc/openvpn/*/local.conf ; then
>  		ewarn "WARNING: The openvpn init script has changed"
>  		ewarn ""
>  	fi

Not that this warning is at all helpful, but it's obsolete (the change
was over ten years ago). The whole "if" block can go.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-08-09 12:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-08 21:34 [gentoo-dev] [PATCH 1/5] media-plugins/vdr-live: Replace unnecessary path_exists calls Michał Górny
2018-08-08 21:34 ` [gentoo-dev] [PATCH 2/5] media-plugins/vdr-vdrmanager: Replace unnecessary path_exists call Michał Górny
2018-08-08 21:34 ` [gentoo-dev] [PATCH 3/5] net-vpn/openvpn: Remove unnecessary option switch to path_exists Michał Górny
2018-08-09 12:39   ` Michael Orlitzky
2018-08-08 21:34 ` [gentoo-dev] [PATCH 4/5] sys-apps/openrc: " Michał Górny
2018-08-08 21:34 ` [gentoo-dev] [PATCH 5/5] eutils.eclass: Restore the original path_exists function Michał Górny
2018-08-09  5:05   ` Ulrich Mueller
2018-08-09  7:34     ` Michał Górny
2018-08-09  6:13   ` M. J. Everitt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox