diff --git a/lib/package_metadir.c b/lib/package_metadir.c index d0c545cd..e7f2e59c 100644 --- a/lib/package_metadir.c +++ b/lib/package_metadir.c @@ -34,7 +34,7 @@ struct pkgmeta { - const char *name; + char name[64]; prop_dictionary_t d; UT_hash_handle hh; }; @@ -59,8 +59,7 @@ metadir_get(const char *name) struct pkgmeta *pm; HASH_FIND_STR(pkgmetas, __UNCONST(name), pm); - if (pm != NULL && - (prop_object_type(pm->d) == PROP_TYPE_DICTIONARY)) + if (pm && pm->d) return pm->d; return NULL; @@ -70,7 +69,7 @@ prop_dictionary_t xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name) { struct pkgmeta *pm; - prop_dictionary_t pkgd; + prop_dictionary_t pkgd, d; const char *savedpkgname; char *plistf; @@ -97,25 +96,25 @@ xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name) } } - /* Add pkg plist to hash map */ - pm = malloc(sizeof(*pm)); - assert(pm); - pm->name = name; - pm->d = prop_dictionary_internalize_from_zfile(plistf); + d = prop_dictionary_internalize_from_zfile(plistf); free(plistf); - - if (pm->d == NULL) { - free(pm); + if (d == NULL) { xbps_dbg_printf(xhp, "cannot read %s metadata: %s\n", savedpkgname, strerror(errno)); return NULL; } + /* Add pkg plist to hash map */ + pm = calloc(1, sizeof(*pm)); + assert(pm); + strlcpy(pm->name, name, sizeof(pm->name)); + pm->d = d; + HASH_ADD_KEYPTR(hh, pkgmetas, __UNCONST(name), strlen(__UNCONST(name)), pm); - return pm->d; + return d; } diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 1ba658ca..9b5d5b96 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -80,11 +80,11 @@ unpack_archive(struct xbps_handle *xhp, prop_dictionary_t pkg_repod, struct archive *ar) { - prop_dictionary_t filesd, old_filesd; + prop_dictionary_t filesd = NULL, old_filesd = NULL; prop_array_t array, obsoletes; prop_object_t obj; prop_data_t data; - void *instbuf, *rembuf; + void *instbuf = NULL, *rembuf = NULL; const struct stat *entry_statp; struct stat st; struct xbps_unpack_cb_data xucd; @@ -103,8 +103,6 @@ unpack_archive(struct xbps_handle *xhp, assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY); assert(ar != NULL); - instbuf = rembuf = NULL; - filesd = old_filesd = NULL; preserve = update = conf_file = file_exists = false; skip_obsoletes = softreplace = false; @@ -485,25 +483,25 @@ unpack_archive(struct xbps_handle *xhp, * - Package with "softreplace" keyword. */ old_filesd = xbps_metadir_get_pkgd(xhp, pkgname); - if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) { - obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd); - for (i = 0; i < prop_array_count(obsoletes); i++) { - obj = prop_array_get(obsoletes, i); - file = prop_string_cstring_nocopy(obj); - if (remove(file) == -1) { - xbps_set_cb_state(xhp, - XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL, - errno, pkgname, version, - "%s: failed to remove obsolete entry `%s': %s", - pkgver, file, strerror(errno)); - continue; - } + assert(prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY); + + obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd); + for (i = 0; i < prop_array_count(obsoletes); i++) { + obj = prop_array_get(obsoletes, i); + file = prop_string_cstring_nocopy(obj); + if (remove(file) == -1) { xbps_set_cb_state(xhp, - XBPS_STATE_REMOVE_FILE_OBSOLETE, - 0, pkgname, version, - "%s: removed obsolete entry: %s", pkgver, file); - prop_object_release(obj); + XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL, + errno, pkgname, version, + "%s: failed to remove obsolete entry `%s': %s", + pkgver, file, strerror(errno)); + continue; } + xbps_set_cb_state(xhp, + XBPS_STATE_REMOVE_FILE_OBSOLETE, + 0, pkgname, version, + "%s: removed obsolete entry: %s", pkgver, file); + prop_object_release(obj); } out1: