libxbps: added xbps_transaction_autoremove_pkgs(bool purge).
This is to add package orphans into the transaction dictionary.
This commit is contained in:
@@ -169,10 +169,11 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *version, *pkgver, *tract;
|
||||
int rv = 0;
|
||||
bool update;
|
||||
bool update, install, purge;
|
||||
|
||||
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
update = install = purge = false;
|
||||
xhp = xbps_handle_get();
|
||||
iter = xbps_array_iter_from_dict(transd, "packages");
|
||||
if (iter == NULL)
|
||||
@@ -203,15 +204,18 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
|
||||
if (strcmp(tract, "remove") == 0) {
|
||||
purge = update = false;
|
||||
/*
|
||||
* Remove a package.
|
||||
* Remove and optionally also purge package.
|
||||
*/
|
||||
prop_dictionary_get_bool(obj, "remove-and-update",
|
||||
&update);
|
||||
prop_dictionary_get_bool(obj, "remove-and-purge",
|
||||
&purge);
|
||||
rv = xbps_remove_pkg(pkgname, version, update);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
if (update)
|
||||
if (update || !purge)
|
||||
continue;
|
||||
|
||||
if ((rv = xbps_purge_pkg(pkgname, false)) != 0)
|
||||
@@ -229,6 +233,8 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
*/
|
||||
if (strcmp(tract, "update") == 0)
|
||||
update = true;
|
||||
else
|
||||
install = true;
|
||||
|
||||
if (update) {
|
||||
/*
|
||||
@@ -265,6 +271,10 @@ xbps_transaction_commit(prop_dictionary_t transd)
|
||||
}
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
/* if there are no packages to install or update we are done */
|
||||
if (!update && !install)
|
||||
goto out;
|
||||
/*
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
|
@@ -236,3 +236,55 @@ xbps_transaction_install_pkg(const char *pkgpattern)
|
||||
{
|
||||
return transaction_find_pkg(pkgpattern, "install");
|
||||
}
|
||||
|
||||
int
|
||||
xbps_transaction_autoremove_pkgs(bool purge)
|
||||
{
|
||||
prop_dictionary_t transd;
|
||||
prop_array_t orphans, mdeps, unsorted;
|
||||
prop_object_t obj;
|
||||
const char *pkgver;
|
||||
size_t count;
|
||||
int rv = 0;
|
||||
|
||||
orphans = xbps_find_pkg_orphans(NULL);
|
||||
if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
|
||||
return EINVAL;
|
||||
|
||||
count = prop_array_count(orphans);
|
||||
if (count == 0) {
|
||||
/* no orphans? we are done */
|
||||
rv = ENOENT;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Prepare transaction dictionary and missing deps array.
|
||||
*/
|
||||
if ((transd = xbps_transaction_dictionary_get()) == NULL) {
|
||||
rv = ENXIO;
|
||||
goto out;
|
||||
}
|
||||
if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) {
|
||||
rv = ENXIO;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Add pkg orphan dictionary into the unsorted_deps array.
|
||||
*/
|
||||
unsorted = prop_dictionary_get(transd, "unsorted_deps");
|
||||
while (count--) {
|
||||
obj = prop_array_get(orphans, count);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_set_cstring_nocopy(obj,
|
||||
"transaction", "remove");
|
||||
if (purge)
|
||||
prop_dictionary_set_bool(obj, "remove-and-purge", true);
|
||||
prop_array_add(unsorted, obj);
|
||||
xbps_dbg_printf("%s: added into transaction (remove).\n",
|
||||
pkgver);
|
||||
}
|
||||
out:
|
||||
if (prop_object_type(orphans) == PROP_TYPE_ARRAY)
|
||||
prop_object_release(orphans);
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user