xbps-repo: 'sync' and 'pkg-list' target now accept a repository URI argument.

If set, only the matching repository will be used for the task.
This commit is contained in:
Juan RP 2012-06-01 15:02:06 +02:00
parent ba84f82e66
commit 981b13bd5a
8 changed files with 57 additions and 57 deletions

10
NEWS
View File

@ -1,5 +1,15 @@
xbps-0.16 (???):
* xbps-repo(8): 'sync' target now is able to sync just a single repository
by passing the repository URI as argument, i.e:
$ xbps-repo sync http://xbps.mirror.org/repo
* xbps-repo(8): 'pkg-list' target now expects the repository URI than
the index number, i.e:
$ xbps-repo pkg-list http://xbps.mirror.org/repo
* xbps-bin(8): -n flag (dry-run mode) now also prints the pkg architecture
as last component and if the transaction reason supports it.

View File

@ -268,7 +268,7 @@ main(int argc, char **argv)
if (argc < 2)
usage(true);
if (sync && ((rv = xbps_rpool_sync()) != 0))
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
goto out;
for (i = 1; i < argc; i++)
@ -282,7 +282,7 @@ main(int argc, char **argv)
if (argc < 2)
usage(true);
if (sync && ((rv = xbps_rpool_sync()) != 0))
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
goto out;
for (i = 1; i < argc; i++)
@ -351,7 +351,7 @@ main(int argc, char **argv)
if (argc != 1)
usage(true);
if (sync && ((rv = xbps_rpool_sync()) != 0))
if (sync && ((rv = xbps_rpool_sync(NULL)) != 0))
goto out;
rv = dist_upgrade(yes, dry_run, show_download_pkglist_url);

View File

@ -80,6 +80,11 @@ find_files_in_package(struct xbps_rpool_index *rpi, void *arg, bool *done)
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) {
free(plist);
if (errno == ENOENT) {
fprintf(stderr, "%s: index-files missing! "
"ignoring...\n", rpi->uri);
return 0;
}
return errno;
}
free(plist);

View File

@ -38,15 +38,12 @@ int
repo_pkg_list_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
{
struct list_pkgver_cb lpc;
uint16_t idx;
char *cp;
const char *repo = arg;
(void)done;
if (arg != NULL) {
idx = (uint16_t)strtoul(arg, &cp, 0);
if (rpi->index != idx)
if (repo && strcmp(rpi->uri, repo))
return 0;
}
lpc.check_state = false;
lpc.state = 0;
lpc.pkgver_len = find_longest_pkgver(rpi->repo);
@ -64,8 +61,8 @@ repo_list_uri_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
(void)arg;
(void)done;
printf("[%u] %s (%zu packages)\n",
rpi->index, rpi->uri, (size_t)prop_array_count(rpi->repo));
printf("%s (%zu packages)\n", rpi->uri,
(size_t)prop_array_count(rpi->repo));
return 0;
}

View File

@ -61,9 +61,9 @@ usage(bool fail)
" Generate a local repository in `directory'.\n"
" list\n"
" List registered repositories.\n"
" pkg-list [index]\n"
" Print packages in repository matching `index' number.\n"
" If `index' not specified, all registered repositories will be used.\n"
" pkg-list [repo]\n"
" Print packages in repository matching `repo' URI.\n"
" If `repo' not specified, all registered repositories will be used.\n"
" search <pattern> [patterns]\n"
" Search for packages in repositories matching the patterns.\n"
" show <pkgname|pkgpattern>\n"
@ -72,8 +72,9 @@ usage(bool fail)
" Print package's required dependencies for `pkgname' or `pkgpattern'.\n"
" show-files <pkgname|pkgpattern>\n"
" Print package's files list for `pkgname' or `pkgpattern'.\n"
" sync\n"
" Synchronize package index files for all registered repositories.\n\n"
" sync [repo]\n"
" Synchronize package index file for `repo'.\n"
" If `repo' not specified, all remote repositories will be used. \n\n"
"Refer to xbps-repo(8) for a more detailed description.\n");
exit(fail ? EXIT_FAILURE : EXIT_SUCCESS);
@ -266,14 +267,14 @@ main(int argc, char **argv)
rv = repo_genindex(argv[1]);
if (rv == 0)
rv = repo_genindex_files(argv[1]);
rv = repo_genindex_files(argv[1])
} else if (strcasecmp(argv[0], "sync") == 0) {
/* Syncs the pkg index for all registered remote repos */
if (argc != 1)
if (argc < 1 || argc > 2)
usage(true);
rv = xbps_rpool_sync();
rv = xbps_rpool_sync(argv[1]);
if (rv == ENOTSUP) {
xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n");

View File

@ -73,12 +73,11 @@ available in the index. If a newer package is available, the old package file
will be removed automatically.
.It Sy list
Lists all working repositories in repository pool.
.It Sy pkg-list Op index
Lists all currently registered packages in repository index as specified
in the
.Ar index
argument. If argument is not specified, any package contained in all repositories
will be shown. The argument expects a decimal number starting from 0,
.It Sy pkg-list Op repository
Lists all currently registered packages from all repositories, or just from
.Ar repository .
If argument is not specified, any package contained in all repositories
will be shown. The argument expects the repository URI.
matching the output of the
.Ar list
target.
@ -124,8 +123,9 @@ if a remote repository is the winner and binary package is not available in
it will fetch remotely and
.Em on the fly
the info from target repository.
.It Sy sync
Syncs the package index file for all registered remote repositories.
.It Sy sync Op repository
Syncs the package index file for all remote repositories or just for
.Ar repository .
The index file will be fetched if local and remote size/mtime do not match.
.Sh FILES
.Bl -tag -width /var/db/xbps/<repodir>/index-files.plist -compact

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.5"
#define XBPS_API_VERSION "20120601"
#define XBPS_API_VERSION "20120601-1"
#define XBPS_VERSION "0.16"
/**
@ -1492,22 +1492,19 @@ struct xbps_rpool_index {
* URI string associated with repository.
*/
const char *uri;
/**
* @var rpi_index
*
* Repository index in pool.
*/
uint16_t index;
};
/**
* Synchronizes the package index file for all remote repositories
* as specified in the configuration file, repositories.plist.
* as specified in the configuration file or if \a uri argument is
* set, just sync the index file for that repository.
*
* @param[in] uri Repository URI to match for sync (optional).
*
* @return 0 on success, ENOTSUP if no repositories were found in
* the configuration file.
*/
int xbps_rpool_sync(void);
int xbps_rpool_sync(const char *uri);
/**
* Iterates over the repository pool and executes the \a fn function

View File

@ -144,41 +144,33 @@ xbps_rpool_release(struct xbps_handle *xhp)
}
int
xbps_rpool_sync(void)
xbps_rpool_sync(const char *uri)
{
const struct xbps_handle *xhp = xbps_handle_get();
const char *repouri;
size_t i;
int rv;
int rv = 0;
if (xhp->cfg == NULL)
return ENOTSUP;
for (i = 0; i < cfg_size(xhp->cfg, "repositories"); i++) {
repouri = cfg_getnstr(xhp->cfg, "repositories", i);
/* If argument was set just process that repository */
if (uri && strcmp(repouri, uri))
continue;
/*
* Fetch repository plist index.
*/
rv = xbps_repository_sync_pkg_index(repouri, XBPS_PKGINDEX);
if (rv == -1) {
if (xbps_repository_sync_pkg_index(repouri, XBPS_PKGINDEX) == -1) {
rv = fetchLastErrCode != 0 ? fetchLastErrCode : errno;
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ?
strerror(errno) : xbps_fetch_error_string());
continue;
}
/*
* Fetch repository plist files index.
*/
rv = xbps_repository_sync_pkg_index(repouri,
XBPS_PKGINDEX_FILES);
if (rv == -1) {
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ?
strerror(errno) : xbps_fetch_error_string());
repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string());
continue;
}
}
return 0;
return rv;
}
int
@ -207,8 +199,6 @@ xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *a
d = prop_array_get(xhp->repo_pool, i);
prop_dictionary_get_cstring_nocopy(d, "uri", &rpi.uri);
rpi.repo = prop_dictionary_get(d, "index");
rpi.index = i;
rv = (*fn)(&rpi, arg, &done);
if (rv != 0 || done)
break;