static inline alpm_pkghash_t *pkgcache_add(alpm_pkghash_t *cache, struct pkg *pkg) { struct pkg *old = _alpm_pkghash_find(cache, pkg->name); int vercmp = old == NULL ? 0 : alpm_pkg_vercmp(pkg->version, old->version); if (vercmp == 0 || vercmp == 1) { if (old) { cache = _alpm_pkghash_remove(cache, old, NULL); package_free(old); } return _alpm_pkghash_add(cache, pkg); } return cache; }
void repo_database_reduce(repo_t *repo) { if (repo->pkgcache) { alpm_pkghash_t *cache = repo->pkgcache; alpm_list_t *node, *pkgs = cache->list; for (node = pkgs; node; node = node->next) { alpm_pkg_meta_t *pkg = node->data; if (faccessat(repo->dirfd, pkg->filename, F_OK, 0) < 0) { if (errno != ENOENT) err(EXIT_FAILURE, "couldn't access package %s", pkg->filename); printf(" dropping %s\n", pkg->name); cache = _alpm_pkghash_remove(cache, pkg, NULL); alpm_pkg_free_metadata(pkg); repo->state = REPO_DIRTY; continue; } } repo->pkgcache = cache; } }