pkg_metadir: fix some issues I've found while finding obsolete files.

This commit is contained in:
Juan RP 2012-11-18 12:07:43 +01:00
parent e08c258967
commit 6094bbc6ea
2 changed files with 31 additions and 34 deletions

View File

@ -34,7 +34,7 @@
struct pkgmeta { struct pkgmeta {
const char *name; char name[64];
prop_dictionary_t d; prop_dictionary_t d;
UT_hash_handle hh; UT_hash_handle hh;
}; };
@ -59,8 +59,7 @@ metadir_get(const char *name)
struct pkgmeta *pm; struct pkgmeta *pm;
HASH_FIND_STR(pkgmetas, __UNCONST(name), pm); HASH_FIND_STR(pkgmetas, __UNCONST(name), pm);
if (pm != NULL && if (pm && pm->d)
(prop_object_type(pm->d) == PROP_TYPE_DICTIONARY))
return pm->d; return pm->d;
return NULL; return NULL;
@ -70,7 +69,7 @@ prop_dictionary_t
xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name) xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name)
{ {
struct pkgmeta *pm; struct pkgmeta *pm;
prop_dictionary_t pkgd; prop_dictionary_t pkgd, d;
const char *savedpkgname; const char *savedpkgname;
char *plistf; char *plistf;
@ -97,25 +96,25 @@ xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name)
} }
} }
/* Add pkg plist to hash map */ d = prop_dictionary_internalize_from_zfile(plistf);
pm = malloc(sizeof(*pm));
assert(pm);
pm->name = name;
pm->d = prop_dictionary_internalize_from_zfile(plistf);
free(plistf); free(plistf);
if (d == NULL) {
if (pm->d == NULL) {
free(pm);
xbps_dbg_printf(xhp, "cannot read %s metadata: %s\n", xbps_dbg_printf(xhp, "cannot read %s metadata: %s\n",
savedpkgname, strerror(errno)); savedpkgname, strerror(errno));
return NULL; 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, HASH_ADD_KEYPTR(hh,
pkgmetas, pkgmetas,
__UNCONST(name), __UNCONST(name),
strlen(__UNCONST(name)), strlen(__UNCONST(name)),
pm); pm);
return pm->d; return d;
} }

View File

@ -80,11 +80,11 @@ unpack_archive(struct xbps_handle *xhp,
prop_dictionary_t pkg_repod, prop_dictionary_t pkg_repod,
struct archive *ar) struct archive *ar)
{ {
prop_dictionary_t filesd, old_filesd; prop_dictionary_t filesd = NULL, old_filesd = NULL;
prop_array_t array, obsoletes; prop_array_t array, obsoletes;
prop_object_t obj; prop_object_t obj;
prop_data_t data; prop_data_t data;
void *instbuf, *rembuf; void *instbuf = NULL, *rembuf = NULL;
const struct stat *entry_statp; const struct stat *entry_statp;
struct stat st; struct stat st;
struct xbps_unpack_cb_data xucd; 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(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
assert(ar != NULL); assert(ar != NULL);
instbuf = rembuf = NULL;
filesd = old_filesd = NULL;
preserve = update = conf_file = file_exists = false; preserve = update = conf_file = file_exists = false;
skip_obsoletes = softreplace = false; skip_obsoletes = softreplace = false;
@ -485,7 +483,8 @@ unpack_archive(struct xbps_handle *xhp,
* - Package with "softreplace" keyword. * - Package with "softreplace" keyword.
*/ */
old_filesd = xbps_metadir_get_pkgd(xhp, pkgname); old_filesd = xbps_metadir_get_pkgd(xhp, pkgname);
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) { assert(prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY);
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd); obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
for (i = 0; i < prop_array_count(obsoletes); i++) { for (i = 0; i < prop_array_count(obsoletes); i++) {
obj = prop_array_get(obsoletes, i); obj = prop_array_get(obsoletes, i);
@ -504,7 +503,6 @@ unpack_archive(struct xbps_handle *xhp,
"%s: removed obsolete entry: %s", pkgver, file); "%s: removed obsolete entry: %s", pkgver, file);
prop_object_release(obj); prop_object_release(obj);
} }
}
out1: out1:
/* Add objects from XBPS_PKGFILES */ /* Add objects from XBPS_PKGFILES */