libxbps: introduce the concept of "soft replace"; see the NEWS file.
This commit is contained in:
@@ -264,7 +264,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
|
||||
}
|
||||
|
||||
int
|
||||
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
xbps_remove_pkg(const char *pkgname, const char *version, bool update,
|
||||
bool soft_replace)
|
||||
{
|
||||
struct xbps_handle *xhp;
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
@@ -343,6 +344,13 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
free(pkgver);
|
||||
free(buf);
|
||||
return xbps_requiredby_pkg_remove(pkgname);
|
||||
} else if (soft_replace) {
|
||||
/*
|
||||
* Soft replace a package. Do not remove its files, but
|
||||
* execute PURGE action, remove metadata files and unregister
|
||||
* from pkgdb.
|
||||
*/
|
||||
goto softreplace;
|
||||
}
|
||||
|
||||
pkgd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
|
||||
@@ -383,6 +391,8 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
||||
pkgver, strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
|
||||
softreplace:
|
||||
/*
|
||||
* Set package state to "half-removed".
|
||||
*/
|
||||
|
@@ -190,7 +190,7 @@ xbps_transaction_commit(void)
|
||||
size_t i;
|
||||
const char *pkgname, *version, *pkgver, *tract;
|
||||
int rv = 0;
|
||||
bool update, install;
|
||||
bool update, install, sr;
|
||||
|
||||
assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
@@ -234,12 +234,14 @@ xbps_transaction_commit(void)
|
||||
|
||||
if (strcmp(tract, "remove") == 0) {
|
||||
update = false;
|
||||
sr = false;
|
||||
/*
|
||||
* Remove package.
|
||||
*/
|
||||
prop_dictionary_get_bool(obj, "remove-and-update",
|
||||
&update);
|
||||
rv = xbps_remove_pkg(pkgname, version, update);
|
||||
prop_dictionary_get_bool(obj, "softreplace", &sr);
|
||||
rv = xbps_remove_pkg(pkgname, version, update, sr);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
} else if (strcmp(tract, "configure") == 0) {
|
||||
@@ -265,7 +267,8 @@ xbps_transaction_commit(void)
|
||||
*/
|
||||
xbps_set_cb_state(XBPS_STATE_UPDATE, 0,
|
||||
pkgname, version, NULL);
|
||||
rv = xbps_remove_pkg(pkgname, version, true);
|
||||
rv = xbps_remove_pkg(pkgname, version,
|
||||
true, false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(
|
||||
XBPS_STATE_UPDATE_FAIL,
|
||||
|
@@ -40,7 +40,7 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
|
||||
bool instd_auto;
|
||||
bool instd_auto, sr;
|
||||
size_t idx;
|
||||
|
||||
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
|
||||
@@ -141,6 +141,22 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
|
||||
prop_dictionary_set_bool(pkg_repod,
|
||||
"automatic-install", instd_auto);
|
||||
}
|
||||
/*
|
||||
* Copy requiredby and automatic-install objects
|
||||
* from replaced package into pkg's dictionary
|
||||
* for "softreplace" packages.
|
||||
*/
|
||||
sr = false;
|
||||
prop_dictionary_get_bool(pkg_repod, "softreplace", &sr);
|
||||
if (sr) {
|
||||
if (instd_reqby &&
|
||||
prop_array_count(instd_reqby)) {
|
||||
prop_dictionary_set(pkg_repod,
|
||||
"requiredby", instd_reqby);
|
||||
}
|
||||
prop_dictionary_set_bool(pkg_repod,
|
||||
"automatic-install", instd_auto);
|
||||
}
|
||||
/*
|
||||
* Add package dictionary into the transaction and mark
|
||||
* it as to be "removed".
|
||||
|
Reference in New Issue
Block a user