1 |
here's what i'll commit to eutils.eclass: |
2 |
|
3 |
# @FUNCTION: path_exists |
4 |
# @USAGE: [-a|-o] <paths> |
5 |
# @DESCRIPTION: |
6 |
# Check if the specified paths exist. Works for all types of paths |
7 |
# (files/dirs/etc...). The -a and -o flags control the requirements |
8 |
# of the paths. They correspond to "and" and "or" logic. So the -a |
9 |
# flag means all the paths must exist while the -o flag means at least |
10 |
# one of the paths must exist. The default behavior is "and". If no |
11 |
# paths are specified, then the return value is "false". |
12 |
path_exists() { |
13 |
local opt=$1 |
14 |
[[ ${opt} == -[ao] ]] && shift || opt="-a" |
15 |
|
16 |
# no paths -> return false |
17 |
# same behavior as: [[ -e "" ]] |
18 |
[[ $# -eq 0 ]] && return 1 |
19 |
|
20 |
local p r=0 |
21 |
for p in "$@" ; do |
22 |
[[ -e ${p} ]] |
23 |
: $(( r += $? )) |
24 |
done |
25 |
|
26 |
case ${opt} in |
27 |
-a) return $(( r != 0 )) ;; |
28 |
-o) return $(( r == $# )) ;; |
29 |
esac |
30 |
} |
31 |
-mike |