xbps-rindex: fix clean mode while removing obsolete entries on index-files with updates.
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
|
||||
struct cbdata {
|
||||
xbps_array_t result;
|
||||
xbps_dictionary_t idx;
|
||||
const char *repourl;
|
||||
};
|
||||
|
||||
@@ -80,6 +81,32 @@ idx_cleaner_cb(struct xbps_handle *xhp,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
idxfiles_cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
|
||||
const char *key _unused, void *arg, bool *done _unused)
|
||||
{
|
||||
xbps_dictionary_t pkg;
|
||||
struct cbdata *cbd = arg;
|
||||
char *pkgname;
|
||||
const char *arch, *pkgver, *idxpkgver;
|
||||
|
||||
/* Find out entries on index-files that aren't registered on index */
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
|
||||
xbps_dbg_printf(xhp, "%s: checking %s [%s] ...", pkgver, arch);
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if ((pkg = xbps_dictionary_get(cbd->idx, pkgname))) {
|
||||
xbps_dictionary_get_cstring_nocopy(pkg, "pkgver", &idxpkgver);
|
||||
if (strcmp(idxpkgver, pkgver))
|
||||
xbps_array_add_cstring_nocopy(cbd->result, pkgver);
|
||||
}
|
||||
free(pkgname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Removes stalled pkg entries in repository's XBPS_REPOIDX file, if any
|
||||
* binary package cannot be read (unavailable, not enough perms, etc).
|
||||
@@ -113,17 +140,32 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
|
||||
}
|
||||
printf("Cleaning `%s' index, please wait...\n", repodir);
|
||||
|
||||
/*
|
||||
* First pass: find out obsolete entries on index and index-files.
|
||||
*/
|
||||
cbd.repourl = repodir;
|
||||
cbd.result = xbps_array_create();
|
||||
allkeys = xbps_dictionary_all_keys(idx);
|
||||
rv = xbps_array_foreach_cb(xhp, allkeys, idx, idx_cleaner_cb, &cbd);
|
||||
rv = xbps_array_foreach_cb_multi(xhp, allkeys, idx, idx_cleaner_cb, &cbd);
|
||||
|
||||
/*
|
||||
* Second pass: find out obsolete entries on index-files.
|
||||
*/
|
||||
cbd.idx = idx;
|
||||
xbps_object_release(allkeys);
|
||||
allkeys = xbps_dictionary_all_keys(idxfiles);
|
||||
rv = xbps_array_foreach_cb_multi(xhp, allkeys, idx, idxfiles_cleaner_cb, &cbd);
|
||||
|
||||
/*
|
||||
* Finally remove entries from both dictionaries.
|
||||
*/
|
||||
for (unsigned int x = 0; x < xbps_array_count(cbd.result); x++) {
|
||||
xbps_array_get_cstring_nocopy(cbd.result, x, &keyname);
|
||||
printf("index: removed entry %s\n", keyname);
|
||||
printf("index-files: removed entry %s\n", keyname);
|
||||
xbps_dictionary_remove(idxfiles, keyname);
|
||||
pkgname = xbps_pkg_name(keyname);
|
||||
xbps_dictionary_remove(idx, pkgname);
|
||||
printf("index: removed entry %s\n", pkgname);
|
||||
free(pkgname);
|
||||
flush = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user