xbps-install(8): added support to list pkgs that will be downloaded from remote repos.

This commit is contained in:
Juan RP 2014-07-14 09:30:28 +02:00
parent 207e95c029
commit 26fca48da2
3 changed files with 34 additions and 14 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.38 (???):
* xbps-install(8): added support to list packages that will be downloaded, if those
were available in a remote repository and were not in the cache directory.
* Before accepting a transaction, xbps now checks if there's enough free space
on the target rootdir (on disk) to proceed with the operation. In code terms,
xbps_transaction_prepare() now returns ENOSPC if the size of the transaction

View File

@ -43,6 +43,7 @@ struct transaction {
uint32_t up_pkgcnt;
uint32_t cf_pkgcnt;
uint32_t rm_pkgcnt;
uint32_t dl_pkgcnt;
};
static void
@ -78,7 +79,7 @@ show_actions(xbps_object_iterator_t iter)
}
static void
show_package_list(xbps_object_iterator_t iter, const char *match, int cols)
show_package_list(xbps_object_iterator_t iter, const char *match, int cols, bool dload)
{
xbps_object_t obj;
const char *pkgver, *tract;
@ -86,9 +87,11 @@ show_package_list(xbps_object_iterator_t iter, const char *match, int cols)
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
if (strcmp(match, tract))
continue;
if (dload && xbps_dictionary_get(obj, "download")) {
print_package_line(pkgver, cols, false);
} else if (strcmp(match, tract) == 0) {
print_package_line(pkgver, cols, false);
}
}
xbps_object_iterator_reset(iter);
print_package_line(NULL, cols, true);
@ -101,14 +104,23 @@ show_transaction_sizes(struct transaction *trans, int cols)
char size[8];
/*
* Show the list of packages that will be installed.
* Show the list of packages that will be downloaded, installed, updated,
* removed or configured.
*/
xbps_dictionary_get_uint32(trans->d, "total-download-pkgs",
&trans->dl_pkgcnt);
if (trans->dl_pkgcnt) {
printf("%u package%s will be downloaded:\n",
trans->dl_pkgcnt, trans->dl_pkgcnt == 1 ? "" : "s");
show_package_list(trans->iter, "install", cols, true);
printf("\n");
}
xbps_dictionary_get_uint32(trans->d, "total-install-pkgs",
&trans->inst_pkgcnt);
if (trans->inst_pkgcnt) {
printf("%u package%s will be installed:\n",
trans->inst_pkgcnt, trans->inst_pkgcnt == 1 ? "" : "s");
show_package_list(trans->iter, "install", cols);
show_package_list(trans->iter, "install", cols, false);
printf("\n");
}
xbps_dictionary_get_uint32(trans->d, "total-update-pkgs",
@ -116,7 +128,7 @@ show_transaction_sizes(struct transaction *trans, int cols)
if (trans->up_pkgcnt) {
printf("%u package%s will be updated:\n",
trans->up_pkgcnt, trans->up_pkgcnt == 1 ? "" : "s");
show_package_list(trans->iter, "update", cols);
show_package_list(trans->iter, "update", cols, false);
printf("\n");
}
xbps_dictionary_get_uint32(trans->d, "total-configure-pkgs",
@ -124,7 +136,7 @@ show_transaction_sizes(struct transaction *trans, int cols)
if (trans->cf_pkgcnt) {
printf("%u package%s will be configured:\n",
trans->cf_pkgcnt, trans->cf_pkgcnt == 1 ? "" : "s");
show_package_list(trans->iter, "configure", cols);
show_package_list(trans->iter, "configure", cols, false);
printf("\n");
}
xbps_dictionary_get_uint32(trans->d, "total-remove-pkgs",
@ -132,7 +144,7 @@ show_transaction_sizes(struct transaction *trans, int cols)
if (trans->rm_pkgcnt) {
printf("%u package%s will be removed:\n",
trans->rm_pkgcnt, trans->rm_pkgcnt == 1 ? "" : "s");
show_package_list(trans->iter, "remove", cols);
show_package_list(trans->iter, "remove", cols, false);
printf("\n");
}
/*
@ -314,8 +326,9 @@ exec_transaction(struct xbps_handle *xhp, int maxcols, bool yes, bool drun)
* It's time to run the transaction!
*/
if ((rv = xbps_transaction_commit(xhp)) == 0) {
printf("\n%u installed, %u updated, "
"%u configured, %u removed.\n", trans->inst_pkgcnt,
printf("\n%u downloaded, %u installed, %u updated, "
"%u configured, %u removed.\n",
trans->dl_pkgcnt, trans->inst_pkgcnt,
trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,
trans->rm_pkgcnt);
}

View File

@ -62,10 +62,10 @@ compute_transaction_stats(struct xbps_handle *xhp)
struct statvfs svfs;
unsigned long rootdir_free_size;
uint64_t tsize, dlsize, instsize, rmsize;
uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt;
uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt, dl_pkgcnt;
const char *tract, *pkgver, *repo;
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = dl_pkgcnt = 0;
tsize = dlsize = instsize = rmsize = 0;
iter = xbps_array_iter_from_dict(xhp->transd, "packages");
@ -108,6 +108,8 @@ compute_transaction_stats(struct xbps_handle *xhp)
tsize += 512;
dlsize += tsize;
instsize += tsize;
dl_pkgcnt++;
xbps_dictionary_set_bool(obj, "download", true);
}
}
/*
@ -153,7 +155,9 @@ compute_transaction_stats(struct xbps_handle *xhp)
if (!xbps_dictionary_set_uint32(xhp->transd,
"total-remove-pkgs", rm_pkgcnt))
return EINVAL;
if (!xbps_dictionary_set_uint32(xhp->transd,
"total-download-pkgs", dl_pkgcnt))
return EINVAL;
if (!xbps_dictionary_set_uint64(xhp->transd,
"total-installed-size", instsize))
return EINVAL;