summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobbie Harwood <rharwood@redhat.com>2019-04-24 15:28:33 -0400
committerPanu Matilainen <pmatilai@redhat.com>2020-03-26 11:57:58 +0200
commit35be021dbce5a8c6c05198fbb97ade2ad47abcf3 (patch)
tree01c768d8c5e89d3544da495fc43ebda317e55b04
parent1a5d2d5a6fd32000715971c6935fc1559d900dc1 (diff)
downloadrpm-35be021dbce5a8c6c05198fbb97ade2ad47abcf3.tar.gz
Fix rpm2archive behavior with multiple arguments
If multiple arguments are passed to rpm2archive, convert them all to tgz. (Previous behavior was to convert only the first one and silently ignore the rest.) Signed-off-by: Robbie Harwood <rharwood@redhat.com> Co-authored-by: Florian Festi <ffesti@redhat.com> (cherry picked from commit c73b0f34e32c299c87b7163352808d1071a05d2b)
-rw-r--r--rpm2archive.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/rpm2archive.c b/rpm2archive.c
index 3b1a56559..d0d1e6649 100644
--- a/rpm2archive.c
+++ b/rpm2archive.c
@@ -187,22 +187,19 @@ static int process_package(rpmts ts, char * filename)
int main(int argc, char *argv[])
{
- int rc;
-
+ int rc, i;
+
xsetprogname(argv[0]); /* Portability call -- see system.h */
rpmReadConfigFiles(NULL, NULL);
- char * filename;
- if (argc == 1)
- filename = "-";
- else {
- if (rstreq(argv[1], "-h") || rstreq(argv[1], "--help")) {
- fprintf(stderr, "Usage: rpm2archive file.rpm\n");
- exit(EXIT_FAILURE);
- } else {
- filename = argv[1];
- }
+
+ if (argc > 1 && (rstreq(argv[1], "-h") || rstreq(argv[1], "--help"))) {
+ fprintf(stderr, "Usage: %s [file.rpm ...]\n", argv[0]);
+ exit(EXIT_FAILURE);
}
+ if (argc == 1)
+ argv[argc++] = "-"; /* abuse NULL pointer at the end of argv */
+
rpmts ts = rpmtsCreate();
rpmVSFlags vsflags = 0;
@@ -212,9 +209,13 @@ int main(int argc, char *argv[])
vsflags |= RPMVSF_NOHDRCHK;
(void) rpmtsSetVSFlags(ts, vsflags);
- rc = process_package(ts, filename);
+ for (i = 1; i < argc; i++) {
- ts = rpmtsFree(ts);
+ rc = process_package(ts, argv[i]);
+ if (rc != 0)
+ return rc;
+ }
+ (void) rpmtsFree(ts);
return rc;
}