xbps-rindex: cleanup stage area on -c too.
This commit is contained in:
parent
b9ce711848
commit
e1a76b13e5
@ -88,6 +88,34 @@ out:
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cleanup_repo(struct xbps_handle *xhp, const char *repodir, struct xbps_repo *repo,
|
||||||
|
const char *reponame) {
|
||||||
|
int rv = 0;
|
||||||
|
xbps_array_t allkeys;
|
||||||
|
/*
|
||||||
|
* First pass: find out obsolete entries on index and index-files.
|
||||||
|
*/
|
||||||
|
dest = xbps_dictionary_copy_mutable(repo->idx);
|
||||||
|
allkeys = xbps_dictionary_all_keys(dest);
|
||||||
|
(void)xbps_array_foreach_cb_multi(xhp, allkeys, repo->idx, idx_cleaner_cb, __UNCONST(repodir));
|
||||||
|
xbps_object_release(allkeys);
|
||||||
|
|
||||||
|
if (!xbps_dictionary_equals(dest, repo->idx)) {
|
||||||
|
if (!repodata_flush(xhp, repodir, reponame, dest, repo->idxmeta)) {
|
||||||
|
rv = errno;
|
||||||
|
fprintf(stderr, "failed to write repodata: %s\n",
|
||||||
|
strerror(errno));
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(strcmp("stagedata", reponame) == 0)
|
||||||
|
printf("stage: %u packages registered.\n", xbps_dictionary_count(dest));
|
||||||
|
else
|
||||||
|
printf("index: %u packages registered.\n", xbps_dictionary_count(dest));
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Removes stalled pkg entries in repository's XBPS_REPOIDX file, if any
|
* Removes stalled pkg entries in repository's XBPS_REPOIDX file, if any
|
||||||
* binary package cannot be read (unavailable, not enough perms, etc).
|
* binary package cannot be read (unavailable, not enough perms, etc).
|
||||||
@ -95,8 +123,7 @@ out:
|
|||||||
int
|
int
|
||||||
index_clean(struct xbps_handle *xhp, const char *repodir)
|
index_clean(struct xbps_handle *xhp, const char *repodir)
|
||||||
{
|
{
|
||||||
xbps_array_t allkeys;
|
struct xbps_repo *repo, *stage;
|
||||||
struct xbps_repo *repo;
|
|
||||||
char *rlockfname = NULL;
|
char *rlockfname = NULL;
|
||||||
int rv = 0, rlockfd = -1;
|
int rv = 0, rlockfd = -1;
|
||||||
|
|
||||||
@ -106,7 +133,7 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
_XBPS_RINDEX, strerror(rv));
|
_XBPS_RINDEX, strerror(rv));
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
repo = xbps_repo_open(xhp, repodir);
|
repo = xbps_repo_public_open(xhp, repodir);
|
||||||
if (repo == NULL) {
|
if (repo == NULL) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
if (rv == ENOENT) {
|
if (rv == ENOENT) {
|
||||||
@ -118,33 +145,24 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
xbps_repo_unlock(rlockfd, rlockfname);
|
xbps_repo_unlock(rlockfd, rlockfname);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
if (repo->idx == NULL) {
|
stage = xbps_repo_stage_open(xhp, repodir);
|
||||||
|
if (repo->idx == NULL || (stage && stage->idx == NULL)) {
|
||||||
fprintf(stderr, "%s: incomplete repository data file!\n", _XBPS_RINDEX);
|
fprintf(stderr, "%s: incomplete repository data file!\n", _XBPS_RINDEX);
|
||||||
rv = EINVAL;
|
rv = EINVAL;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
printf("Cleaning `%s' index, please wait...\n", repodir);
|
printf("Cleaning `%s' index, please wait...\n", repodir);
|
||||||
|
|
||||||
/*
|
if((rv = cleanup_repo(xhp, repodir, repo, "repodata")))
|
||||||
* First pass: find out obsolete entries on index and index-files.
|
|
||||||
*/
|
|
||||||
dest = xbps_dictionary_copy_mutable(repo->idx);
|
|
||||||
allkeys = xbps_dictionary_all_keys(dest);
|
|
||||||
(void)xbps_array_foreach_cb_multi(xhp, allkeys, repo->idx, idx_cleaner_cb, __UNCONST(repodir));
|
|
||||||
xbps_object_release(allkeys);
|
|
||||||
|
|
||||||
if (!xbps_dictionary_equals(dest, repo->idx)) {
|
|
||||||
if (!repodata_flush(xhp, repodir, "repodata", dest, repo->idxmeta)) {
|
|
||||||
rv = errno;
|
|
||||||
fprintf(stderr, "failed to write repodata: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
goto out;
|
goto out;
|
||||||
|
if(stage) {
|
||||||
|
cleanup_repo(xhp, repodir, stage, "stagedata");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
printf("index: %u packages registered.\n", xbps_dictionary_count(dest));
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
xbps_repo_close(repo);
|
xbps_repo_close(repo);
|
||||||
|
if(stage)
|
||||||
|
xbps_repo_close(stage);
|
||||||
xbps_repo_unlock(rlockfd, rlockfname);
|
xbps_repo_unlock(rlockfd, rlockfname);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
|
Loading…
Reference in New Issue
Block a user