libxbps: improve xbps_purge_pkg() in case that metadata dir doesn't exist.

This commit is contained in:
Juan RP 2011-10-30 11:12:03 +01:00
parent 858e616f41
commit 2a8b74484e
3 changed files with 29 additions and 18 deletions

4
NEWS
View File

@ -1,5 +1,9 @@
xbps-0.11.0 (???):
* libxbps: improve xbps_purge_pkg() in case that the process was
unexpectedly interrupted, do not error out unless the unregister
phase return an error value.
* libxbps: when unpacking a package that replaced another package
due to virtual packages, preserve its configuration files if
they already existed.

View File

@ -55,7 +55,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.2"
#define XBPS_API_VERSION "20111030"
#define XBPS_API_VERSION "20111030-1"
#define XBPS_VERSION "0.11.0"
/**

View File

@ -133,8 +133,11 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
*/
pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb_dictionary,
"packages", pkgname);
if (pkgd == NULL)
if (pkgd == NULL) {
xbps_dbg_printf("[purge] %s: missing pkg dictionary (%s)\n",
pkgname, strerror(errno));
return errno;
}
if (check_state) {
/*
@ -142,20 +145,27 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
*/
if ((rv = xbps_pkg_state_dictionary(pkgd, &state)) != 0)
return rv;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
if (state != XBPS_PKG_STATE_CONFIG_FILES) {
xbps_dbg_printf("[purge] %s not in config-files "
"state.\n", pkgname);
return rv;
}
}
/*
* Remove unmodified configuration files.
*/
dict = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
if (dict == NULL)
return errno;
if (prop_dictionary_get(dict, "conf_files")) {
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) {
if (dict == NULL) {
xbps_dbg_printf("[purge] %s: failed to read files.plist (%s)\n",
pkgname, strerror(errno));
if (errno != ENOENT)
return errno;
} else {
if (prop_dictionary_get(dict, "conf_files")) {
rv = xbps_remove_pkg_files(dict, "conf_files");
prop_object_release(dict);
return rv;
if (rv != 0)
return rv;
}
}
/*
@ -163,14 +173,12 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
*/
if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
rv = errno;
prop_object_release(dict);
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n",
pkgname, strerror(rv));
xbps_error_printf("[purge] %s: cannot change to rootdir "
"(%s)\n", pkgname, strerror(rv));
return rv;
}
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
if (buf == NULL) {
prop_object_release(dict);
rv = ENOMEM;
return rv;
}
@ -185,21 +193,20 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
xbps_error_printf("%s: purge action error in "
"REMOVE script: %s\n", pkgname,
strerror(errno));
prop_object_release(dict);
return rv;
}
}
}
free(buf);
prop_object_release(dict);
/*
* Remove metadata dir and unregister package.
*/
if ((rv = remove_pkg_metadata(pkgname,
prop_string_cstring_nocopy(xhp->rootdir))) != 0) {
xbps_error_printf("%s: couldn't remove metadata files: %s\n",
pkgname, strerror(rv));
return rv;
xbps_dbg_printf("[purge] %s: failed to remove metadata "
"files (%s)\n", pkgname, strerror(rv));
if (rv != ENOENT)
return rv;
}
if ((rv = xbps_unregister_pkg(pkgname)) != 0) {
xbps_error_printf("%s: couldn't unregister package: %s\n",