xbps-{install,query}: added -M --memory-sync option.

This explicitly enables the in memory fetch/store of remote repository
data archives mode, ignoring existing on-disk repodata archives.

This changes the previous behaviour of falling back to this mode if no
on-disk repodata archives were found.

Thanks to @Gottox and @dominikh for comments.
This commit is contained in:
Juan RP 2014-11-27 10:42:05 +01:00
parent 8e2225eb4e
commit fe9a795995
7 changed files with 45 additions and 16 deletions

12
NEWS
View File

@ -1,12 +1,10 @@
xbps-0.42 (???): xbps-0.42 (???):
* Added support to fetch repository data remotely and on demand. That means * xbps-{install,query}: added new option (-M, --memory-sync) to fetch and
that synchronizing the repository data with `xbps-install -S` is now store remote repository data in memory. That means that synchronizing
completely optional. If local repodata is found on disk, it's the preferred the repository archives with `xbps-install -S` is now completely optional.
operation mode. This also means that `xbps-query(8)` may be used by any This also means that `xbps-query(8)` may be used by any user without the
user without the need to be the `superuser` to synchronize the repository need to be the `superuser` to synchronize the repository archives.
archives. Of course this new operation mode requires a proper network
connection.
* xbps-{install,query}: added new option (-i, --ignore-conf-repos) to ignore * xbps-{install,query}: added new option (-i, --ignore-conf-repos) to ignore
repositories defined in configuration files (xbps.d). Only repos specified repositories defined in configuration files (xbps.d). Only repos specified

View File

@ -52,6 +52,8 @@ usage(bool fail)
" overwritten.\n" " overwritten.\n"
" -h --help Print help usage\n" " -h --help Print help usage\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d\n" " -i --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -M --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n"
" -n --dry-run Dry-run mode\n" " -n --dry-run Dry-run mode\n"
" -R,--repository=<url> Add repository to the top of the list.\n" " -R,--repository=<url> Add repository to the top of the list.\n"
" This option can be specified multiple times.\n" " This option can be specified multiple times.\n"
@ -91,7 +93,7 @@ repo_import_key_cb(struct xbps_repo *repo, void *arg _unused, bool *done _unused
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *shortopts = "AC:c:dfhinR:r:SuVvy"; const char *shortopts = "AC:c:dfhiMnR:r:SuVvy";
const struct option longopts[] = { const struct option longopts[] = {
{ "automatic", no_argument, NULL, 'A' }, { "automatic", no_argument, NULL, 'A' },
{ "config", required_argument, NULL, 'C' }, { "config", required_argument, NULL, 'C' },
@ -100,6 +102,7 @@ main(int argc, char **argv)
{ "force", no_argument, NULL, 'f' }, { "force", no_argument, NULL, 'f' },
{ "help", no_argument, NULL, 'h' }, { "help", no_argument, NULL, 'h' },
{ "ignore-conf-repos", no_argument, NULL, 'i' }, { "ignore-conf-repos", no_argument, NULL, 'i' },
{ "memory-sync", no_argument, NULL, 'M' },
{ "dry-run", no_argument, NULL, 'n' }, { "dry-run", no_argument, NULL, 'n' },
{ "repository", required_argument, NULL, 'R' }, { "repository", required_argument, NULL, 'R' },
{ "rootdir", required_argument, NULL, 'r' }, { "rootdir", required_argument, NULL, 'r' },
@ -149,6 +152,9 @@ main(int argc, char **argv)
case 'i': case 'i':
flags |= XBPS_FLAG_IGNORE_CONF_REPOS; flags |= XBPS_FLAG_IGNORE_CONF_REPOS;
break; break;
case 'M':
flags |= XBPS_FLAG_REPOS_MEMSYNC;
break;
case 'n': case 'n':
drun = true; drun = true;
break; break;

View File

@ -1,4 +1,4 @@
.Dd November 5, 2014 .Dd November 27, 2014
.Dt XBPS-INSTALL 8 .Dt XBPS-INSTALL 8
.Sh NAME .Sh NAME
.Nm xbps-install .Nm xbps-install
@ -86,6 +86,9 @@ Ignore repositories defined in configuration files.
Only repositories specified in the command line via Only repositories specified in the command line via
.Ar --repository .Ar --repository
will be used. will be used.
.It Fl M, Fl -memory-sync
For remote repositories, the data is fetched and stored in memory for the current
operation. This ignores the existing on-disk repository archives in rootdir.
.It Fl n, Fl -dry-run .It Fl n, Fl -dry-run
Dry-run mode. Show what actions would be done but don't do anything. Dry-run mode. Show what actions would be done but don't do anything.
.It Fl R, Fl -repository=uri .It Fl R, Fl -repository=uri

View File

@ -43,6 +43,8 @@ usage(bool fail)
" -d --debug Debug mode shown to stderr\n" " -d --debug Debug mode shown to stderr\n"
" -h --help Print help usage\n" " -h --help Print help usage\n"
" -i --ignore-conf-repos Ignore repositories defined in xbps.d\n" " -i --ignore-conf-repos Ignore repositories defined in xbps.d\n"
" -M --memory-sync Remote repository data is fetched and stored\n"
" in memory, ignoring on-disk repodata archives.\n"
" -p --property PROP[,...] Show properties for PKGNAME\n" " -p --property PROP[,...] Show properties for PKGNAME\n"
" -R --repository Enable repository mode. This mode explicitly\n" " -R --repository Enable repository mode. This mode explicitly\n"
" looks for packages in repositories.\n" " looks for packages in repositories.\n"
@ -74,7 +76,7 @@ usage(bool fail)
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
const char *shortopts = "C:c:df:hHiLlmOo:p:Rr:s:S:VvX:x:"; const char *shortopts = "C:c:df:hHiLlMmOo:p:Rr:s:S:VvX:x:";
const struct option longopts[] = { const struct option longopts[] = {
{ "config", required_argument, NULL, 'C' }, { "config", required_argument, NULL, 'C' },
{ "cachedir", required_argument, NULL, 'c' }, { "cachedir", required_argument, NULL, 'c' },
@ -84,6 +86,7 @@ main(int argc, char **argv)
{ "list-repos", no_argument, NULL, 'L' }, { "list-repos", no_argument, NULL, 'L' },
{ "list-pkgs", no_argument, NULL, 'l' }, { "list-pkgs", no_argument, NULL, 'l' },
{ "list-hold-pkgs", no_argument, NULL, 'H' }, { "list-hold-pkgs", no_argument, NULL, 'H' },
{ "memory-sync", no_argument, NULL, 'M' },
{ "list-manual-pkgs", no_argument, NULL, 'm' }, { "list-manual-pkgs", no_argument, NULL, 'm' },
{ "list-orphans", no_argument, NULL, 'O' }, { "list-orphans", no_argument, NULL, 'O' },
{ "ownedby", required_argument, NULL, 'o' }, { "ownedby", required_argument, NULL, 'o' },
@ -148,6 +151,9 @@ main(int argc, char **argv)
case 'l': case 'l':
list_pkgs = opmode = true; list_pkgs = opmode = true;
break; break;
case 'M':
flags |= XBPS_FLAG_REPOS_MEMSYNC;
break;
case 'm': case 'm':
list_manual = opmode = true; list_manual = opmode = true;
break; break;

View File

@ -1,4 +1,4 @@
.Dd November 21, 2014 .Dd November 27, 2014
.Dt XBPS-QUERY 8 .Dt XBPS-QUERY 8
.Sh NAME .Sh NAME
.Nm xbps-query .Nm xbps-query
@ -70,6 +70,9 @@ Ignore repositories defined in configuration files.
Only repositories specified in the command line via Only repositories specified in the command line via
.Ar --repository .Ar --repository
will be used. will be used.
.It Fl M, Fl -memory-sync
For remote repositories, the data is fetched and stored in memory for the current
operation. This ignores the existing on-disk repository archives in rootdir.
.It Fl p, Fl -property Ar PROP[,...] .It Fl p, Fl -property Ar PROP[,...]
Only match this package property. Only match this package property.
Multiple properties can be specified by delimiting them with commas. Multiple properties can be specified by delimiting them with commas.

View File

@ -48,7 +48,7 @@
* *
* This header documents the full API for the XBPS Library. * This header documents the full API for the XBPS Library.
*/ */
#define XBPS_API_VERSION "20141126" #define XBPS_API_VERSION "20141127"
#ifndef XBPS_VERSION #ifndef XBPS_VERSION
#define XBPS_VERSION "UNSET" #define XBPS_VERSION "UNSET"
@ -183,6 +183,13 @@
*/ */
#define XBPS_FLAG_IGNORE_CONF_REPOS 0x00000200 #define XBPS_FLAG_IGNORE_CONF_REPOS 0x00000200
/**
* @def XBPS_FLAG_REPOS_MEMSYNC
* Fetch and store repodata in memory, ignoring on-disk metadata.
* Must be set through the xbps_handle::flags member.
*/
#define XBPS_FLAG_REPOS_MEMSYNC 0x00000400
/** /**
* @def XBPS_FETCH_CACHECONN * @def XBPS_FETCH_CACHECONN
* Default (global) limit of cached connections used in libfetch. * Default (global) limit of cached connections used in libfetch.

View File

@ -206,7 +206,16 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url, bool lock)
repofile = xbps_repo_path(xhp, url); repofile = xbps_repo_path(xhp, url);
} }
/* /*
* Open or create the repository archive. * In memory repo sync.
*/
if (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC) {
if (repo_open_remote(repo))
return repo;
goto out;
}
/*
* Open the repository archive.
*/ */
if (lock) if (lock)
repo->fd = open(repofile, O_RDWR); repo->fd = open(repofile, O_RDWR);
@ -215,9 +224,6 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url, bool lock)
if (repo->fd == -1) { if (repo->fd == -1) {
int rv = errno; int rv = errno;
if (repo_open_remote(repo))
return repo;
xbps_dbg_printf(xhp, "[repo] `%s' open repodata %s\n", xbps_dbg_printf(xhp, "[repo] `%s' open repodata %s\n",
repofile, strerror(rv)); repofile, strerror(rv));
goto out; goto out;