From: Jean Delvare Subject: inspect: Handle long options passed to tar Upstream: Committed (1e9f433f693b4ee09ebf3267222b11694448e81f) 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 @@ -258,13 +258,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()