libxbps: introduce the concept of "soft replace"; see the NEWS file.

This commit is contained in:
Juan RP 2012-05-25 17:24:36 +02:00
parent d075f7182a
commit 6a4de0127d
5 changed files with 45 additions and 7 deletions

6
NEWS
View File

@ -1,5 +1,11 @@
xbps-0.16 (???): xbps-0.16 (???):
* libxbps: introduce the concept of "soft replace". When a package
contains that boolean object set in pkg's metadata props.plist,
some steps will be skipped at remove time for the package being
replaced: its files won't be removed and the post action in REMOVE
file won't be executed.
* libxbps: change the order in which package files are removed: * libxbps: change the order in which package files are removed:
current: files, conf_files, links, directories. current: files, conf_files, links, directories.

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.4" #define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120525" #define XBPS_API_VERSION "20120525-1"
#define XBPS_VERSION "0.16" #define XBPS_VERSION "0.16"
/** /**
@ -1330,10 +1330,13 @@ int xbps_unregister_pkg(const char *pkgname, const char *version, bool flush);
* @param[in] version Package version associated. * @param[in] version Package version associated.
* @param[in] update If true, some steps will be skipped. See in the * @param[in] update If true, some steps will be skipped. See in the
* detailed description above for more information. * detailed description above for more information.
* @param[in] soft_replace If true, some steps will be skipped. See in
* the detailed description above for more information.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_remove_pkg(const char *pkgname, const char *version, bool update); int xbps_remove_pkg(const char *pkgname, const char *version, bool update,
bool soft_replace);
/** /**
* Remove files defined in a proplib array as specified by \a key * Remove files defined in a proplib array as specified by \a key

View File

@ -264,7 +264,8 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
} }
int 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; struct xbps_handle *xhp;
prop_dictionary_t pkgd = NULL; prop_dictionary_t pkgd = NULL;
@ -343,6 +344,13 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
free(pkgver); free(pkgver);
free(buf); free(buf);
return xbps_requiredby_pkg_remove(pkgname); 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); 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)); pkgver, strerror(rv));
goto out; goto out;
} }
softreplace:
/* /*
* Set package state to "half-removed". * Set package state to "half-removed".
*/ */

View File

@ -190,7 +190,7 @@ xbps_transaction_commit(void)
size_t i; size_t i;
const char *pkgname, *version, *pkgver, *tract; const char *pkgname, *version, *pkgver, *tract;
int rv = 0; int rv = 0;
bool update, install; bool update, install, sr;
assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY);
@ -234,12 +234,14 @@ xbps_transaction_commit(void)
if (strcmp(tract, "remove") == 0) { if (strcmp(tract, "remove") == 0) {
update = false; update = false;
sr = false;
/* /*
* Remove package. * Remove package.
*/ */
prop_dictionary_get_bool(obj, "remove-and-update", prop_dictionary_get_bool(obj, "remove-and-update",
&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) if (rv != 0)
goto out; goto out;
} else if (strcmp(tract, "configure") == 0) { } else if (strcmp(tract, "configure") == 0) {
@ -265,7 +267,8 @@ xbps_transaction_commit(void)
*/ */
xbps_set_cb_state(XBPS_STATE_UPDATE, 0, xbps_set_cb_state(XBPS_STATE_UPDATE, 0,
pkgname, version, NULL); pkgname, version, NULL);
rv = xbps_remove_pkg(pkgname, version, true); rv = xbps_remove_pkg(pkgname, version,
true, false);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state( xbps_set_cb_state(
XBPS_STATE_UPDATE_FAIL, XBPS_STATE_UPDATE_FAIL,

View File

@ -40,7 +40,7 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver; const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
bool instd_auto; bool instd_auto, sr;
size_t idx; size_t idx;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); 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, prop_dictionary_set_bool(pkg_repod,
"automatic-install", instd_auto); "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 * Add package dictionary into the transaction and mark
* it as to be "removed". * it as to be "removed".