xbps_init() now sets rootdir, cachedir and flags.

That means that the following functions were removed:
	- xbps_set_{cachedir,flags,rootdir}.
	- xbps_get_{cachedir,flags,rootdir}.

With this change fixed an obvious typo that made -c argument to not work,
and now the cache directory is an absolute path not relative to rootdir.
This commit is contained in:
Juan RP 2011-02-21 17:42:47 +01:00
parent 8d5a1ad0a3
commit 870ad18d58
30 changed files with 195 additions and 227 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.8.0 (???): xbps-0.8.0 (???):
* xbps-{bin,repo): -c (cachedir) argument now is an absolute path and
not relative to the root directory.
* Fixed finally when a package should replace an installed package, but * Fixed finally when a package should replace an installed package, but
at the same time the package to be replaced also needs to be updated at the same time the package to be replaced also needs to be updated
in the transaction. A real example: in the transaction. A real example:

View File

@ -91,6 +91,7 @@ out:
int int
xbps_check_pkg_integrity(const char *pkgname) xbps_check_pkg_integrity(const char *pkgname)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t pkgd, propsd = NULL, filesd = NULL; prop_dictionary_t pkgd, propsd = NULL, filesd = NULL;
prop_array_t array; prop_array_t array;
prop_object_t obj; prop_object_t obj;
@ -101,6 +102,7 @@ xbps_check_pkg_integrity(const char *pkgname)
bool broken = false, files_broken = false; bool broken = false, files_broken = false;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
pkgd = xbps_find_pkg_dict_installed(pkgname, false); pkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (pkgd == NULL) { if (pkgd == NULL) {
@ -158,8 +160,7 @@ xbps_check_pkg_integrity(const char *pkgname)
} }
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file); prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s", path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
xbps_get_rootdir(), file);
if (path == NULL) { if (path == NULL) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = errno; rv = errno;
@ -209,8 +210,7 @@ xbps_check_pkg_integrity(const char *pkgname)
} }
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file); prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s", path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
xbps_get_rootdir(), file);
if (path == NULL) { if (path == NULL) {
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
rv = ENOMEM; rv = ENOMEM;

View File

@ -71,6 +71,7 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t ke
int int
find_files_in_packages(const char *pattern) find_files_in_packages(const char *pattern)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t pkg_filesd; prop_dictionary_t pkg_filesd;
prop_array_t files_keys; prop_array_t files_keys;
DIR *dirp; DIR *dirp;
@ -79,7 +80,8 @@ find_files_in_packages(const char *pattern)
int rv = 0; int rv = 0;
unsigned int i, count; unsigned int i, count;
path = xbps_xasprintf("%s/%s/metadata", xbps_get_rootdir(), xhp = xbps_handle_get();
path = xbps_xasprintf("%s/%s/metadata", xhp->rootdir,
XBPS_META_PATH); XBPS_META_PATH);
if (path == NULL) if (path == NULL)
return -1; return -1;

View File

@ -93,16 +93,14 @@ check_binpkg_hash(const char *path,
static int static int
download_package_list(prop_object_iterator_t iter, bool only_show) download_package_list(prop_object_iterator_t iter, bool only_show)
{ {
const struct xbps_handle *xhp;
prop_object_t obj; prop_object_t obj;
const char *pkgver, *repoloc, *filename, *cachedir, *sha256; const char *pkgver, *repoloc, *filename, *sha256;
char *binfile; char *binfile;
int rv = 0; int rv = 0;
bool cksum; bool cksum;
cachedir = xbps_get_cachedir(); xhp = xbps_handle_get();
if (cachedir == NULL)
return EINVAL;
again: again:
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
cksum = false; cksum = false;
@ -141,12 +139,12 @@ again:
free(binfile); free(binfile);
continue; continue;
} }
if (xbps_mkpath(__UNCONST(cachedir), 0755) == -1) { if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
free(binfile); free(binfile);
return errno; return errno;
} }
printf("Downloading %s binary package ...\n", pkgver); printf("Downloading %s binary package ...\n", pkgver);
rv = xbps_fetch_file(binfile, cachedir, false, NULL); rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
if (rv == -1) { if (rv == -1) {
xbps_error_printf("xbps-bin: couldn't download `%s'\n", xbps_error_printf("xbps-bin: couldn't download `%s'\n",
filename); filename);
@ -374,13 +372,15 @@ xbps_update_pkg(const char *pkgname)
static int static int
exec_transaction(struct transaction *trans) exec_transaction(struct transaction *trans)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t instpkgd; prop_dictionary_t instpkgd;
prop_object_t obj; prop_object_t obj;
const char *pkgname, *version, *pkgver, *instver, *filen, *tract; const char *pkgname, *version, *pkgver, *instver, *filen, *tract;
int flags = xbps_get_flags(), rv = 0; int rv = 0;
bool update, preserve, autoinst; bool update, preserve, autoinst;
pkg_state_t state; pkg_state_t state;
xhp = xbps_handle_get();
/* /*
* Only show the URLs to download the binary packages. * Only show the URLs to download the binary packages.
*/ */
@ -497,7 +497,7 @@ exec_transaction(struct transaction *trans)
"(%s)\n", pkgver, strerror(rv)); "(%s)\n", pkgver, strerror(rv));
return rv; return rv;
} }
if ((flags & XBPS_FLAG_VERBOSE) == 0) if ((xhp->flags & XBPS_FLAG_VERBOSE) == 0)
printf("\n"); printf("\n");
/* /*
* Register binary package. * Register binary package.

View File

@ -191,17 +191,19 @@ main(int argc, char **argv)
struct xbps_fetch_progress_data xfpd; struct xbps_fetch_progress_data xfpd;
struct list_pkgver_cb lpc; struct list_pkgver_cb lpc;
struct sigaction sa; struct sigaction sa;
const char *rootdir, *cachedir;
int i , c, flags, rv; int i , c, flags, rv;
bool yes, purge, with_debug, force_rm_with_deps, recursive_rm; bool yes, purge, with_debug, force_rm_with_deps, recursive_rm;
bool show_download_pkglist_url = false; bool show_download_pkglist_url = false;
rootdir = cachedir = NULL;
flags = rv = 0; flags = rv = 0;
yes = purge = force_rm_with_deps = recursive_rm = with_debug = false; yes = purge = force_rm_with_deps = recursive_rm = with_debug = false;
while ((c = getopt(argc, argv, "VcdDFfpRr:vy")) != -1) { while ((c = getopt(argc, argv, "Vc:dDFfpRr:vy")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
xbps_set_cachedir(optarg); cachedir = optarg;
break; break;
case 'd': case 'd':
with_debug = true; with_debug = true;
@ -223,7 +225,7 @@ main(int argc, char **argv)
break; break;
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
xbps_set_rootdir(optarg); rootdir = optarg;
break; break;
case 'v': case 'v':
flags |= XBPS_FLAG_VERBOSE; flags |= XBPS_FLAG_VERBOSE;
@ -246,9 +248,6 @@ main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(); usage();
if (flags != 0)
xbps_set_flags(flags);
/* /*
* Register a signal handler to clean up resources used by libxbps. * Register a signal handler to clean up resources used by libxbps.
*/ */
@ -270,6 +269,9 @@ main(int argc, char **argv)
else else
xh.xbps_unpack_cb = unpack_progress_cb_percentage; xh.xbps_unpack_cb = unpack_progress_cb_percentage;
xh.xupd = &xupd; xh.xupd = &xupd;
xh.rootdir = rootdir;
xh.cachedir = cachedir;
xh.flags = flags;
xbps_init(&xh); xbps_init(&xh);
if ((dict = xbps_regpkgdb_dictionary_get()) == NULL) { if ((dict = xbps_regpkgdb_dictionary_get()) == NULL) {

View File

@ -7,7 +7,7 @@
.\" Source: \ \& .\" Source: \ \&
.\" Language: English .\" Language: English
.\" .\"
.TH "XBPS\-BIN" "8" "02/05/2011" "\ \&" "\ \&" .TH "XBPS\-BIN" "8" "02/21/2011" "\ \&" "\ \&"
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
.\" * set default formatting .\" * set default formatting
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
@ -31,13 +31,7 @@ The xbps\-bin(8) command is used to handle binary packages created for the XBPS
\fB\-c\fR \fIcachedir\fR \fB\-c\fR \fIcachedir\fR
.RS 4 .RS 4
Sets the cache directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to Sets the cache directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to
\fI/var/cache/xbps\fR \fI/var/cache/xbps\fR\&.
and it\(cqs always relative to the
\fIroot directory\fR\&. So if you use a
\fIrootdir\fR
of
\fI/blah\fR, it will become
\fI/blah/cachedir\fR\&.
.RE .RE
.PP .PP
\fB\-d\fR \fB\-d\fR

View File

@ -442,9 +442,10 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
prop_dictionary_t plistd, confd = NULL; prop_dictionary_t plistd, confd = NULL;
struct xbps_handle xh;
FILE *f = NULL; FILE *f = NULL;
char *outfile = NULL; char *outfile = NULL;
const char *conf_file = NULL; const char *conf_file = NULL, *rootdir = NULL;
int c; int c;
bool revdeps = false; bool revdeps = false;
@ -468,7 +469,7 @@ main(int argc, char **argv)
break; break;
case 'r': case 'r':
/* Set different rootdir. */ /* Set different rootdir. */
xbps_set_rootdir(optarg); rootdir = optarg;
break; break;
case '?': case '?':
default: default:
@ -482,6 +483,11 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
/* Initialize libxbps */
memset(&xh, 0, sizeof(xh));
xh.rootdir = rootdir;
xbps_init(&xh);
/* /*
* Output file will be <pkgname>.dot if not specified. * Output file will be <pkgname>.dot if not specified.
*/ */

View File

@ -80,22 +80,23 @@ main(int argc, char **argv)
struct xbps_handle xh; struct xbps_handle xh;
struct xbps_fetch_progress_data xfpd; struct xbps_fetch_progress_data xfpd;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
char *root; const char *rootdir, *cachedir;
int c, rv = 0; int c, rv = 0;
bool with_debug = false; bool with_debug = false;
while ((c = getopt(argc, argv, "Vcdr:")) != -1) { rootdir = cachedir = NULL;
while ((c = getopt(argc, argv, "Vc:dr:")) != -1) {
switch (c) { switch (c) {
case 'c': case 'c':
xbps_set_cachedir(optarg); cachedir = optarg;
break; break;
case 'd': case 'd':
with_debug = true; with_debug = true;
break; break;
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
root = optarg; rootdir = optarg;
xbps_set_rootdir(root);
break; break;
case 'V': case 'V':
printf("%s\n", XBPS_RELVER); printf("%s\n", XBPS_RELVER);
@ -119,6 +120,8 @@ main(int argc, char **argv)
xh.with_debug = with_debug; xh.with_debug = with_debug;
xh.xbps_fetch_cb = fetch_file_progress_cb; xh.xbps_fetch_cb = fetch_file_progress_cb;
xh.xfpd = &xfpd; xh.xfpd = &xfpd;
xh.rootdir = rootdir;
xh.cachedir = cachedir;
xbps_init(&xh); xbps_init(&xh);
if ((rv = xbps_repository_pool_init()) != 0) { if ((rv = xbps_repository_pool_init()) != 0) {

View File

@ -163,11 +163,13 @@ unregister_repository(const char *uri)
int int
register_repository(const char *uri) register_repository(const char *uri)
{ {
const struct xbps_handle *xhp;
struct repoinfo *rpi = NULL; struct repoinfo *rpi = NULL;
const char *idxstr = NULL; const char *idxstr = NULL;
char *metadir, *plist; char *metadir, *plist;
int rv = 0; int rv = 0;
xhp = xbps_handle_get();
if ((idxstr = sanitize_url(uri)) == NULL) if ((idxstr = sanitize_url(uri)) == NULL)
return errno; return errno;
@ -189,7 +191,7 @@ register_repository(const char *uri)
/* /*
* Create metadir if necessary. * Create metadir if necessary.
*/ */
metadir = xbps_xasprintf("%s/%s", xbps_get_rootdir(), metadir = xbps_xasprintf("%s/%s", xhp->rootdir,
XBPS_META_PATH); XBPS_META_PATH);
if (metadir == NULL) if (metadir == NULL)
return errno; return errno;

View File

@ -1,4 +1,4 @@
.TH "XBPS\-REPO" "8" "05/02/2011" "\ \&" "\ \&" .TH "XBPS\-REPO" "8" "02/21/2011" "\ \&" "\ \&"
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
.\" * set default formatting .\" * set default formatting
.\" ----------------------------------------------------------------- .\" -----------------------------------------------------------------
@ -24,14 +24,7 @@ The xbps\-repo(8) command is used to handle local or remote binary package repos
Sets the Sets the
\fIcache\fR \fIcache\fR
directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to
\fI/var/cache/xbps\fR \fI/var/cache/xbps\fR\&.
and it\(cqs always relative to the
\fIroot\fR
directory\&. So if you use a
\fIrootdir\fR
of
\fI/blah\fR, it will become
\fI/blah/cachedir\fR\&.
.RE .RE
.PP .PP
\fB\-d\fR \fB\-d\fR

View File

@ -109,7 +109,7 @@ main(int argc, char **argv)
struct xbps_handle xh; struct xbps_handle xh;
struct xbps_fetch_progress_data xfpd; struct xbps_fetch_progress_data xfpd;
prop_dictionary_t dict; prop_dictionary_t dict;
const char *version; const char *version, *rootdir = NULL;
char *plist, *pkgname, *pkgver, *in_chroot_env, *hash; char *plist, *pkgname, *pkgver, *in_chroot_env, *hash;
bool debug = false, in_chroot = false; bool debug = false, in_chroot = false;
int i, c, rv = 0; int i, c, rv = 0;
@ -118,7 +118,7 @@ main(int argc, char **argv)
switch (c) { switch (c) {
case 'r': case 'r':
/* To specify the root directory */ /* To specify the root directory */
xbps_set_rootdir(optarg); rootdir = optarg;
break; break;
case 'd': case 'd':
debug = true; debug = true;
@ -145,9 +145,10 @@ main(int argc, char **argv)
xh.with_debug = debug; xh.with_debug = debug;
xh.xbps_fetch_cb = fetch_file_progress_cb; xh.xbps_fetch_cb = fetch_file_progress_cb;
xh.xfpd = &xfpd; xh.xfpd = &xfpd;
xh.rootdir = rootdir;
xbps_init(&xh); xbps_init(&xh);
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) { if (plist == NULL) {
fprintf(stderr, fprintf(stderr,

View File

@ -133,7 +133,8 @@ void xbps_warn_printf(const char *, ...);
* @brief Generic XBPS structure handler for initialization. * @brief Generic XBPS structure handler for initialization.
* *
* This structure sets some global properties for libxbps, to set some * This structure sets some global properties for libxbps, to set some
* function callbacks and data to the fetch and unpack functions. * function callbacks and data to the fetch and unpack functions,
* the root and cache directory, flags, etc.
*/ */
struct xbps_handle { struct xbps_handle {
/** /**
@ -164,6 +165,28 @@ struct xbps_handle {
* as argument to the \a xbps_fetch_cb function callback. * as argument to the \a xbps_fetch_cb function callback.
*/ */
struct xbps_fetch_progress_data *xfpd; struct xbps_fetch_progress_data *xfpd;
/**
* @var flags
*
* Flags to be set globally, possible values:
* - XBPS_FLAG_VERBOSE
* - XBPS_FLAG_FORCE
*/
int flags;
/**
* @var rootdir
*
* Root directory for all operations in XBPS. If NULL,
* by default it's set to /.
*/
const char *rootdir;
/**
* @var cachedir
*
* Cache directory to store downloaded binary packages.
* If NULL default value in \a XBPS_CACHE_PATH is used.
*/
const char *cachedir;
/** /**
* @var with_debug * @var with_debug
* *
@ -175,9 +198,12 @@ struct xbps_handle {
/** /**
* Initialize the XBPS library with the following steps: * Initialize the XBPS library with the following steps:
* *
* - Sets the function callbacks for fetching and unpacking. * - Set function callbacks for fetching and unpacking.
* - Sets default cache connections for libfetch. * - Set root directory.
* - Initializes the debug printfs. * - Set cache directory.
* - Set global flags.
* - Set default cache connections for libfetch.
* - Initialize the debug printfs.
* *
* @param[in] xh Pointer to an xbps_handle structure. It's * @param[in] xh Pointer to an xbps_handle structure. It's
* assumed that this pointer is not NULL. * assumed that this pointer is not NULL.
@ -189,6 +215,11 @@ void xbps_init(struct xbps_handle *xh);
*/ */
void xbps_end(void); void xbps_end(void);
/**
* Returns a pointer to the xbps_handle structure set by xbps_init().
*/
const struct xbps_handle *xbps_handle_get(void);
/*@}*/ /*@}*/
/** @addtogroup configure */ /** @addtogroup configure */
@ -1193,7 +1224,7 @@ int xbps_unpack_binary_pkg(prop_dictionary_t trans_pkg_dict);
* *
* @return 0 on success, -1 on error and errno set appropiately. * @return 0 on success, -1 on error and errno set appropiately.
*/ */
int xbps_mkpath(char *path, mode_t mode); int xbps_mkpath(const char *path, mode_t mode);
/** /**
* Returns a string by concatenating its variable argument list * Returns a string by concatenating its variable argument list
@ -1363,36 +1394,6 @@ const char *xbps_get_pkg_revision(const char *pkg);
*/ */
bool xbps_pkg_has_rundeps(prop_dictionary_t dict); bool xbps_pkg_has_rundeps(prop_dictionary_t dict);
/**
* Sets the global root directory.
*
* @param[in] path Destination directory.
*/
void xbps_set_rootdir(const char *path);
/**
* Gets the global root directory.
*
* @return A string with full path to the root directory.
*/
const char *xbps_get_rootdir(void);
/**
* Sets globally the cache directory to store downloaded binary
* packages. Any full path without rootdir is valid.
*
* @param[in] cachedir Directory to be set.
*/
void xbps_set_cachedir(const char *cachedir);
/**
* Gets the cache directory currently used to store downloaded
* binary packages.
*
* @return The path to a directory.
*/
const char *xbps_get_cachedir(void);
/** /**
* Converts the 64 bits signed number specified in \a bytes to * Converts the 64 bits signed number specified in \a bytes to
* a human parsable string buffer pointed to \a buf. * a human parsable string buffer pointed to \a buf.
@ -1405,20 +1406,6 @@ const char *xbps_get_cachedir(void);
*/ */
int xbps_humanize_number(char *buf, int64_t bytes); int xbps_humanize_number(char *buf, int64_t bytes);
/**
* Sets the flag specified in \a flags for internal use.
*
* @param[in] flags Flags to be set globally.
*/
void xbps_set_flags(int flags);
/**
* Gets the flags currently set internally.
*
* @return An integer with flags
*/
int xbps_get_flags(void);
/*@}*/ /*@}*/
__END_DECLS __END_DECLS

View File

@ -74,12 +74,6 @@
__BEGIN_DECLS __BEGIN_DECLS
/**
* @private
* From lib/initend.c
*/
const struct xbps_handle HIDDEN *xbps_handle_get(void);
/** /**
* @private * @private
* From lib/download.c * From lib/download.c

View File

@ -37,11 +37,11 @@
* @brief Initialization and finalization routines * @brief Initialization and finalization routines
* @defgroup initend Initialization and finalization functions * @defgroup initend Initialization and finalization functions
* *
* Use these functions to initialize some parameters before starting * Use these functions to initialize some parameters before start
* using libxbps and finalize usage to release resources at the end. * using libxbps and finalize usage to release resources at the end.
*/ */
static bool debug; static bool debug;
static const struct xbps_handle *xhp; static struct xbps_handle *xhp;
void void
xbps_init(struct xbps_handle *xh) xbps_init(struct xbps_handle *xh)
@ -52,6 +52,13 @@ xbps_init(struct xbps_handle *xh)
debug = xhp->with_debug; debug = xhp->with_debug;
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN, xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN,
XBPS_FETCH_CACHECONN_HOST); XBPS_FETCH_CACHECONN_HOST);
/* If rootdir not set, defaults to '/' */
if (xhp->rootdir == NULL)
xhp->rootdir = "/";
/* If cachedir not set, defaults to XBPS_CACHE_PATH */
if (xhp->cachedir == NULL)
xhp->cachedir = XBPS_CACHE_PATH;
} }
void void
@ -63,9 +70,10 @@ xbps_end(void)
xhp = NULL; xhp = NULL;
} }
const struct xbps_handle HIDDEN * const struct xbps_handle *
xbps_handle_get(void) xbps_handle_get(void)
{ {
assert(xhp != NULL);
return xhp; return xhp;
} }

View File

@ -37,15 +37,20 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <xbps_api.h> #include <xbps_api.h>
#include "xbps_api_impl.h"
int int
xbps_mkpath(char *path, mode_t mode) xbps_mkpath(const char *path, mode_t mode)
{ {
struct stat sb; struct stat sb;
char *slash = path; char *ppath, *slash;
int done = 0, rv; int done = 0, rv;
mode_t dir_mode; mode_t dir_mode;
if ((ppath = strdup(path)) == NULL)
return -1;
slash = ppath;
/* /*
* The default file mode is a=rwx (0777) with selected permissions * The default file mode is a=rwx (0777) with selected permissions
* removed in accordance with the file mode creation mask. For * removed in accordance with the file mode creation mask. For
@ -64,7 +69,7 @@ xbps_mkpath(char *path, mode_t mode)
done = (*slash == '\0'); done = (*slash == '\0');
*slash = '\0'; *slash = '\0';
rv = mkdir(path, done ? mode : dir_mode); rv = mkdir(ppath, done ? mode : dir_mode);
if (rv < 0) { if (rv < 0) {
/* /*
* Can't create; path exists or no perms. * Can't create; path exists or no perms.
@ -73,14 +78,16 @@ xbps_mkpath(char *path, mode_t mode)
int sverrno; int sverrno;
sverrno = errno; sverrno = errno;
if (stat(path, &sb) < 0) { if (stat(ppath, &sb) < 0) {
/* Not there; use mkdir()s error */ /* Not there; use mkdir()s error */
errno = sverrno; errno = sverrno;
free(ppath);
return -1; return -1;
} }
if (!S_ISDIR(sb.st_mode)) { if (!S_ISDIR(sb.st_mode)) {
/* Is there, but isn't a directory */ /* Is there, but isn't a directory */
errno = ENOTDIR; errno = ENOTDIR;
free(ppath);
return -1; return -1;
} }
} }
@ -89,6 +96,7 @@ xbps_mkpath(char *path, mode_t mode)
*slash = '/'; *slash = '/';
} }
free(ppath);
return 0; return 0;
} }

View File

@ -43,9 +43,9 @@
* ran successful. * ran successful.
* *
* @note * @note
* If the \a XBPS_FLAG_FORCE is set through xbps_set_flags(), the package * If the \a XBPS_FLAG_FORCE is set through xbps_init() in the flags
* (or packages) will be reconfigured even if its state is * member, the package (or packages) will be reconfigured even if its
* XBPS_PKG_STATE_INSTALLED. * state is XBPS_PKG_STATE_INSTALLED.
*/ */
int int
@ -86,14 +86,16 @@ xbps_configure_pkg(const char *pkgname,
bool check_state, bool check_state,
bool update) bool update)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
const char *lver, *rootdir = xbps_get_rootdir(); const char *lver;
char *buf; char *buf;
int rv = 0, flags = xbps_get_flags(); int rv = 0;
pkg_state_t state = 0; pkg_state_t state = 0;
bool reconfigure = false; bool reconfigure = false;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
if (check_state) { if (check_state) {
rv = xbps_get_pkg_state_installed(pkgname, &state); rv = xbps_get_pkg_state_installed(pkgname, &state);
@ -101,7 +103,7 @@ xbps_configure_pkg(const char *pkgname,
return EINVAL; return EINVAL;
if (state == XBPS_PKG_STATE_INSTALLED) { if (state == XBPS_PKG_STATE_INSTALLED) {
if ((flags & XBPS_FLAG_FORCE) == 0) if ((xhp->flags & XBPS_FLAG_FORCE) == 0)
return 0; return 0;
reconfigure = true; reconfigure = true;
@ -123,9 +125,9 @@ xbps_configure_pkg(const char *pkgname,
if (buf == NULL) if (buf == NULL)
return ENOMEM; return ENOMEM;
if (chdir(rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n", xbps_dbg_printf("%s: [configure] chdir to '%s' returned %s\n",
pkgname, rootdir, strerror(errno)); pkgname, xhp->rootdir, strerror(errno));
free(buf); free(buf);
return EINVAL; return EINVAL;
} }

View File

@ -43,6 +43,7 @@
int int
xbps_property_set(const char *key, const char *pkgname) xbps_property_set(const char *key, const char *pkgname)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t d, repo_pkgd = NULL, pkgd = NULL; prop_dictionary_t d, repo_pkgd = NULL, pkgd = NULL;
prop_array_t props, provides = NULL, virtual = NULL; prop_array_t props, provides = NULL, virtual = NULL;
prop_string_t virtualpkg; prop_string_t virtualpkg;
@ -54,6 +55,7 @@ xbps_property_set(const char *key, const char *pkgname)
assert(pkgname != NULL); assert(pkgname != NULL);
regpkgd_alloc = pkgd_alloc = virtual_alloc = propbool = false; regpkgd_alloc = pkgd_alloc = virtual_alloc = propbool = false;
xhp = xbps_handle_get();
if ((d = xbps_regpkgdb_dictionary_get()) == NULL) { if ((d = xbps_regpkgdb_dictionary_get()) == NULL) {
/* /*
@ -180,7 +182,7 @@ xbps_property_set(const char *key, const char *pkgname)
/* /*
* Write regpkgdb dictionary to plist file. * Write regpkgdb dictionary to plist file.
*/ */
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) { if (plist == NULL) {
rv = ENOMEM; rv = ENOMEM;
@ -205,6 +207,7 @@ out:
int int
xbps_property_unset(const char *key, const char *pkgname) xbps_property_unset(const char *key, const char *pkgname)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t d, pkgd; prop_dictionary_t d, pkgd;
prop_array_t props; prop_array_t props;
char *plist; char *plist;
@ -212,6 +215,7 @@ xbps_property_unset(const char *key, const char *pkgname)
assert(key != NULL); assert(key != NULL);
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
if ((d = xbps_regpkgdb_dictionary_get()) == NULL) if ((d = xbps_regpkgdb_dictionary_get()) == NULL)
return ENODEV; return ENODEV;
@ -252,7 +256,7 @@ xbps_property_unset(const char *key, const char *pkgname)
/* /*
* Write regpkgdb dictionary to plist file. * Write regpkgdb dictionary to plist file.
*/ */
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) { if (plist == NULL) {
rv = ENOMEM; rv = ENOMEM;

View File

@ -48,7 +48,7 @@
*/ */
static int static int
remove_pkg_metadata(const char *pkgname) remove_pkg_metadata(const char *pkgname, const char *rootdir)
{ {
struct dirent *dp; struct dirent *dp;
DIR *dirp; DIR *dirp;
@ -57,7 +57,7 @@ remove_pkg_metadata(const char *pkgname)
assert(pkgname != NULL); assert(pkgname != NULL);
metadir = xbps_xasprintf("%s/%s/metadata/%s", xbps_get_rootdir(), metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir,
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);
if (metadir == NULL) if (metadir == NULL)
return ENOMEM; return ENOMEM;
@ -127,13 +127,15 @@ out:
int int
xbps_purge_pkg(const char *pkgname, bool check_state) xbps_purge_pkg(const char *pkgname, bool check_state)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict, pkgd; prop_dictionary_t dict, pkgd;
const char *version; const char *version;
char *buf; char *buf;
int rv = 0, flags = xbps_get_flags(); int rv = 0;
pkg_state_t state; pkg_state_t state;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
/* /*
* Firstly let's get the pkg dictionary from regpkgdb. * Firstly let's get the pkg dictionary from regpkgdb.
*/ */
@ -171,7 +173,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
/* /*
* Execute the purge action in REMOVE script (if found). * Execute the purge action in REMOVE script (if found).
*/ */
if (chdir(xbps_get_rootdir()) == -1) { if (chdir(xhp->rootdir) == -1) {
rv = errno; rv = errno;
prop_object_release(dict); prop_object_release(dict);
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n", xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n",
@ -205,7 +207,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
/* /*
* Remove metadata dir and unregister package. * Remove metadata dir and unregister package.
*/ */
if ((rv = remove_pkg_metadata(pkgname)) != 0) { if ((rv = remove_pkg_metadata(pkgname, xhp->rootdir)) != 0) {
xbps_error_printf("%s: couldn't remove metadata files: %s\n", xbps_error_printf("%s: couldn't remove metadata files: %s\n",
pkgname, strerror(rv)); pkgname, strerror(rv));
goto out; goto out;
@ -215,7 +217,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
pkgname, strerror(rv)); pkgname, strerror(rv));
goto out; goto out;
} }
if (flags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Package %s purged successfully.\n", pkgname); xbps_printf("Package %s purged successfully.\n", pkgname);
out: out:

View File

@ -43,6 +43,7 @@
int int
xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic) xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict, pkgd; prop_dictionary_t dict, pkgd;
prop_array_t array, provides = NULL; prop_array_t array, provides = NULL;
const char *pkgname, *version, *desc, *pkgver; const char *pkgname, *version, *desc, *pkgver;
@ -50,7 +51,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
int rv = 0; int rv = 0;
bool autoinst = false; bool autoinst = false;
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;
@ -141,12 +143,14 @@ out:
int int
xbps_unregister_pkg(const char *pkgname) xbps_unregister_pkg(const char *pkgname)
{ {
const struct xbps_handle *xhp;
char *plist; char *plist;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;

View File

@ -45,7 +45,7 @@
* will be executed. * will be executed.
* -# Its files, dirs and links will be removed. Modified files (not * -# Its files, dirs and links will be removed. Modified files (not
* matching its sha256 hash) are preserved, unless XBPS_FLAG_FORCE * matching its sha256 hash) are preserved, unless XBPS_FLAG_FORCE
* is set via xbps_set_flags(). * is set via xbps_init() in the flags member.
* -# Its <b>post-remove</b> target specified in the REMOVE script * -# Its <b>post-remove</b> target specified in the REMOVE script
* will be executed. * will be executed.
* -# Its requiredby objects will be removed from the installed packages * -# Its requiredby objects will be removed from the installed packages
@ -74,15 +74,17 @@
int int
xbps_remove_pkg_files(prop_dictionary_t dict, const char *key) xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
{ {
const struct xbps_handle *xhp;
prop_array_t array; prop_array_t array;
prop_object_iterator_t iter; prop_object_iterator_t iter;
prop_object_t obj; prop_object_t obj;
const char *file, *sha256, *curobj = NULL; const char *file, *sha256, *curobj = NULL;
char *path = NULL; char *path = NULL;
int flags = xbps_get_flags(), rv = 0; int rv = 0;
assert(dict != NULL); assert(dict != NULL);
assert(key != NULL); assert(key != NULL);
xhp = xbps_handle_get();
array = prop_dictionary_get(dict, key); array = prop_dictionary_get(dict, key);
if (array == NULL) if (array == NULL)
@ -105,7 +107,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
while ((obj = prop_object_iterator_next(iter))) { while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj, "file", &file); prop_dictionary_get_cstring_nocopy(obj, "file", &file);
path = xbps_xasprintf("%s/%s", xbps_get_rootdir(), file); path = xbps_xasprintf("%s/%s", xhp->rootdir, file);
if (path == NULL) { if (path == NULL) {
rv = ENOMEM; rv = ENOMEM;
break; break;
@ -127,7 +129,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
continue; continue;
} else if (rv == ERANGE) { } else if (rv == ERANGE) {
rv = 0; rv = 0;
if (flags & XBPS_FLAG_FORCE) { if (xhp->flags & XBPS_FLAG_FORCE) {
xbps_warn_printf("'%s': SHA256 " xbps_warn_printf("'%s': SHA256 "
"mismatch, forcing removal...\n", "mismatch, forcing removal...\n",
file); file);
@ -136,7 +138,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
"mismatch, preserving file...\n", "mismatch, preserving file...\n",
file); file);
} }
if ((flags & XBPS_FLAG_FORCE) == 0) { if ((xhp->flags & XBPS_FLAG_FORCE) == 0) {
free(path); free(path);
continue; continue;
} }
@ -151,13 +153,13 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
* Remove the object if possible. * Remove the object if possible.
*/ */
if (remove(path) == -1) { if (remove(path) == -1) {
if (flags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_warn_printf("can't remove %s `%s': %s\n", xbps_warn_printf("can't remove %s `%s': %s\n",
curobj, file, strerror(errno)); curobj, file, strerror(errno));
} else { } else {
/* Success */ /* Success */
if (flags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Removed %s: `%s'\n", curobj, file); xbps_printf("Removed %s: `%s'\n", curobj, file);
} }
free(path); free(path);
@ -170,6 +172,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
int int
xbps_remove_pkg(const char *pkgname, const char *version, bool update) xbps_remove_pkg(const char *pkgname, const char *version, bool update)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict; prop_dictionary_t dict;
char *buf; char *buf;
int rv = 0; int rv = 0;
@ -178,6 +181,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
xhp = xbps_handle_get();
/* /*
* Check if pkg is installed before anything else. * Check if pkg is installed before anything else.
*/ */
@ -189,7 +193,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
if (buf == NULL) if (buf == NULL)
return ENOMEM; return ENOMEM;
if (chdir(xbps_get_rootdir()) == -1) { if (chdir(xhp->rootdir) == -1) {
free(buf); free(buf);
return EINVAL; return EINVAL;
} }

View File

@ -39,6 +39,7 @@
int HIDDEN int HIDDEN
xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd) xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
{ {
const struct xbps_handle *xhp;
prop_object_iterator_t iter, iter2; prop_object_iterator_t iter, iter2;
prop_object_t obj, obj2; prop_object_t obj, obj2;
prop_string_t oldstr, newstr; prop_string_t oldstr, newstr;
@ -46,11 +47,12 @@ xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
const char *array_str = "files"; const char *array_str = "files";
const char *oldhash; const char *oldhash;
char *file; char *file;
int rv = 0, flags = xbps_get_flags(); int rv = 0;
bool found, dodirs = false, dolinks = false; bool found, dodirs = false, dolinks = false;
assert(oldd != NULL); assert(oldd != NULL);
assert(newd != NULL); assert(newd != NULL);
xhp = xbps_handle_get();
again: again:
iter = xbps_get_array_iter_from_dict(oldd, array_str); iter = xbps_get_array_iter_from_dict(oldd, array_str);
@ -135,7 +137,7 @@ again:
free(file); free(file);
continue; continue;
} }
if (flags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Removed obsolete entry: %s\n", xbps_printf("Removed obsolete entry: %s\n",
prop_string_cstring_nocopy(oldstr)); prop_string_cstring_nocopy(oldstr));

View File

@ -103,13 +103,15 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
int HIDDEN int HIDDEN
xbps_requiredby_pkg_remove(const char *pkgname) xbps_requiredby_pkg_remove(const char *pkgname)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict; prop_dictionary_t dict;
char *plist; char *plist;
int rv = 0; int rv = 0;
assert(pkgname != NULL); assert(pkgname != NULL);
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;

View File

@ -141,6 +141,7 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
int int
xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state) xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict = NULL, pkgd; prop_dictionary_t dict = NULL, pkgd;
prop_array_t array; prop_array_t array;
char *plist; char *plist;
@ -148,8 +149,9 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
bool newpkg = false; bool newpkg = false;
assert(pkgname != NULL); assert(pkgname != NULL);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) if (plist == NULL)
return ENOMEM; return ENOMEM;

View File

@ -166,9 +166,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
prop_array_t array; prop_array_t array;
struct archive_entry *entry; struct archive_entry *entry;
size_t nmetadata = 0, entry_idx = 0; size_t nmetadata = 0, entry_idx = 0;
const char *rootdir, *entry_pname, *transact; const char *entry_pname, *transact;
char *buf; char *buf;
int rv, flags, xflags; int rv, flags;
bool preserve, update; bool preserve, update;
assert(ar != NULL); assert(ar != NULL);
@ -177,10 +177,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
assert(version != NULL); assert(version != NULL);
preserve = update = false; preserve = update = false;
rootdir = xbps_get_rootdir();
xflags = xbps_get_flags();
if (chdir(rootdir) == -1) { if (chdir(xhp->rootdir) == -1) {
xbps_error_printf("cannot chdir to rootdir for " xbps_error_printf("cannot chdir to rootdir for "
"`%s-%s': %s\n", pkgname, version, strerror(errno)); "`%s-%s': %s\n", pkgname, version, strerror(errno));
return errno; return errno;
@ -389,7 +387,7 @@ unpack_archive(prop_dictionary_t pkg_repod,
pkgname, version, strerror(rv)); pkgname, version, strerror(rv));
goto out; goto out;
} else { } else {
if (xflags & XBPS_FLAG_VERBOSE) if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_warn_printf("ignoring existing " xbps_warn_printf("ignoring existing "
"entry: %s\n", entry_pname); "entry: %s\n", entry_pname);

View File

@ -186,14 +186,16 @@ xbps_get_array_iter_from_dict(prop_dictionary_t dict, const char *key)
prop_dictionary_t prop_dictionary_t
xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, const char *plist) xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, const char *plist)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t plistd = NULL; prop_dictionary_t plistd = NULL;
char *plistf; char *plistf;
assert(pkgn != NULL); assert(pkgn != NULL);
assert(plist != NULL); assert(plist != NULL);
xhp = xbps_handle_get();
plistf = xbps_xasprintf("%s/%s/metadata/%s/%s", plistf = xbps_xasprintf("%s/%s/metadata/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, pkgn, plist); xhp->rootdir, XBPS_META_PATH, pkgn, plist);
if (plistf == NULL) if (plistf == NULL)
return NULL; return NULL;

View File

@ -66,6 +66,7 @@ static pthread_mutex_t refcnt_mtx = PTHREAD_MUTEX_INITIALIZER;
prop_dictionary_t prop_dictionary_t
xbps_regpkgdb_dictionary_get(void) xbps_regpkgdb_dictionary_get(void)
{ {
const struct xbps_handle *xhp;
char *plist; char *plist;
if (regpkgdb_initialized) { if (regpkgdb_initialized) {
@ -75,7 +76,8 @@ xbps_regpkgdb_dictionary_get(void)
return regpkgdb_dict; return regpkgdb_dict;
} }
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL) if (plist == NULL)
return NULL; return NULL;

View File

@ -55,6 +55,7 @@ static pthread_mutex_t mtx_refcnt = PTHREAD_MUTEX_INITIALIZER;
int int
xbps_repository_pool_init(void) xbps_repository_pool_init(void)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict = NULL; prop_dictionary_t dict = NULL;
prop_array_t array; prop_array_t array;
prop_object_t obj; prop_object_t obj;
@ -64,6 +65,7 @@ xbps_repository_pool_init(void)
char *plist; char *plist;
int rv = 0; int rv = 0;
xhp = xbps_handle_get();
xbps_dbg_printf("%s: repolist_refcnt %zu\n", __func__, repolist_refcnt); xbps_dbg_printf("%s: repolist_refcnt %zu\n", __func__, repolist_refcnt);
if (repolist_initialized) { if (repolist_initialized) {
@ -73,7 +75,7 @@ xbps_repository_pool_init(void)
return 0; return 0;
} }
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST); XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL) { if (plist == NULL) {
rv = errno; rv = errno;

View File

@ -40,6 +40,7 @@
int int
xbps_repository_register(const char *uri) xbps_repository_register(const char *uri)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array; prop_array_t array;
prop_object_t obj = NULL; prop_object_t obj = NULL;
@ -47,8 +48,9 @@ xbps_repository_register(const char *uri)
int rv = 0; int rv = 0;
assert(uri != NULL); assert(uri != NULL);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST); XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL) if (plist == NULL)
return errno; return errno;
@ -120,6 +122,7 @@ out:
int int
xbps_repository_unregister(const char *uri) xbps_repository_unregister(const char *uri)
{ {
const struct xbps_handle *xhp;
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array; prop_array_t array;
const char *pkgindexdir; const char *pkgindexdir;
@ -127,8 +130,9 @@ xbps_repository_unregister(const char *uri)
int rv = 0; int rv = 0;
assert(uri != NULL); assert(uri != NULL);
xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", xbps_get_rootdir(), plist = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REPOLIST); XBPS_META_PATH, XBPS_REPOLIST);
if (plist == NULL) if (plist == NULL)
return errno; return errno;

View File

@ -84,6 +84,7 @@ xbps_get_remote_repo_string(const char *uri)
int int
xbps_repository_sync_pkg_index(const char *uri) xbps_repository_sync_pkg_index(const char *uri)
{ {
const struct xbps_handle *xhp;
struct url *url = NULL; struct url *url = NULL;
struct utsname un; struct utsname un;
struct stat st; struct stat st;
@ -95,6 +96,7 @@ xbps_repository_sync_pkg_index(const char *uri)
assert(uri != NULL); assert(uri != NULL);
tmp_metafile = rpidx = lrepodir = lrepofile = NULL; tmp_metafile = rpidx = lrepodir = lrepofile = NULL;
xhp = xbps_handle_get();
if (uname(&un) == -1) if (uname(&un) == -1)
return -1; return -1;
@ -111,8 +113,7 @@ xbps_repository_sync_pkg_index(const char *uri)
/* /*
* Create metadir if necessary. * Create metadir if necessary.
*/ */
metadir = xbps_xasprintf("%s/%s", xbps_get_rootdir(), metadir = xbps_xasprintf("%s/%s", xhp->rootdir, XBPS_META_PATH);
XBPS_META_PATH);
if (metadir == NULL) { if (metadir == NULL) {
rv = -1; rv = -1;
goto out; goto out;
@ -142,7 +143,7 @@ xbps_repository_sync_pkg_index(const char *uri)
* package index file. * package index file.
*/ */
lrepodir = xbps_xasprintf("%s/%s/%s", lrepodir = xbps_xasprintf("%s/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixedp); xhp->rootdir, XBPS_META_PATH, uri_fixedp);
if (lrepodir == NULL) { if (lrepodir == NULL) {
rv = -1; rv = -1;
goto out; goto out;

View File

@ -51,10 +51,6 @@
* @brief Utility routines * @brief Utility routines
* @defgroup util Utility functions * @defgroup util Utility functions
*/ */
static const char *rootdir;
static const char *cachedir;
static int flags;
static void static void
digest2string(const uint8_t *digest, char *string, size_t len) digest2string(const uint8_t *digest, char *string, size_t len)
{ {
@ -318,16 +314,18 @@ xbps_get_pkgpattern_version(const char *pkg)
static char * static char *
get_pkg_index_remote_plist(const char *uri) get_pkg_index_remote_plist(const char *uri)
{ {
const struct xbps_handle *xhp;
char *uri_fixed, *repodir; char *uri_fixed, *repodir;
assert(uri != NULL); assert(uri != NULL);
xhp = xbps_handle_get();
uri_fixed = xbps_get_remote_repo_string(uri); uri_fixed = xbps_get_remote_repo_string(uri);
if (uri_fixed == NULL) if (uri_fixed == NULL)
return NULL; return NULL;
repodir = xbps_xasprintf("%s/%s/%s/%s", repodir = xbps_xasprintf("%s/%s/%s/%s",
xbps_get_rootdir(), XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX); xhp->rootdir, XBPS_META_PATH, uri_fixed, XBPS_PKGINDEX);
if (repodir == NULL) { if (repodir == NULL) {
free(uri_fixed); free(uri_fixed);
return NULL; return NULL;
@ -356,7 +354,8 @@ xbps_get_pkg_index_plist(const char *uri)
char * char *
xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod, const char *repoloc) xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod, const char *repoloc)
{ {
const char *filen, *arch, *cdir; const struct xbps_handle *xhp;
const char *filen, *arch;
char *lbinpkg = NULL; char *lbinpkg = NULL;
assert(pkg_repod != NULL); assert(pkg_repod != NULL);
@ -369,14 +368,11 @@ xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod, const char *repoloc)
"architecture", &arch)) "architecture", &arch))
return NULL; return NULL;
cdir = xbps_get_cachedir(); xhp = xbps_handle_get();
if (cdir == NULL)
return NULL;
/* /*
* First check if binpkg is available in cachedir. * First check if binpkg is available in cachedir.
*/ */
lbinpkg = xbps_xasprintf("%s/%s", cdir, filen); lbinpkg = xbps_xasprintf("%s/%s", xhp->cachedir, filen);
if (lbinpkg == NULL) if (lbinpkg == NULL)
return NULL; return NULL;
@ -404,68 +400,6 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkg)
return false; return false;
} }
void
xbps_set_rootdir(const char *dir)
{
assert(dir != NULL);
rootdir = dir;
}
const char *
xbps_get_rootdir(void)
{
if (rootdir == NULL)
rootdir = "/";
return rootdir;
}
void
xbps_set_cachedir(const char *dir)
{
static char res[PATH_MAX];
int r = 0;
assert(dir != NULL);
r = snprintf(res, sizeof(res) - 1, "%s/%s", xbps_get_rootdir(), dir);
if (r < 0 || r >= (int)sizeof(res) - 1) {
/* If error or truncated set to default */
cachedir = XBPS_CACHE_PATH;
return;
}
cachedir = res;
}
const char *
xbps_get_cachedir(void)
{
static char res[PATH_MAX];
int r = 0;
if (cachedir == NULL) {
r = snprintf(res, sizeof(res) - 1, "%s/%s",
xbps_get_rootdir(), XBPS_CACHE_PATH);
if (r < 0 || r >= (int)sizeof(res) - 1)
return NULL;
cachedir = res;
}
return cachedir;
}
void
xbps_set_flags(int lflags)
{
flags = lflags;
}
int
xbps_get_flags(void)
{
return flags;
}
#ifdef HAVE_VASPRINTF #ifdef HAVE_VASPRINTF
char * char *
xbps_xasprintf(const char *fmt, ...) xbps_xasprintf(const char *fmt, ...)