xbps-rindex: consider stage area when removing packages.

This commit is contained in:
Enno Boland 2016-03-21 10:50:25 +01:00
parent 008de6f470
commit 3431715d67

View File

@ -67,7 +67,7 @@ remove_pkg(const char *repodir, const char *file)
static int static int
cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused, void *arg, bool *done _unused) cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused, void *arg, bool *done _unused)
{ {
struct xbps_repo *repo = arg; struct xbps_repo *repo = ((struct xbps_repo **)arg)[0], *stage = ((struct xbps_repo **)arg)[1];
const char *binpkg; const char *binpkg;
char *pkgver, *arch = NULL; char *pkgver, *arch = NULL;
int rv; int rv;
@ -97,7 +97,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused,
/* /*
* If binpkg is not registered in index, remove binpkg. * If binpkg is not registered in index, remove binpkg.
*/ */
if (!xbps_repo_get_pkg(repo, pkgver)) { if (!xbps_repo_get_pkg(repo, pkgver) && !(stage && xbps_repo_get_pkg(stage, pkgver))) {
if ((rv = remove_pkg(repo->uri, binpkg)) != 0) { if ((rv = remove_pkg(repo->uri, binpkg)) != 0) {
free(pkgver); free(pkgver);
return 0; return 0;
@ -112,13 +112,13 @@ int
remove_obsoletes(struct xbps_handle *xhp, const char *repodir) remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
{ {
xbps_array_t array = NULL; xbps_array_t array = NULL;
struct xbps_repo *repo; struct xbps_repo *repos[2], *repo, *stage;
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
char *ext; char *ext;
int rv = 0; int rv = 0;
repo = xbps_repo_open(xhp, repodir); repo = xbps_repo_public_open(xhp, repodir);
if (repo == NULL) { if (repo == NULL) {
if (errno != ENOENT) { if (errno != ENOENT) {
fprintf(stderr, "xbps-rindex: cannot read repository data: %s\n", fprintf(stderr, "xbps-rindex: cannot read repository data: %s\n",
@ -127,10 +127,13 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
} }
return 0; return 0;
} }
stage = xbps_repo_stage_open(xhp, repodir);
if (chdir(repodir) == -1) { if (chdir(repodir) == -1) {
fprintf(stderr, "xbps-rindex: cannot chdir to %s: %s\n", fprintf(stderr, "xbps-rindex: cannot chdir to %s: %s\n",
repodir, strerror(errno)); repodir, strerror(errno));
free(repo); free(repo);
if(stage)
free(stage);
return errno; return errno;
} }
if ((dirp = opendir(repodir)) == NULL) { if ((dirp = opendir(repodir)) == NULL) {
@ -153,8 +156,12 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
} }
(void)closedir(dirp); (void)closedir(dirp);
rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, repo); repos[0] = repo;
repos[1] = stage;
rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, repos);
xbps_repo_close(repo); xbps_repo_close(repo);
if(stage)
xbps_repo_close(stage);
xbps_object_release(array); xbps_object_release(array);
return rv; return rv;