Gentoo Archives: gentoo-dev

From: "Amadeusz Żołnowski" <aidecoe@×××××××.name>
To: gentoo-dev <gentoo-dev@l.g.o>
Subject: Re: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild
Date: Wed, 13 Oct 2010 19:57:32
Message-Id: 1286999464-sup-1533@etiriah
In Reply to: Re: [gentoo-dev] Re: [gentoo-commits] gentoo-x86 commit in net-misc/openvpn: ChangeLog openvpn-2.1.3.ebuild by "Amadeusz Żołnowski"
1 Excerpts from Amadeusz Żołnowski's message of Wed Oct 13 21:20:01 +0200 2010:
2 > Excerpts from Mike Frysinger's message of Wed Oct 13 20:51:35 +0200 2010:
3 > > path_exists() {
4 > > local opt=$1
5 > > [[ ${opt} == -[ao] ]] && shift || opt="-a"
6 > >
7 > > # no paths -> return false
8 > > # same behavior as: [[ -e "" ]]
9 > > [[ $# -eq 0 ]] && return 1
10 > >
11 > > local p r=0
12 > > for p in "$@" ; do
13 > > [[ -e ${p} ]]
14 > > : $(( r += $? ))
15 > > done
16 >
17 > 1) Why check every path in both "and" and "or" cases?
18 >
19 > 2) Even simpler:
20 > for p; do
21 > [[ -e $p ]]
22 > ((r+=$?))
23 > done
24 >
25 > >
26 > > case ${opt} in
27 > > -a) return $(( r != 0 )) ;;
28 > > -o) return $(( r == $# )) ;;
29 > > esac
30 > > }
31
32
33 And why putting different tasks into one function? My suggestion:
34
35 any_paths() {
36 local f
37
38 for f; do
39 [[ -e $f ]] && return 0
40 done
41
42 return 1
43 }
44
45 all_paths() {
46 local f
47
48 for f; do
49 [[ -e $f ]] || return 1
50 done
51
52 return 0
53 }
54
55
56 Isn't it simpler approach? And have benfits over 2in1:
57
58 1) More readable in use.
59 2) More efficient.
60 3) 1 + 1 < 2 in this case ;-)
61 --
62 Amadeusz Żołnowski
63
64 PGP key fpr: C700 CEDE 0C18 212E 49DA 4653 F013 4531 E1DB FAB5

Attachments

File name MIME type
signature.asc application/pgp-signature

Replies