-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bin/xbps-repodb: add new tool to manage multiple repositories at once #286
Open
Duncaen
wants to merge
3
commits into
void-linux:master
Choose a base branch
from
Duncaen:xbps-repodb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
TOPDIR = ../.. | ||
-include $(TOPDIR)/config.mk | ||
|
||
BIN = xbps-repodb | ||
OBJS = main.o purge.o | ||
|
||
include $(TOPDIR)/mk/prog.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*- | ||
* Copyright (c) 2020 Duncan Overbruck <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef _XBPS_REPODB_DEFS_H_ | ||
#define _XBPS_REPODB_DEFS_H_ | ||
|
||
/* Form purge.c */ | ||
int purge_repos(struct xbps_handle *, int, char *[], bool); | ||
|
||
#endif /* !_XBPS_REPODB_DEFS_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/*- | ||
* Copyright (c) 2020 Duncan Overbruck <[email protected]> | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <strings.h> | ||
#include <errno.h> | ||
#include <unistd.h> | ||
#include <getopt.h> | ||
|
||
#include <xbps.h> | ||
|
||
#include "defs.h" | ||
|
||
|
||
static void __attribute__((noreturn)) | ||
usage(void) | ||
{ | ||
fprintf(stdout, | ||
"Usage: xbps-repodb [OPTIONS] MODE <repository>...\n\n" | ||
"OPTIONS:\n" | ||
" -d, --debug Enable debug messages to stderr\n" | ||
" -n, --dry-run Dry-run mode\n" | ||
" -v, --verbose Enable verbose output\n" | ||
" -V, --version Prints the xbps release version\n" | ||
"MODE:\n" | ||
" -p, --purge Remove obsolete binary packages from repositories\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
int c = 0, rv = 0; | ||
struct xbps_handle xh; | ||
const struct option longopts[] = { | ||
{ "debug", no_argument, NULL, 'd' }, | ||
{ "dry-run", no_argument, NULL, 'n' }, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing "purge" long option here |
||
{ "verbose", no_argument, NULL, 'v' }, | ||
{ "version", no_argument, NULL, 'V' }, | ||
{ NULL, 0, NULL, 0 } | ||
}; | ||
bool dry = false; | ||
enum { | ||
MODE_NIL, | ||
MODE_PURGE, | ||
} mode = MODE_NIL; | ||
|
||
memset(&xh, 0, sizeof xh); | ||
|
||
while ((c = getopt_long(argc, argv, "dhnpVv", longopts, NULL)) != -1) { | ||
switch (c) { | ||
case 'd': | ||
xh.flags |= XBPS_FLAG_DEBUG; | ||
break; | ||
case 'p': | ||
mode = MODE_PURGE; | ||
break; | ||
case 'n': | ||
dry = true; | ||
break; | ||
case 'v': | ||
xh.flags |= XBPS_FLAG_VERBOSE; | ||
break; | ||
case 'V': | ||
printf("%s\n", XBPS_RELVER); | ||
exit(EXIT_SUCCESS); | ||
case '?': | ||
case 'h': | ||
default: | ||
usage(); | ||
} | ||
} | ||
argc -= optind; | ||
argv += optind; | ||
|
||
if (argc == 0 || mode == MODE_NIL) | ||
usage(); | ||
|
||
/* | ||
* Initialize libxbps. | ||
*/ | ||
xh.flags |= XBPS_FLAG_IGNORE_CONF_REPOS; | ||
if ((rv = xbps_init(&xh)) != 0) { | ||
xbps_error_printf("failed to initialize libxbps: %s\n", | ||
strerror(rv)); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
switch (mode) { | ||
case MODE_PURGE: | ||
rv = purge_repos(&xh, argc, argv, dry); | ||
case MODE_NIL: | ||
break; | ||
} | ||
|
||
xbps_end(&xh); | ||
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't you do
struct xbps_handle xh = { };
instead of a memset below? It should initialize the whole struct to zero and is easier to follow.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this isn't ISO C.
struct xbps_handle xh = { 0 };
should work too.