repo: introduce xbps_repo_release(), misc changes.
- xbps_repo_release(): new function to release all resources associated with a repository object. - xbps_repo_close(): this now just closes the file descriptor associated with the archive and associated resources. - repo_open_local: after getting the repository dictionaries, use xbps_repo_close() to release archive resources. Bump XBPS_API_VERSION.
This commit is contained in:
parent
b9fb5e1cc8
commit
70efe5c63a
@ -51,7 +51,7 @@
|
|||||||
*
|
*
|
||||||
* This header documents the full API for the XBPS Library.
|
* This header documents the full API for the XBPS Library.
|
||||||
*/
|
*/
|
||||||
#define XBPS_API_VERSION "20200221"
|
#define XBPS_API_VERSION "20200414"
|
||||||
|
|
||||||
#ifndef XBPS_VERSION
|
#ifndef XBPS_VERSION
|
||||||
#define XBPS_VERSION "UNSET"
|
#define XBPS_VERSION "UNSET"
|
||||||
@ -1645,12 +1645,21 @@ struct xbps_repo *xbps_repo_stage_open(struct xbps_handle *xhp, const char *url)
|
|||||||
struct xbps_repo *xbps_repo_public_open(struct xbps_handle *xhp, const char *url);
|
struct xbps_repo *xbps_repo_public_open(struct xbps_handle *xhp, const char *url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes a repository object and releases resources.
|
* Closes a repository object, its archive associated is
|
||||||
|
* closed and those resources released.
|
||||||
*
|
*
|
||||||
* @param[in] repo The repository object to close.
|
* @param[in] repo The repository object to close.
|
||||||
*/
|
*/
|
||||||
void xbps_repo_close(struct xbps_repo *repo);
|
void xbps_repo_close(struct xbps_repo *repo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This calls \fn xbps_repo_close and releases all resources
|
||||||
|
* associated with this repository object.
|
||||||
|
*
|
||||||
|
* @param[in] repo The repository object to release.
|
||||||
|
*/
|
||||||
|
void xbps_repo_release(struct xbps_repo *repo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Returns a heap-allocated string with the repository local path.
|
* Returns a heap-allocated string with the repository local path.
|
||||||
|
39
lib/repo.c
39
lib/repo.c
@ -171,6 +171,11 @@ repo_open_local(struct xbps_repo *repo, const char *repofile)
|
|||||||
repo->is_signed = true;
|
repo->is_signed = true;
|
||||||
xbps_dictionary_make_immutable(repo->idxmeta);
|
xbps_dictionary_make_immutable(repo->idxmeta);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
|
* We don't need the archive anymore, we are only
|
||||||
|
* interested in the proplib dictionaries.
|
||||||
|
*/
|
||||||
|
xbps_repo_close(repo);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -195,9 +200,9 @@ repo_open_remote(struct xbps_repo *repo)
|
|||||||
static struct xbps_repo *
|
static struct xbps_repo *
|
||||||
repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
||||||
{
|
{
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo = NULL;
|
||||||
const char *arch;
|
const char *arch;
|
||||||
char *repofile;
|
char *repofile = NULL;
|
||||||
|
|
||||||
assert(xhp);
|
assert(xhp);
|
||||||
assert(url);
|
assert(url);
|
||||||
@ -218,8 +223,7 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
|||||||
char *rpath;
|
char *rpath;
|
||||||
|
|
||||||
if ((rpath = xbps_get_remote_repo_string(url)) == NULL) {
|
if ((rpath = xbps_get_remote_repo_string(url)) == NULL) {
|
||||||
free(repo);
|
goto out;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
repofile = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir, rpath, arch, name);
|
repofile = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir, rpath, arch, name);
|
||||||
free(rpath);
|
free(rpath);
|
||||||
@ -232,9 +236,10 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
|||||||
* In memory repo sync.
|
* In memory repo sync.
|
||||||
*/
|
*/
|
||||||
if (repo->is_remote && (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC)) {
|
if (repo->is_remote && (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC)) {
|
||||||
if (repo_open_remote(repo))
|
if (repo_open_remote(repo)) {
|
||||||
|
free(repofile);
|
||||||
return repo;
|
return repo;
|
||||||
|
}
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -254,7 +259,7 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
|
|||||||
|
|
||||||
out:
|
out:
|
||||||
free(repofile);
|
free(repofile);
|
||||||
xbps_repo_close(repo);
|
xbps_repo_release(repo);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,8 +374,23 @@ xbps_repo_close(struct xbps_repo *repo)
|
|||||||
if (!repo)
|
if (!repo)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (repo->ar != NULL)
|
if (repo->ar != NULL) {
|
||||||
archive_read_finish(repo->ar);
|
archive_read_finish(repo->ar);
|
||||||
|
repo->ar = NULL;
|
||||||
|
}
|
||||||
|
if (repo->fd != -1) {
|
||||||
|
close(repo->fd);
|
||||||
|
repo->fd = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xbps_repo_release(struct xbps_repo *repo)
|
||||||
|
{
|
||||||
|
if (!repo)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xbps_repo_close(repo);
|
||||||
|
|
||||||
if (repo->idx != NULL) {
|
if (repo->idx != NULL) {
|
||||||
xbps_object_release(repo->idx);
|
xbps_object_release(repo->idx);
|
||||||
@ -380,9 +400,6 @@ xbps_repo_close(struct xbps_repo *repo)
|
|||||||
xbps_object_release(repo->idxmeta);
|
xbps_object_release(repo->idxmeta);
|
||||||
repo->idxmeta = NULL;
|
repo->idxmeta = NULL;
|
||||||
}
|
}
|
||||||
if (repo->fd != -1)
|
|
||||||
close(repo->fd);
|
|
||||||
|
|
||||||
free(repo);
|
free(repo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,16 +120,18 @@ xbps_rpool_get_repo(const char *url)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
xbps_rpool_release(struct xbps_handle *xhp UNUSED)
|
xbps_rpool_release(struct xbps_handle *xhp)
|
||||||
{
|
{
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo;
|
||||||
|
|
||||||
while ((repo = SIMPLEQ_FIRST(&rpool_queue))) {
|
while ((repo = SIMPLEQ_FIRST(&rpool_queue))) {
|
||||||
SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries);
|
SIMPLEQ_REMOVE(&rpool_queue, repo, xbps_repo, entries);
|
||||||
xbps_repo_close(repo);
|
xbps_repo_release(repo);
|
||||||
}
|
}
|
||||||
if (xhp->repositories)
|
if (xhp && xhp->repositories) {
|
||||||
xbps_object_release(xhp->repositories);
|
xbps_object_release(xhp->repositories);
|
||||||
|
xhp->repositories = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
Reference in New Issue
Block a user