quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH RFC] inspect: Split the patch/tar/unzip wrapper to a


From: Jean Delvare
Subject: [Quilt-dev] [PATCH RFC] inspect: Split the patch/tar/unzip wrapper to a separate script
Date: Sat, 25 Oct 2014 18:51:59 +0200

I couldn't find any reason why the patch/tar/unzip wrapper is
generated each time inspect is invoked. Make it a separate script in
its own right and let the patch, tar and unzip links point to it.

This makes this piece of code  easier to read, edit, trace and debug.
This also solves the case where the filesystem hosting the temporary
files is mounted with noexec.
---
Andreas, do you happen to know the reason why the wrapper script was
generated on-the-fly originally? I hope I'm not missing anything.

 Makefile.in                      |    6 
 quilt/scripts/inspect-wrapper.in |  265 ++++++++++++++++++++++++++++++++++++
 quilt/scripts/inspect.in         |  282 ---------------------------------------
 3 files changed, 271 insertions(+), 282 deletions(-)

--- a/Makefile.in
+++ b/Makefile.in
@@ -78,8 +78,8 @@ QUILT :=      $(QUILT_IN)
 SRC +=         $(QUILT_SRC:%=quilt/%)
 DIRT +=                $(QUILT_IN:%=quilt/%)
 
-SCRIPTS_IN :=  patchfns inspect dependency-graph edmail        \
-               remove-trailing-ws backup-files
+SCRIPTS_IN :=  patchfns inspect inspect-wrapper dependency-graph       \
+               edmail remove-trailing-ws backup-files
 
 SCRIPTS_SRC := $(SCRIPTS_IN:%=%.in)
 SCRIPTS :=     $(SCRIPTS_IN)
@@ -390,7 +390,7 @@ test/.depend : Makefile $(TESTS)
            -e 's:quilt/graph:quilt/graph quilt/scripts/dependency-graph:' \
            -e 's:quilt/mail:quilt/mail quilt/scripts/edmail:' \
            -e 's:quilt/refresh:quilt/refresh 
quilt/scripts/remove-trailing-ws:' \
-           -e 's:quilt/setup:quilt/setup quilt/scripts/inspect:' \
+           -e 's:quilt/setup:quilt/setup quilt/scripts/inspect 
quilt/scripts/inspect-wrapper:' \
          > $@
 
 ifneq ($(shell . $(QUILTRC) ;  echo $$QUILT_PATCHES_PREFIX),)
--- /dev/null
+++ b/quilt/scripts/inspect-wrapper.in
@@ -0,0 +1,265 @@
+#! @BASH@
+
+# find original data file by md5sum
+original_file()
+{
+       local file=$1 md5sum
+
+       set -- $(md5sum < $file)
+       md5sum=$1
+       while read md5sum_ file_
+       do
+               if [ "$md5sum" = "$md5sum_" ]
+               then
+                       echo ${file_#\*}
+                       return 0
+               fi
+       done < $tmpdir/md5sums
+
+       # Try harder
+       if ! [ -e $tmpdir/more-md5sums ]
+       then
+               ( cd $RPM_BUILD_DIR
+               find . -type f \
+               | sed -e 's:^.\/::' \
+               | xargs md5sum \
+               ) > $tmpdir/more-md5sums
+       fi
+
+       while read md5sum_ file_
+       do
+               if [ "$md5sum" = "$md5sum_" ]
+               then
+                       echo ${file_#\*}
+                       return 0
+               fi
+       done < $tmpdir/more-md5sums
+
+       return 1
+}
+
+# Extract a command line option with or without argument
+cmdline_option()
+{
+       local letter=$1 no_arg=$2
+       shift
+
+       while [ $# -ne 0 ]
+       do
+               if [ "${1:0:2}" = -$letter ]
+               then
+                       if [ -z "$no_arg" ]
+                       then
+                               [ "$1" = -$letter ] && set -- "$1$2"
+                       fi
+                       echo $1
+                       break
+               fi
+               shift
+       done
+}
+
+# Extract the -p option from the command line
+strip_option()
+{
+       set -- $(cmdline_option p "$@")
+       [ "$1" != -p1 ] && echo $1
+}
+
+# Extract the -R option from the command line
+reverse_option()
+{
+       set -- $(cmdline_option R no_arg "$@")
+       echo $1
+}
+
+patch_opt_d()
+{
+       local subdir=$(cmdline_option d "$@")
+       [ -z "$subdir" ] || echo "${subdir:2}"
+
+}
+
+patch_input_file()
+{
+       while [ $# -gt 0 ]
+       do
+               case "$1" in
+               -i|--input)
+                       if [ $# -ge 2 ]
+                       then
+                               echo "$2"
+                               return
+                       fi
+                       ;;
+               -i*)
+                       echo "${1#-i}"
+                       return
+                       ;;
+               --input=*)
+                       echo "${1#--input=}"
+                       return
+                       ;;
+               esac
+               shift
+       done
+       return 1
+}
+
+tar_input_file()
+{
+       case "$1" in
+       # Modern option format
+       -*)
+               while [ $# -gt 0 ]
+               do
+                       case "$1" in
+                       # Extract the file name (long option)
+                       --file)
+                               echo "$2"
+                               return
+                               ;;
+                       --file=*)
+                               echo "${1#--file=}"
+                               return
+                               ;;
+                       # Skip other long options
+                       --*)
+                               shift
+                               ;;
+                       # Extract the file name (short option)
+                       -*f)
+                               echo "$2"
+                               return
+                               ;;
+                       -f*)
+                               echo "${1#-f}"
+                               return
+                               ;;
+                       # Skip other short options and parameters
+                       *)
+                               shift
+                               ;;
+                       esac
+               done
+               ;;
+       # Legacy option format (must always come first)
+       *C*f*)
+               echo "$3"
+               return
+               ;;
+       *f*)
+               echo "$2"
+               return
+               ;;
+       ?*)
+               # Eat legacy options and try again
+               until [ $# -eq 0 -o "${1:0:1}" = "-" ]
+               do
+                       shift
+               done
+               tar_input_file "$@"
+               return
+               ;;
+       esac
+       return 1
+}
+
+unzip_input_file()
+{
+       while [ $# -gt 0 ]
+       do
+               case "$1" in
+               -*)
+                       shift
+                       ;;
+               *)
+                       echo "$1"
+                       return
+                       ;;
+               esac
+       done
+       return 1
+}
+
+tar_opt_C()
+{
+       case "$1" in
+       *C*f*)
+               echo "$2"
+               return ;;
+       esac
+}
+
+pwd_to_dir()
+{
+       local subdir=$1 dir
+
+       if [ -n "$subdir" ]
+       then
+               dir=$(cd "$subdir" && echo $PWD)
+       else
+               dir=$PWD
+       fi
+       dir=${dir/$RPM_BUILD_DIR}
+       dir=${dir##/}
+       dir=${dir// /\\ }
+
+       echo "$dir"
+}
+
+PATH=${PATH#*:}
+# If we are called too early, pass through without processing
+[ -n "$RPM_BUILD_DIR" ] || exec ${0##*/} "$@"
+
+tmpdir=${RPM_BUILD_DIR%/*}
+case "${0##*/}" in
+patch)
+       inputfile=$(patch_input_file "$@")
+       ;;
+tar)
+       inputfile=$(tar_input_file "$@")
+       # For tar, file - means read from stdin
+       [ "$inputfile" = "-" ] && inputfile=
+       ;;
+unzip)
+       inputfile=$(unzip_input_file "$@")
+       ;;
+esac
+if [ -z "$inputfile" ]
+then
+       # put data from stdin into tmpfile
+       cat > $tmpdir/data
+fi
+
+unpackfile=$(original_file ${inputfile:-$tmpdir/data})
+if [ -n "$unpackfile" ]
+then
+       case "${0##*/}" in
+       patch)
+               echo -n p >&4
+               subdir=$(patch_opt_d "$@")
+               dir=$(pwd_to_dir $subdir)
+               echo "${0##*/} ${dir:-.} $unpackfile" \
+                    $(strip_option "$@") $(reverse_option "$@") >&3
+               ;;
+       tar)
+               echo -n t >&4
+               subdir=$(tar_opt_C "$@")
+               dir=$(pwd_to_dir $subdir)
+               echo "${0##*/} ${dir:-.} $unpackfile" >&3
+               ;;
+       unzip)
+               echo -n Z >&4
+               dir=$(pwd_to_dir)
+               echo "${0##*/} ${dir:-.} $unpackfile" >&3
+               ;;
+       esac
+fi
+
+if [ -n "$inputfile" ]
+then
+       ${0##*/} "$@"
+else
+       ${0##*/} "$@" < $tmpdir/data
+fi
--- a/quilt/scripts/inspect.in
+++ b/quilt/scripts/inspect.in
@@ -142,285 +142,9 @@ done > $tmpdir/md5sums
 echo >&4
 shopt -u nullglob
 
-# wrapper script for patch, tar and unzip
-cat <<-'EOF' > $tmpdir/bin/wrapper
-       #! @BASH@
-
-       # find original data file by md5sum
-       original_file()
-       {
-               local file=$1 md5sum
-
-               set -- $(md5sum < $file)
-               md5sum=$1
-               while read md5sum_ file_
-               do
-                       if [ "$md5sum" = "$md5sum_" ]
-                       then
-                               echo ${file_#\*}
-                               return 0
-                       fi
-               done < $tmpdir/md5sums
-
-               # Try harder
-               if ! [ -e $tmpdir/more-md5sums ]
-               then
-                       ( cd $RPM_BUILD_DIR
-                       find . -type f \
-                       | sed -e 's:^.\/::' \
-                       | xargs md5sum \
-                       ) > $tmpdir/more-md5sums
-               fi
-
-               while read md5sum_ file_
-               do
-                       if [ "$md5sum" = "$md5sum_" ]
-                       then
-                               echo ${file_#\*}
-                               return 0
-                       fi
-               done < $tmpdir/more-md5sums
-
-               return 1
-       }
-
-       # Extract a command line option with or without argument
-       cmdline_option()
-       {
-               local letter=$1 no_arg=$2
-               shift
-
-               while [ $# -ne 0 ]
-               do
-                       if [ "${1:0:2}" = -$letter ]
-                       then
-                               if [ -z "$no_arg" ]
-                               then
-                                       [ "$1" = -$letter ] && set -- "$1$2"
-                               fi
-                               echo $1
-                               break
-                       fi
-                       shift
-               done
-       }
-
-       # Extract the -p option from the command line
-       strip_option()
-       {
-               set -- $(cmdline_option p "$@")
-               [ "$1" != -p1 ] && echo $1
-       }
-
-       # Extract the -R option from the command line
-       reverse_option()
-       {
-               set -- $(cmdline_option R no_arg "$@")
-               echo $1
-       }
-
-       patch_opt_d()
-       {
-               local subdir=$(cmdline_option d "$@")
-               [ -z "$subdir" ] || echo "${subdir:2}"
-
-       }
-
-       patch_input_file()
-       {
-               while [ $# -gt 0 ]; do
-                       case "$1" in
-                       -i|--input)
-                               if [ $# -ge 2 ]
-                               then
-                                       echo "$2"
-                                       return
-                               fi
-                               ;;
-                       -i*)
-                               echo "${1#-i}"
-                               return
-                               ;;
-                       --input=*)
-                               echo "${1#--input=}"
-                               return
-                               ;;
-                       esac
-                       shift
-               done
-               return 1
-       }
-
-       tar_input_file()
-       {
-               case "$1" in
-               # Modern option format
-               -*)
-                       while [ $# -gt 0 ]; do
-                               case "$1" in
-                               # Extract the file name (long option)
-                               --file)
-                                       echo "$2"
-                                       return
-                                       ;;
-                               --file=*)
-                                       echo "${1#--file=}"
-                                       return
-                                       ;;
-                               # Skip other long options
-                               --*)
-                                       shift
-                                       ;;
-                               # Extract the file name (short option)
-                               -*f)
-                                       echo "$2"
-                                       return
-                                       ;;
-                               -f*)
-                                       echo "${1#-f}"
-                                       return
-                                       ;;
-                               # Skip other short options and parameters
-                               *)
-                                       shift
-                                       ;;
-                               esac
-                       done
-                       ;;
-               # Legacy option format (must always come first)
-               *C*f*)
-                       echo "$3"
-                       return
-                       ;;
-               *f*)
-                       echo "$2"
-                       return
-                       ;;
-               ?*)
-                       # Eat legacy options and try again
-                       until [ $# -eq 0 -o "${1:0:1}" = "-" ]; do
-                               shift
-                       done
-                       tar_input_file "$@"
-                       return
-                       ;;
-               esac
-               return 1
-       }
-
-       unzip_input_file()
-       {
-               while [ $# -gt 0 ]; do
-                       case "$1" in
-                       -*)
-                               shift
-                               ;;
-                       *)
-                               echo "$1"
-                               return
-                               ;;
-                       esac
-               done
-               return 1
-       }
-
-       tar_opt_C()
-       {
-               case "$1" in
-               *C*f*)
-                       echo "$2"
-                       return ;;
-               esac
-       }
-
-       pwd_to_dir()
-       {
-               local subdir=$1 dir
-
-               if [ -n "$subdir" ]
-               then
-                       dir=$(cd "$subdir" && echo $PWD)
-               else
-                       dir=$PWD
-               fi
-               dir=${dir/$RPM_BUILD_DIR}
-               dir=${dir##/}
-               dir=${dir// /\\ }
-
-               echo "$dir"
-       }
-
-       PATH=${PATH#*:}
-       # If we are called too early, pass through without processing
-       [ -n "$RPM_BUILD_DIR" ] || exec ${0##*/} "$@"
-
-       tmpdir=${RPM_BUILD_DIR%/*}
-       case "${0##*/}" in
-       patch)
-               inputfile=$(patch_input_file "$@")
-               ;;
-       tar)
-               inputfile=$(tar_input_file "$@")
-               # For tar, file - means read from stdin
-               [ "$inputfile" = "-" ] && inputfile=
-               ;;
-       unzip)
-               inputfile=$(unzip_input_file "$@")
-               ;;
-       esac
-       if [ -z "$inputfile" ]
-       then
-               # put data from stdin into tmpfile
-               cat > $tmpdir/data
-       fi
-
-       unpackfile=$(original_file ${inputfile:-$tmpdir/data})
-       if [ -n "$unpackfile" ]
-       then
-               case "${0##*/}" in
-               patch)
-                       echo -n p >&4
-                       subdir=$(patch_opt_d "$@")
-                       dir=$(pwd_to_dir $subdir)
-                       echo "${0##*/} ${dir:-.} $unpackfile" \
-                            $(strip_option "$@") $(reverse_option "$@") >&3
-                       ;;
-               tar)
-                       echo -n t >&4
-                       subdir=$(tar_opt_C "$@")
-                       dir=$(pwd_to_dir $subdir)
-                       echo "${0##*/} ${dir:-.} $unpackfile" >&3
-                       ;;
-               unzip)
-                       echo -n Z >&4
-                       dir=$(pwd_to_dir)
-                       echo "${0##*/} ${dir:-.} $unpackfile" >&3
-                       ;;
-               esac
-       fi
-
-       if [ -n "$inputfile" ]
-       then
-               ${0##*/} "$@"
-       else
-               ${0##*/} "$@" < $tmpdir/data
-       fi
-EOF
-
-chmod 755 $tmpdir/bin/wrapper
-# If $TMPDIR is mounted with noexec, rpmbuild won't be able to execute
-# our wrapper script
-if [ ! -x $tmpdir/bin/wrapper ]
-then
-       printf "Cannot execute %s; filesystem mounted with noexec?\n" \
-              $tmpdir/bin/wrapper >&2
-       printf "Setting %s in ~/.quiltrc may help\n" "VARTMPDIR" >&2
-       exit 1
-fi
-
-ln -s wrapper $tmpdir/bin/patch
-ln -s wrapper $tmpdir/bin/tar
-ln -s wrapper $tmpdir/bin/unzip
+ln -s $QUILT_DIR/scripts/inspect-wrapper $tmpdir/bin/patch
+ln -s $QUILT_DIR/scripts/inspect-wrapper $tmpdir/bin/tar
+ln -s $QUILT_DIR/scripts/inspect-wrapper $tmpdir/bin/unzip
 
 # let rpm do all the dirty specfile stuff ...
 echo -n "### rpmbuild: " >&4


-- 
Jean Delvare
SUSE L3 Support



reply via email to

[Prev in Thread] Current Thread [Next in Thread]