pkg_metadir: fix some issues I've found while finding obsolete files.
This commit is contained in:
parent
e08c258967
commit
6094bbc6ea
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -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,25 +483,25 @@ 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);
|
|
||||||
for (i = 0; i < prop_array_count(obsoletes); i++) {
|
obsoletes = xbps_find_pkg_obsoletes(xhp, old_filesd, filesd);
|
||||||
obj = prop_array_get(obsoletes, i);
|
for (i = 0; i < prop_array_count(obsoletes); i++) {
|
||||||
file = prop_string_cstring_nocopy(obj);
|
obj = prop_array_get(obsoletes, i);
|
||||||
if (remove(file) == -1) {
|
file = prop_string_cstring_nocopy(obj);
|
||||||
xbps_set_cb_state(xhp,
|
if (remove(file) == -1) {
|
||||||
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_set_cb_state(xhp,
|
||||||
XBPS_STATE_REMOVE_FILE_OBSOLETE,
|
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
|
||||||
0, pkgname, version,
|
errno, pkgname, version,
|
||||||
"%s: removed obsolete entry: %s", pkgver, file);
|
"%s: failed to remove obsolete entry `%s': %s",
|
||||||
prop_object_release(obj);
|
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:
|
out1:
|
||||||
|
Loading…
Reference in New Issue
Block a user