quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH v2] inspect: Handle long options passed to tar


From: Jean Delvare
Subject: [Quilt-dev] [PATCH v2] inspect: Handle long options passed to tar
Date: Wed, 01 Oct 2014 11:37:40 +0200

The command line interface to tar is complex and sometimes confusing,
but we should still do our best to figure out where the file name is
on that command line.

Add support for the --file FILE and --file=FILE options. Other long
options must be explicitly skipped, as well as short options not
containing the letter "f".

With this we should be good to go in most real-world cases, but
there are still a few corner cases we may not handle properly. Let's
just hope we never hit them.

Reported by Petr Tesarik.
---
Changes since v1:
* Fix an endless loop when trying to parse options "x --file file".
* On "-xC software -f file", the previous code would extract "-f" as
  the file name, instead of "file".

 quilt/scripts/inspect.in |   45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

--- a/quilt/scripts/inspect.in
+++ b/quilt/scripts/inspect.in
@@ -250,13 +250,58 @@ cat <<-'EOF' > $tmpdir/bin/wrapper
        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()

-- 
Jean Delvare
SUSE L3 Support




reply via email to

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