Multiple changes to pkgs on hold mode.

- Added transaction stats for pkgs on hold.

- Always add packages on hold to the transaction dictionary,
  its type will be set to XBPS_TRANS_HOLD.

- Changed xbps_transaction_update_pkg() to have a new "force"
  bool argument to force an update with a pkg on hold.

- As discussed in #274 with @Duncaen the only way to update a
  pkg on hold is by using `-f`, i.e `xbps-install -f foo`.

Closes #265
Closes #274
This commit is contained in:
Juan RP
2020-04-23 06:03:56 +02:00
parent 6b6b394686
commit 7d8247ae56
9 changed files with 127 additions and 108 deletions

View File

@@ -53,7 +53,7 @@
* data type is specified on its edge, i.e string, array, integer, dictionary.
*/
static int
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
{
xbps_dictionary_t pkg_pkgdb = NULL, pkg_repod = NULL;
xbps_object_t obj;
@@ -92,7 +92,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
return ENOENT;
}
} else {
if (reinstall) {
if (force) {
ttype = XBPS_TRANS_REINSTALL;
} else {
ttype = XBPS_TRANS_UPDATE;
@@ -195,12 +195,14 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool reinstall)
return rv;
}
if (ttype != XBPS_TRANS_HOLD) {
if (state == XBPS_PKG_STATE_UNPACKED)
ttype = XBPS_TRANS_CONFIGURE;
else if (state == XBPS_PKG_STATE_NOT_INSTALLED)
ttype = XBPS_TRANS_INSTALL;
}
if (state == XBPS_PKG_STATE_UNPACKED)
ttype = XBPS_TRANS_CONFIGURE;
else if (state == XBPS_PKG_STATE_NOT_INSTALLED)
ttype = XBPS_TRANS_INSTALL;
if (!force && xbps_dictionary_get(pkg_repod, "hold"))
ttype = XBPS_TRANS_HOLD;
/*
* Store pkgd from repo into the transaction.
*/
@@ -318,9 +320,6 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
char pkgname[XBPS_NAME_SIZE] = {0};
pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj);
if (xbps_dictionary_get(pkgd, "hold")) {
continue;
}
if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) {
continue;
}
@@ -346,7 +345,7 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
}
int
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
{
xbps_array_t rdeps;
int rv;
@@ -391,14 +390,13 @@ xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkg)
}
}
/* add pkg repod */
rv = trans_find_pkg(xhp, pkg, false);
rv = trans_find_pkg(xhp, pkg, force);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkg, rv);
return rv;
}
int
xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
bool reinstall)
xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg, bool force)
{
xbps_array_t rdeps;
int rv;
@@ -441,7 +439,7 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp, const char *pkg,
return rv;
}
}
rv = trans_find_pkg(xhp, pkg, reinstall);
rv = trans_find_pkg(xhp, pkg, force);
xbps_dbg_printf(xhp, "%s: trans_find_pkg %s: %d\n", __func__, pkg, rv);
return rv;
}

View File

@@ -62,8 +62,10 @@ compute_transaction_stats(struct xbps_handle *xhp)
struct statvfs svfs;
uint64_t rootdir_free_size, tsize, dlsize, instsize, rmsize;
uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt, dl_pkgcnt;
uint32_t hold_pkgcnt;
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = dl_pkgcnt = 0;
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
hold_pkgcnt = dl_pkgcnt = 0;
tsize = dlsize = instsize = rmsize = 0;
iter = xbps_array_iter_from_dict(xhp->transd, "packages");
@@ -92,6 +94,8 @@ compute_transaction_stats(struct xbps_handle *xhp)
inst_pkgcnt++;
} else if (ttype == XBPS_TRANS_UPDATE) {
up_pkgcnt++;
} else if (ttype == XBPS_TRANS_HOLD) {
hold_pkgcnt++;
}
if ((ttype != XBPS_TRANS_CONFIGURE) && (ttype != XBPS_TRANS_REMOVE) &&
@@ -152,6 +156,9 @@ compute_transaction_stats(struct xbps_handle *xhp)
if (!xbps_dictionary_set_uint32(xhp->transd,
"total-download-pkgs", dl_pkgcnt))
return EINVAL;
if (!xbps_dictionary_set_uint32(xhp->transd,
"total-hold-pkgs", hold_pkgcnt))
return EINVAL;
if (!xbps_dictionary_set_uint64(xhp->transd,
"total-installed-size", instsize))
return EINVAL;