xbps-bin: show which pkgs are updated and installed before proceeding.

--HG--
extra : convert_revision : 2c2fcd7f3c5909d14d1519ffc7e8ac0cad124b34
This commit is contained in:
Juan RP 2009-08-11 18:53:24 +02:00
parent b8c4131798
commit 45a58485eb
2 changed files with 57 additions and 26 deletions

View file

@ -50,10 +50,11 @@ struct transaction {
bool update;
};
static void cleanup(int);
static int exec_transaction(struct transaction *);
static void show_missing_deps(prop_dictionary_t, const char *);
static int show_missing_dep_cb(prop_object_t, void *, bool *);
static int exec_transaction(struct transaction *);
static void cleanup(int);
static void show_package_list(prop_object_iterator_t, const char *);
static void
show_missing_deps(prop_dictionary_t d, const char *pkgname)
@ -119,15 +120,44 @@ check_pkg_hashes(prop_object_iterator_t iter)
return 0;
}
static void
show_package_list(prop_object_iterator_t iter, const char *match)
{
prop_object_t obj;
size_t cols = 0;
const char *pkgname, *version, *tract;
bool first = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (strcmp(match, tract))
continue;
cols += strlen(pkgname) + strlen(version) + 4;
if (cols <= 80) {
if (first == false) {
printf(" ");
first = true;
}
} else {
printf("\n ");
cols = strlen(pkgname) + strlen(version) + 4;
}
printf("%s-%s ", pkgname, version);
}
prop_object_iterator_reset(iter);
}
static int
show_transaction_sizes(prop_object_iterator_t iter, const char *descr)
show_transaction_sizes(prop_object_iterator_t iter)
{
prop_object_t obj;
uint64_t tsize = 0, dlsize = 0, instsize = 0;
size_t cols = 0;
const char *pkgname, *version;
const char *tract;
char size[64];
bool first = false;
bool trans_inst = false, trans_up = false;
/*
* Iterate over the list of packages that are going to be
@ -143,28 +173,28 @@ show_transaction_sizes(prop_object_iterator_t iter, const char *descr)
}
prop_object_iterator_reset(iter);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "trans-action", &tract);
if (strcmp(tract, "install") == 0)
trans_inst = true;
else if (strcmp(tract, "update") == 0)
trans_up = true;
}
prop_object_iterator_reset(iter);
/*
* Show the list of packages that will be installed.
*/
printf("\nThe following new packages will be %s:\n\n", descr);
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
cols += strlen(pkgname) + strlen(version) + 4;
if (cols <= 80) {
if (first == false) {
printf(" ");
first = true;
}
} else {
printf("\n ");
cols = strlen(pkgname) + strlen(version) + 4;
}
printf("%s-%s ", pkgname, version);
if (trans_inst) {
printf("The following packages will be installed:\n\n");
show_package_list(iter, "install");
printf("\n\n");
}
if (trans_up) {
printf("The following packages will be updated:\n\n");
show_package_list(iter, "update");
printf("\n\n");
}
prop_object_iterator_reset(iter);
printf("\n\n");
/*
* Show total download/installed size for all required packages.
@ -291,8 +321,7 @@ exec_transaction(struct transaction *trans)
/*
* Show download/installed size for the transaction.
*/
rv = show_transaction_sizes(trans->iter,
trans->type == TRANS_ALL ? "updated" : "installed");
rv = show_transaction_sizes(trans->iter);
if (rv != 0)
return rv;

View file

@ -285,6 +285,8 @@ xbps_find_new_pkg(const char *pkgname, prop_dictionary_t instpkg)
goto out;
}
prop_dictionary_set_cstring_nocopy(pkgrd, "trans-action", "update");
if (!prop_array_add(unsorted, pkgrd))
rv = errno;