diff options
Diffstat (limited to 'bin/patch-wrapper.in')
-rwxr-xr-x | bin/patch-wrapper.in | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/bin/patch-wrapper.in b/bin/patch-wrapper.in index 5f2f107..caa600f 100755 --- a/bin/patch-wrapper.in +++ b/bin/patch-wrapper.in @@ -64,6 +64,18 @@ backup_files() { fi } +find_pipe_patch() { + declare patch=$1 + patch=${patch//\[/\\[} + patch=${patch//\]/\\]} + set -- $(stat -c $'%a %N\n' /proc/*/fd/* 2>/dev/null \ + | sed -nre "s,^300 \`(/proc/.*/fd)/.*' -> \`$patch'$,\\1,p") + set -- $(stat -c $'%a %N\n' $1/* 2>/dev/null \ + | sed -nre "s,^500 \`.*' -> \`(.*)',\\1,p") + [ $# -eq 1 ] || set -- "$patch" + echo "$1" +} + options=`getopt -q -o bsB:z:i:p:d: \ --long quiet,silent,backup,backup-if-mismatch \ --long no-backup-if-mismatch,prefix: \ @@ -149,17 +161,26 @@ else fi fi -find_pipe_patch() { - declare patch=$1 - patch=${patch//\[/\\[} - patch=${patch//\]/\\]} - set -- $(stat -c $'%a %N\n' /proc/*/fd/* 2>/dev/null \ - | sed -nre "s,^300 \`(/proc/.*/fd)/.*' -> \`$patch'$,\\1,p") - set -- $(stat -c $'%a %N\n' $1/* 2>/dev/null \ - | sed -nre "s,^500 \`.*' -> \`(.*)',\\1,p") - [ $# -eq 1 ] || set -- "$patch" - echo "$1" -} +if [ -z "$cannot_handle" ] +then + if [ -n "$opt_input" ] + then + patch=$opt_input + elif [ -e /proc/self/fd/0 ] + then + patch=$(readlink /proc/self/fd/0) + if [[ "$patch" =~ "^pipe:" ]] + then + patch=$(find_pipe_patch "$patch") + fi + fi + patch=${patch#$PWD/} + + if [ ! -e "$patch" ] + then + cannot_handle=1 + fi +fi if [ -n "$cannot_handle" ] then @@ -167,18 +188,6 @@ then exit fi -if [ -n "$opt_input" ] -then - patch=$opt_input -else - patch=$(readlink /proc/self/fd/0) - if [[ "$patch" =~ "^pipe:" ]] - then - patch=$(find_pipe_patch "$patch") - fi -fi -patch=${patch#$PWD/} - quilt_patches=${QUILT_PATCHES:-patches} dir=$(dirname "$quilt_patches/$patch") mkdir -p "$dir" |