libxbps: modify the API, new func xbps_get_binpkg_repo_uri().
This function replaces xbps_repository_get_path_from_pkg_dict() and xbps_get_binpkg_local_path(). It takes a pkg dictionary as returned by a repository pkg index or a transaction dictionary and returns a string with the full path to the binary pkg, either in local repos, cachedir or remote repos. Update all code to use this function... sorry I broke ABI compatiblity.
This commit is contained in:
@@ -404,7 +404,7 @@ out:
|
||||
int
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||
{
|
||||
const char *pkgname, *repoloc, *version;
|
||||
const char *pkgname, *version;
|
||||
struct archive *ar = NULL;
|
||||
char *binfile = NULL;
|
||||
int pkg_fd, rv = 0;
|
||||
@@ -412,10 +412,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||
assert(pkg != NULL);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkg, "repository", &repoloc);
|
||||
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
||||
|
||||
binfile = xbps_get_binpkg_local_path(pkg, repoloc);
|
||||
binfile = xbps_get_binpkg_repo_uri(pkg);
|
||||
if (binfile == NULL)
|
||||
return EINVAL;
|
||||
|
||||
@@ -423,8 +422,10 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||
rv = errno;
|
||||
xbps_dbg_printf("cannot open '%s' for unpacking %s\n",
|
||||
binfile, strerror(errno));
|
||||
free(binfile);
|
||||
goto out;
|
||||
}
|
||||
free(binfile);
|
||||
|
||||
ar = archive_read_new();
|
||||
if (ar == NULL) {
|
||||
@@ -457,8 +458,6 @@ out:
|
||||
archive_read_finish(ar);
|
||||
if (pkg_fd != -1)
|
||||
(void)close(pkg_fd);
|
||||
if (binfile)
|
||||
free(binfile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2010 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg (at) NetBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -143,37 +143,6 @@ open_archive(const char *url)
|
||||
return a;
|
||||
}
|
||||
|
||||
static char *
|
||||
binpkg_in_cachedir(prop_dictionary_t d, const char *uri)
|
||||
{
|
||||
char *lbinfile;
|
||||
|
||||
lbinfile = xbps_get_binpkg_local_path(d, uri);
|
||||
if (lbinfile == NULL)
|
||||
return NULL;
|
||||
|
||||
if (access(lbinfile, R_OK) == 0)
|
||||
return lbinfile;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_repository_get_path_from_pkg_dict(prop_dictionary_t d, const char *uri)
|
||||
{
|
||||
const char *arch, *filen;
|
||||
char *path = NULL;
|
||||
|
||||
path = binpkg_in_cachedir(d, uri);
|
||||
if (path)
|
||||
return path;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(d, "architecture", &arch);
|
||||
prop_dictionary_get_cstring_nocopy(d, "filename", &filen);
|
||||
|
||||
return xbps_xasprintf("%s/%s/%s", uri, arch, filen);
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_repository_get_pkg_plist_dict_from_url(const char *url, const char *plistf)
|
||||
{
|
||||
@@ -225,7 +194,6 @@ prop_dictionary_t
|
||||
xbps_repository_get_pkg_plist_dict(const char *pkgname, const char *plistf)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL, plistd = NULL;
|
||||
const char *repoloc;
|
||||
char *url;
|
||||
int rv = 0;
|
||||
|
||||
@@ -246,8 +214,7 @@ xbps_repository_get_pkg_plist_dict(const char *pkgname, const char *plistf)
|
||||
if (pkgd == NULL)
|
||||
goto out;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
|
||||
url = xbps_repository_get_path_from_pkg_dict(pkgd, repoloc);
|
||||
url = xbps_get_binpkg_repo_uri(pkgd);
|
||||
if (url == NULL) {
|
||||
errno = EINVAL;
|
||||
goto out;
|
||||
|
||||
33
lib/util.c
33
lib/util.c
@@ -374,22 +374,35 @@ xbps_get_pkg_index_plist(const char *uri)
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_get_binpkg_local_path(prop_dictionary_t pkgd, const char *repoloc)
|
||||
xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod)
|
||||
{
|
||||
const char *filen, *arch, *cdir;
|
||||
const char *filen, *arch, *cdir, *repoloc;
|
||||
char *lbinpkg = NULL;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &filen);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "architecture", &arch);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
|
||||
cdir = xbps_get_cachedir();
|
||||
if (cdir == NULL)
|
||||
return NULL;
|
||||
|
||||
if (!xbps_check_is_repo_string_remote(repoloc)) {
|
||||
/* local repo */
|
||||
return xbps_xasprintf("%s/%s/%s", repoloc, arch, filen);
|
||||
}
|
||||
/* cachedir */
|
||||
return xbps_xasprintf("%s/%s", cdir, filen);
|
||||
/*
|
||||
* First check if binpkg is available in cachedir.
|
||||
*/
|
||||
lbinpkg = xbps_xasprintf("%s/%s", cdir, filen);
|
||||
if (lbinpkg == NULL)
|
||||
return NULL;
|
||||
|
||||
if (access(lbinpkg, R_OK) == 0)
|
||||
return lbinpkg;
|
||||
|
||||
free(lbinpkg);
|
||||
|
||||
/*
|
||||
* Local and remote repositories use the same path.
|
||||
*/
|
||||
return xbps_xasprintf("%s/%s/%s", repoloc, arch, filen);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Reference in New Issue
Block a user