commit:     dd9b8dfe0752fd9422782312ba85b4229ee54722
Author:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 29 02:32:25 2016 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Thu Dec 29 02:32:25 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=dd9b8dfe

qtbz2: improve cli a bit

Make -t/-x options autoselect the split action.
Allow -d to be specified more than once.
When given a bad -d path, diagnose it immediately.
When we can't autodetect actions, show a specific error message.

 qtbz2.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/qtbz2.c b/qtbz2.c
index 3c2e9f0..2161f99 100644
--- a/qtbz2.c
+++ b/qtbz2.c
@@ -252,13 +252,15 @@ int qtbz2_main(int argc, char **argv)
                COMMON_GETOPTS_CASES(qtbz2)
                case 'j': action = TBZ2_ACT_JOIN; break;
                case 's': action = TBZ2_ACT_SPLIT; break;
-               case 't': split_xpak = 0; break;
-               case 'x': split_tarbz2 = 0; break;
+               case 't': action = TBZ2_ACT_SPLIT; split_xpak = 0; break;
+               case 'x': action = TBZ2_ACT_SPLIT; split_tarbz2 = 0; break;
                case 'O': tbz2_stdout = 1; break;
                case 'd':
                        if (dir_fd != AT_FDCWD)
-                               err("Only use -d once");
+                               close(dir_fd);
                        dir_fd = open(optarg, O_RDONLY|O_CLOEXEC|O_PATH);
+                       if (unlikely(dir_fd == -1))
+                               errp("could not open dir: %s", optarg);
                        break;
                }
        }
@@ -279,7 +281,8 @@ int qtbz2_main(int argc, char **argv)
                else if (strstr(argv[optind], ".tbz2") != NULL)
                        action = TBZ2_ACT_SPLIT;
                else
-                       qtbz2_usage(EXIT_FAILURE);
+                       err("%s: need to use -j or -s, or file must end in 
.tar.bz2 or .tbz2 to autodetect",
+                               argv[optind]);
        }
 
        /* tbz2tool join .tar.bz2 .xpak .tbz2 */

Reply via email to