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:
Juan RP 2020-04-14 20:08:06 +02:00
parent b9fb5e1cc8
commit 70efe5c63a
3 changed files with 44 additions and 16 deletions

View File

@ -51,7 +51,7 @@
*
* This header documents the full API for the XBPS Library.
*/
#define XBPS_API_VERSION "20200221"
#define XBPS_API_VERSION "20200414"
#ifndef XBPS_VERSION
#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);
/**
* 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.
*/
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.

View File

@ -171,6 +171,11 @@ repo_open_local(struct xbps_repo *repo, const char *repofile)
repo->is_signed = true;
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;
}
@ -195,9 +200,9 @@ repo_open_remote(struct xbps_repo *repo)
static struct xbps_repo *
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;
char *repofile;
char *repofile = NULL;
assert(xhp);
assert(url);
@ -218,8 +223,7 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
char *rpath;
if ((rpath = xbps_get_remote_repo_string(url)) == NULL) {
free(repo);
return NULL;
goto out;
}
repofile = xbps_xasprintf("%s/%s/%s-%s", xhp->metadir, rpath, arch, name);
free(rpath);
@ -232,9 +236,10 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
* In memory repo sync.
*/
if (repo->is_remote && (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC)) {
if (repo_open_remote(repo))
if (repo_open_remote(repo)) {
free(repofile);
return repo;
}
goto out;
}
/*
@ -254,7 +259,7 @@ repo_open_with_type(struct xbps_handle *xhp, const char *url, const char *name)
out:
free(repofile);
xbps_repo_close(repo);
xbps_repo_release(repo);
return NULL;
}
@ -369,8 +374,23 @@ xbps_repo_close(struct xbps_repo *repo)
if (!repo)
return;
if (repo->ar != NULL)
if (repo->ar != NULL) {
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) {
xbps_object_release(repo->idx);
@ -380,9 +400,6 @@ xbps_repo_close(struct xbps_repo *repo)
xbps_object_release(repo->idxmeta);
repo->idxmeta = NULL;
}
if (repo->fd != -1)
close(repo->fd);
free(repo);
}

View File

@ -120,16 +120,18 @@ xbps_rpool_get_repo(const char *url)
}
void
xbps_rpool_release(struct xbps_handle *xhp UNUSED)
xbps_rpool_release(struct xbps_handle *xhp)
{
struct xbps_repo *repo;
while ((repo = SIMPLEQ_FIRST(&rpool_queue))) {
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);
xhp->repositories = NULL;
}
}
int