[PATCH] pactree: Improve command line validation
Exit with non-zero status when the command line specifies more than one package or an unknown option. Fixes FS#64589. Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> --- If I may, I would like to use this occasion to suggest a feature: the ability to process multiple packages by pactree. I am sending a patch for that in reply to this email. src/pactree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pactree.c b/src/pactree.c index 5bc0032..9f074fe 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -346,7 +346,6 @@ static int parse_options(int argc, char *argv[]) version(); cleanup(0); case 'h': - case '?': usage(); cleanup(0); default: @@ -355,7 +354,8 @@ static int parse_options(int argc, char *argv[]) } } - if(!argv[optind]) { + if(!argv[optind] || argv[optind + 1]) { + usage(); return 1; } -- 2.25.0
Make it possible to invoke pactree for multiple packages at once. Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> --- This patch is designed to be applied on top of the one from the parent message. src/pactree.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/pactree.c b/src/pactree.c index 9f074fe..1775587 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -354,7 +354,7 @@ static int parse_options(int argc, char *argv[]) } } - if(!argv[optind] || argv[optind + 1]) { + if(!argv[optind]) { usage(); return 1; } @@ -430,12 +430,18 @@ static void print(const char *parentname, const char *pkgname, } } -static void print_start(const char *pkgname, const char *provname) +static void print_start(void) { if(graphviz) { printf("digraph G { START [color=red, style=filled];\n" - "node [style=filled, color=green];\n" - " \"START\" -> \"%s\";\n", pkgname); + "node [style=filled, color=green];\n"); + } +} + +static void print_target(const char *pkgname, const char *provname) +{ + if(graphviz) { + printf(" \"START\" -> \"%s\";\n", pkgname); } else { tdepth d = { NULL, @@ -526,7 +532,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, tdepth *depth, int r int main(int argc, char *argv[]) { - int freelist = 0, ret; + int freelist = 0, ret, target_ind; alpm_errno_t err; const char *target_name; alpm_pkg_t *pkg; @@ -560,23 +566,30 @@ int main(int argc, char *argv[]) freelist = 1; } - /* we only care about the first non option arg for walking */ - target_name = argv[optind]; - - pkg = alpm_find_dbs_satisfier(handle, dblist, target_name); - if(!pkg) { - fprintf(stderr, "error: package '%s' not found\n", target_name); - cleanup(1); - } + for(target_ind = optind; argv[target_ind]; ++target_ind) { + target_name = argv[target_ind]; + pkg = alpm_find_dbs_satisfier(handle, dblist, target_name); + if(!pkg) { + fprintf(stderr, "error: package '%s' not found\n", target_name); + cleanup(1); + } + } + print_start(); + - print_start(alpm_pkg_get_name(pkg), target_name); - - tdepth d = { - NULL, - NULL, - 1 - }; - walk_deps(dblist, pkg, &d, reverse); + for(target_ind = optind; argv[target_ind]; ++target_ind) { + target_name = argv[target_ind]; + pkg = alpm_find_dbs_satisfier(handle, dblist, target_name); + + print_target(alpm_pkg_get_name(pkg), target_name); + + tdepth d = { + NULL, + NULL, + 1 + }; + walk_deps(dblist, pkg, &d, reverse); + } print_end(); -- 2.25.0
The patch from the parent email:
From: jakseb.dev at gmail.com (Sebastian Jakubiak) Date: Fri, 6 Mar 2020 03:10:38 +0100 Subject: [PATCH] pactree: Implement handling of multiple packages In-Reply-To: <20200306021037.66811-1-jakseb.dev@gmail.com> References: <20200306021037.66811-1-jakseb.dev@gmail.com> Message-ID: <20200306021037.66811-2-jakseb.dev@gmail.com>
Make it possible to invoke pactree for multiple packages at once. [...]
is broken. I didn't take into into account situations when target packages (that is, the ones given as arguments to pactree) repeat or one target package is a dependency of another. Some specific examples: pactree tar tar xz pactree [-g] tar glibc I'm sorry.
On March 6, 2020 4:40:44 PM EST, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
The patch from the parent email:
From: jakseb.dev at gmail.com (Sebastian Jakubiak) Date: Fri, 6 Mar 2020 03:10:38 +0100 Subject: [PATCH] pactree: Implement handling of multiple packages In-Reply-To: <20200306021037.66811-1-jakseb.dev@gmail.com> References: <20200306021037.66811-1-jakseb.dev@gmail.com> Message-ID: <20200306021037.66811-2-jakseb.dev@gmail.com>
Make it possible to invoke pactree for multiple packages at once. [...]
is broken. I didn't take into into account situations when target packages (that is, the ones given as arguments to pactree) repeat or one target package is a dependency of another. Some specific examples:
pactree tar tar xz pactree [-g] tar glibc
I'm sorry.
Copy that. -- Best, Daniel <https://danielcapella.com>
On March 9, 2020 2:02:16 PM EDT, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
Copy that.
What do you mean?
I meant, understood, will not apply. Sorry, it's radio/military jargon. -- Best, Daniel <https://danielcapella.com>
On March 5, 2020 9:10:37 PM EST, Sebastian Jakubiak <jakseb.dev@gmail.com> wrote:
Exit with non-zero status when the command line specifies more than one package or an unknown option.
Fixes FS#64589.
Signed-off-by: Sebastian Jakubiak <jakseb.dev@gmail.com> ---
If I may, I would like to use this occasion to suggest a feature: the ability to process multiple packages by pactree. I am sending a patch for that in reply to this email.
src/pactree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/pactree.c b/src/pactree.c index 5bc0032..9f074fe 100644 --- a/src/pactree.c +++ b/src/pactree.c @@ -346,7 +346,6 @@ static int parse_options(int argc, char *argv[]) version(); cleanup(0); case 'h': - case '?': usage(); cleanup(0); default: @@ -355,7 +354,8 @@ static int parse_options(int argc, char *argv[]) } }
- if(!argv[optind]) { + if(!argv[optind] || argv[optind + 1]) { + usage(); return 1; }
Pushed, thank you. -- Best, Daniel <https://danielcapella.com>
participants (2)
-
Daniel M. Capella
-
Sebastian Jakubiak