xbps-bin: new dry-run mode (-n) for (auto)update, (auto)remove and install targets.

This commit is contained in:
Juan RP 2012-02-03 14:53:28 +01:00
parent 7fd4b16156
commit 3afa3ba93b
5 changed files with 67 additions and 17 deletions

11
NEWS
View File

@ -1,5 +1,16 @@
xbps-0.12.0 (???): xbps-0.12.0 (???):
* xbps-bin: new dry-run mode (-n) to show the actions that would
be executed in a transaction. This mode takes effect in the
autoremove, autoupdate, install, remove and update targets. Example:
$ xbps-bin -n install kernel-snapshot
kernel-snapshot install 3.3.0rc2 /mnt/xbps_builder/host/binpkgs/x86_64
$
The format is "%s %s %s[ %s]\n" for `pkgname', `action', `version'
and `repository' (optional).
* xbps-bin: the install target will now install the best package * xbps-bin: the install target will now install the best package
version available in repository pool if just package name has version available in repository pool if just package name has
been specified, otherwise the first repository matching the been specified, otherwise the first repository matching the

View File

@ -48,9 +48,9 @@ struct list_pkgver_cb {
int install_new_pkg(const char *, bool); int install_new_pkg(const char *, bool);
int update_pkg(const char *); int update_pkg(const char *);
int remove_pkg(const char *, bool); int remove_pkg(const char *, bool);
int autoupdate_pkgs(bool, bool); int autoupdate_pkgs(bool, bool, bool);
int autoremove_pkgs(bool); int autoremove_pkgs(bool, bool);
int exec_transaction(bool, bool); int exec_transaction(bool, bool, bool);
/* from remove.c */ /* from remove.c */
int remove_installed_pkgs(int, char **, bool, bool, bool, bool); int remove_installed_pkgs(int, char **, bool, bool, bool, bool);

View File

@ -65,14 +65,14 @@ main(int argc, char **argv)
const char *rootdir, *cachedir, *conffile, *option; const char *rootdir, *cachedir, *conffile, *option;
int i, c, flags, rv; int i, c, flags, rv;
bool yes, reqby_force, force_rm_with_deps, recursive_rm; bool yes, reqby_force, force_rm_with_deps, recursive_rm;
bool reinstall, show_download_pkglist_url; bool reinstall, show_download_pkglist_url, dry_run;
rootdir = cachedir = conffile = option = NULL; rootdir = cachedir = conffile = option = NULL;
flags = rv = 0; flags = rv = 0;
reqby_force = yes = force_rm_with_deps = false; reqby_force = yes = dry_run = force_rm_with_deps = false;
recursive_rm = reinstall = show_download_pkglist_url = false; recursive_rm = reinstall = show_download_pkglist_url = false;
while ((c = getopt(argc, argv, "AC:c:dDFfMo:Rr:Vvy")) != -1) { while ((c = getopt(argc, argv, "AC:c:dDFfMno:Rr:Vvy")) != -1) {
switch (c) { switch (c) {
case 'A': case 'A':
flags |= XBPS_FLAG_INSTALL_AUTO; flags |= XBPS_FLAG_INSTALL_AUTO;
@ -100,6 +100,9 @@ main(int argc, char **argv)
case 'M': case 'M':
flags |= XBPS_FLAG_INSTALL_MANUAL; flags |= XBPS_FLAG_INSTALL_MANUAL;
break; break;
case 'n':
dry_run = true;
break;
case 'o': case 'o':
option = optarg; option = optarg;
break; break;
@ -214,7 +217,7 @@ main(int argc, char **argv)
if ((rv = install_new_pkg(argv[i], reinstall)) != 0) if ((rv = install_new_pkg(argv[i], reinstall)) != 0)
goto out; goto out;
rv = exec_transaction(yes, show_download_pkglist_url); rv = exec_transaction(yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "update") == 0) { } else if (strcasecmp(argv[0], "update") == 0) {
/* Update an installed package. */ /* Update an installed package. */
@ -225,7 +228,7 @@ main(int argc, char **argv)
if ((rv = update_pkg(argv[i])) != 0) if ((rv = update_pkg(argv[i])) != 0)
goto out; goto out;
rv = exec_transaction(yes, show_download_pkglist_url); rv = exec_transaction(yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "remove") == 0) { } else if (strcasecmp(argv[0], "remove") == 0) {
/* Removes a package. */ /* Removes a package. */
@ -245,7 +248,7 @@ main(int argc, char **argv)
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
rv = exec_transaction(yes, false); rv = exec_transaction(yes, dry_run, false);
} else if (strcasecmp(argv[0], "show") == 0) { } else if (strcasecmp(argv[0], "show") == 0) {
/* Shows info about an installed binary package. */ /* Shows info about an installed binary package. */
@ -286,7 +289,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = autoupdate_pkgs(yes, show_download_pkglist_url); rv = autoupdate_pkgs(yes, dry_run, show_download_pkglist_url);
} else if (strcasecmp(argv[0], "show-orphans") == 0) { } else if (strcasecmp(argv[0], "show-orphans") == 0) {
/* /*
@ -307,7 +310,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = autoremove_pkgs(yes); rv = autoremove_pkgs(yes, dry_run);
} else if (strcasecmp(argv[0], "reconfigure") == 0) { } else if (strcasecmp(argv[0], "reconfigure") == 0) {
/* /*

View File

@ -63,6 +63,24 @@ show_missing_deps(prop_array_t a)
} }
} }
static void
show_actions(prop_object_iterator_t iter)
{
prop_object_t obj;
const char *repoloc, *trans, *pkgname, *version;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "transaction", &trans);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
printf("%s %s %s", pkgname, trans, version);
if (prop_dictionary_get_cstring_nocopy(obj,
"repository", &repoloc))
printf(" %s", repoloc);
printf("\n");
}
}
static int static int
show_binpkgs_url(prop_object_iterator_t iter) show_binpkgs_url(prop_object_iterator_t iter)
{ {
@ -193,7 +211,7 @@ show_transaction_sizes(struct transaction *trans)
} }
int int
autoupdate_pkgs(bool yes, bool show_download_pkglist_url) autoupdate_pkgs(bool yes, bool dry_run, bool show_download_pkglist_url)
{ {
int rv = 0; int rv = 0;
@ -218,11 +236,11 @@ autoupdate_pkgs(bool yes, bool show_download_pkglist_url)
return -1; return -1;
} }
} }
return exec_transaction(yes, show_download_pkglist_url); return exec_transaction(yes, dry_run, show_download_pkglist_url);
} }
int int
autoremove_pkgs(bool yes) autoremove_pkgs(bool yes, bool dry_run)
{ {
int rv; int rv;
@ -236,7 +254,7 @@ autoremove_pkgs(bool yes)
return rv; return rv;
} }
} }
return exec_transaction(yes, false); return exec_transaction(yes, dry_run, false);
} }
int int
@ -325,7 +343,7 @@ remove_pkg(const char *pkgname, bool recursive)
} }
int int
exec_transaction(bool yes, bool show_download_urls) exec_transaction(bool yes, bool dry_run, bool show_download_urls)
{ {
prop_array_t mdeps; prop_array_t mdeps;
struct transaction *trans; struct transaction *trans;
@ -359,6 +377,13 @@ exec_transaction(bool yes, bool show_download_urls)
strerror(errno)); strerror(errno));
goto out; goto out;
} }
/*
* dry-run mode, show what would be done but don't run anything.
*/
if (dry_run) {
show_actions(trans->iter);
goto out;
}
/* /*
* Only show URLs to download binary packages. * Only show URLs to download binary packages.
*/ */

View File

@ -1,4 +1,4 @@
.Dd January 19, 2012 .Dd February 3, 2012
.Os Void GNU/Linux .Os Void GNU/Linux
.Dt xbps-bin 8 .Dt xbps-bin 8
.Sh NAME .Sh NAME
@ -86,6 +86,17 @@ and
.Em update .Em update
targets targets
and target packages and its required dependencies will be matched. and target packages and its required dependencies will be matched.
.It Fl n
Enables dry-run mode.
To show the actions that would be executed in a transaction.
This mode takes effect in the
.Em autoremove ,
.Em autoupdate ,
.Em install ,
.Rm remove
and
.Em update
targets.
.It Fl o Ar key Op key2,... .It Fl o Ar key Op key2,...
Used currently in the Used currently in the
.Em show .Em show