Skip to content

Commit

Permalink
bin/xbps-rindex: Count set modes rather than enumerate them
Browse files Browse the repository at this point in the history
  • Loading branch information
Chocimier committed Apr 2, 2020
1 parent a3a103a commit dda81f8
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions bin/xbps-rindex/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ main(int argc, char **argv)
struct xbps_handle xh;
const char *compression = NULL;
const char *privkey = NULL, *signedby = NULL;
int rv, c, flags = 0;
int rv, c, flags = 0, modes_count = 0;
bool add_mode, clean_mode, rm_mode, sign_mode, sign_pkg_mode, force,
hashcheck;

Expand All @@ -99,9 +99,11 @@ main(int argc, char **argv)
break;
case 'a':
add_mode = true;
modes_count++;
break;
case 'c':
clean_mode = true;
modes_count++;
break;
case 'd':
flags |= XBPS_FLAG_DEBUG;
Expand All @@ -114,15 +116,18 @@ main(int argc, char **argv)
/* NOTREACHED */
case 'r':
rm_mode = true;
modes_count++;
break;
case 's':
sign_mode = true;
modes_count++;
break;
case 'C':
hashcheck = true;
break;
case 'S':
sign_pkg_mode = true;
modes_count++;
break;
case 'v':
flags |= XBPS_FLAG_VERBOSE;
Expand All @@ -132,14 +137,9 @@ main(int argc, char **argv)
exit(EXIT_SUCCESS);
}
}
if ((argc == optind) ||
(!add_mode && !clean_mode && !rm_mode && !sign_mode && !sign_pkg_mode)) {
if ((argc == optind) || (modes_count == 0)) {
usage(true);
} else if ((add_mode && (clean_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
(clean_mode && (add_mode || rm_mode || sign_mode || sign_pkg_mode)) ||
(rm_mode && (add_mode || clean_mode || sign_mode || sign_pkg_mode)) ||
(sign_mode && (add_mode || clean_mode || rm_mode || sign_pkg_mode)) ||
(sign_pkg_mode && (add_mode || clean_mode || rm_mode || sign_mode))) {
} else if (modes_count > 1) {
fprintf(stderr, "Only one mode can be specified: add, clean, "
"remove-obsoletes, sign or sign-pkg.\n");
exit(EXIT_FAILURE);
Expand Down

0 comments on commit dda81f8

Please sign in to comment.