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 (???): 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 * libxbps: when unpacking a package that replaced another package
due to virtual packages, preserve its configuration files if due to virtual packages, preserve its configuration files if
they already existed. they already existed.

View File

@ -55,7 +55,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.2" #define XBPS_PKGINDEX_VERSION "1.2"
#define XBPS_API_VERSION "20111030" #define XBPS_API_VERSION "20111030-1"
#define XBPS_VERSION "0.11.0" #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, pkgd = xbps_find_pkg_in_dict_by_name(xhp->regpkgdb_dictionary,
"packages", pkgname); "packages", pkgname);
if (pkgd == NULL) if (pkgd == NULL) {
xbps_dbg_printf("[purge] %s: missing pkg dictionary (%s)\n",
pkgname, strerror(errno));
return errno; return errno;
}
if (check_state) { 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) if ((rv = xbps_pkg_state_dictionary(pkgd, &state)) != 0)
return rv; 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; return rv;
}
} }
/* /*
* Remove unmodified configuration files. * Remove unmodified configuration files.
*/ */
dict = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES); dict = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
if (dict == NULL) if (dict == NULL) {
return errno; xbps_dbg_printf("[purge] %s: failed to read files.plist (%s)\n",
pkgname, strerror(errno));
if (prop_dictionary_get(dict, "conf_files")) { if (errno != ENOENT)
if ((rv = xbps_remove_pkg_files(dict, "conf_files")) != 0) { return errno;
} else {
if (prop_dictionary_get(dict, "conf_files")) {
rv = xbps_remove_pkg_files(dict, "conf_files");
prop_object_release(dict); 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) { if (chdir(prop_string_cstring_nocopy(xhp->rootdir)) == -1) {
rv = errno; rv = errno;
prop_object_release(dict); xbps_error_printf("[purge] %s: cannot change to rootdir "
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n", "(%s)\n", pkgname, strerror(rv));
pkgname, strerror(rv));
return rv; return rv;
} }
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname); buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
if (buf == NULL) { if (buf == NULL) {
prop_object_release(dict);
rv = ENOMEM; rv = ENOMEM;
return rv; return rv;
} }
@ -185,21 +193,20 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
xbps_error_printf("%s: purge action error in " xbps_error_printf("%s: purge action error in "
"REMOVE script: %s\n", pkgname, "REMOVE script: %s\n", pkgname,
strerror(errno)); strerror(errno));
prop_object_release(dict);
return rv; return rv;
} }
} }
} }
free(buf); free(buf);
prop_object_release(dict);
/* /*
* Remove metadata dir and unregister package. * Remove metadata dir and unregister package.
*/ */
if ((rv = remove_pkg_metadata(pkgname, if ((rv = remove_pkg_metadata(pkgname,
prop_string_cstring_nocopy(xhp->rootdir))) != 0) { prop_string_cstring_nocopy(xhp->rootdir))) != 0) {
xbps_error_printf("%s: couldn't remove metadata files: %s\n", xbps_dbg_printf("[purge] %s: failed to remove metadata "
pkgname, strerror(rv)); "files (%s)\n", pkgname, strerror(rv));
return rv; if (rv != ENOENT)
return rv;
} }
if ((rv = xbps_unregister_pkg(pkgname)) != 0) { if ((rv = xbps_unregister_pkg(pkgname)) != 0) {
xbps_error_printf("%s: couldn't unregister package: %s\n", xbps_error_printf("%s: couldn't unregister package: %s\n",