aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2015-10-16 12:04:46 +0200
committerMichał Górny <mgorny@gentoo.org>2015-11-12 20:32:37 +0100
commite3386ff407d0e6df8e3bdc15ed42f9373b88cddb (patch)
treea9cfec597bd672ef82e631f86e1491ffe1c64a7b
parentin_iuse: Make fatal in global scope (diff)
downloadportage-e3386ff407d0e6df8e3bdc15ed42f9373b88cddb.tar.gz
portage-e3386ff407d0e6df8e3bdc15ed42f9373b88cddb.tar.bz2
portage-e3386ff407d0e6df8e3bdc15ed42f9373b88cddb.zip
eapply: Update parameter splitting to match the spec
-rw-r--r--bin/phase-helpers.sh44
1 files changed, 34 insertions, 10 deletions
diff --git a/bin/phase-helpers.sh b/bin/phase-helpers.sh
index 0c25ffe2d..5be71faab 100644
--- a/bin/phase-helpers.sh
+++ b/bin/phase-helpers.sh
@@ -997,18 +997,42 @@ if ___eapi_has_eapply; then
fi
}
- local f patch_options=() failed started_applying options_terminated
- for f; do
- if [[ ${f} == -* && -z ${options_terminated} ]]; then
- if [[ -n ${started_applying} ]]; then
- die "eapply: options need to be specified before files"
+ local patch_options=() files=()
+ local i found_doublehyphen
+ # first, try to split on --
+ for (( i = 1; i <= ${#@}; ++i )); do
+ if [[ ${@:i:1} == -- ]]; then
+ patch_options=( "${@:1:i-1}" )
+ files=( "${@:i+1}" )
+ found_doublehyphen=1
+ break
+ fi
+ done
+
+ # then, try to split on first non-option
+ if [[ -z ${found_doublehyphen} ]]; then
+ for (( i = 1; i <= ${#@}; ++i )); do
+ if [[ ${@:i:1} != -* ]]; then
+ patch_options=( "${@:1:i-1}" )
+ files=( "${@:i+1}" )
+ break
fi
- if [[ ${f} == -- ]]; then
- options_terminated=1
- else
- patch_options+=( ${f} )
+ done
+
+ # ensure that no options were interspersed with files
+ for i in "${files[@]}"; then
+ if [[ ${i} == -* ]]; then
+ die "eapply: all options must be passed before non-options"
fi
- elif [[ -d ${f} ]]; then
+ fi
+ fi
+
+ if [[ -z ${files[@]} ]]; then
+ die "eapply: no files specified"
+ fi
+
+ for i in "${files[@]}"; do
+ if [[ -d ${f} ]]; then
_eapply_get_files() {
local LC_ALL=POSIX
local prev_shopt=$(shopt -p nullglob)