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

View File

@@ -37,11 +37,11 @@
* @brief Initialization and finalization routines
* @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.
*/
static bool debug;
static const struct xbps_handle *xhp;
static struct xbps_handle *xhp;
void
xbps_init(struct xbps_handle *xh)
@@ -52,6 +52,13 @@ xbps_init(struct xbps_handle *xh)
debug = xhp->with_debug;
xbps_fetch_set_cache_connection(XBPS_FETCH_CACHECONN,
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
@@ -63,9 +70,10 @@ xbps_end(void)
xhp = NULL;
}
const struct xbps_handle HIDDEN *
const struct xbps_handle *
xbps_handle_get(void)
{
assert(xhp != NULL);
return xhp;
}

View File

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

View File

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

View File

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

View File

@@ -48,7 +48,7 @@
*/
static int
remove_pkg_metadata(const char *pkgname)
remove_pkg_metadata(const char *pkgname, const char *rootdir)
{
struct dirent *dp;
DIR *dirp;
@@ -57,7 +57,7 @@ remove_pkg_metadata(const char *pkgname)
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);
if (metadir == NULL)
return ENOMEM;
@@ -127,13 +127,15 @@ out:
int
xbps_purge_pkg(const char *pkgname, bool check_state)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict, pkgd;
const char *version;
char *buf;
int rv = 0, flags = xbps_get_flags();
int rv = 0;
pkg_state_t state;
assert(pkgname != NULL);
xhp = xbps_handle_get();
/*
* 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).
*/
if (chdir(xbps_get_rootdir()) == -1) {
if (chdir(xhp->rootdir) == -1) {
rv = errno;
prop_object_release(dict);
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.
*/
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",
pkgname, strerror(rv));
goto out;
@@ -215,7 +217,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
pkgname, strerror(rv));
goto out;
}
if (flags & XBPS_FLAG_VERBOSE)
if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Package %s purged successfully.\n", pkgname);
out:

View File

@@ -43,6 +43,7 @@
int
xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict, pkgd;
prop_array_t array, provides = NULL;
const char *pkgname, *version, *desc, *pkgver;
@@ -50,7 +51,8 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool automatic)
int rv = 0;
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);
if (plist == NULL)
return ENOMEM;
@@ -141,12 +143,14 @@ out:
int
xbps_unregister_pkg(const char *pkgname)
{
const struct xbps_handle *xhp;
char *plist;
int rv = 0;
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);
if (plist == NULL)
return ENOMEM;

View File

@@ -45,7 +45,7 @@
* will be executed.
* -# Its files, dirs and links will be removed. Modified files (not
* 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
* will be executed.
* -# Its requiredby objects will be removed from the installed packages
@@ -74,15 +74,17 @@
int
xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
{
const struct xbps_handle *xhp;
prop_array_t array;
prop_object_iterator_t iter;
prop_object_t obj;
const char *file, *sha256, *curobj = NULL;
char *path = NULL;
int flags = xbps_get_flags(), rv = 0;
int rv = 0;
assert(dict != NULL);
assert(key != NULL);
xhp = xbps_handle_get();
array = prop_dictionary_get(dict, key);
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))) {
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) {
rv = ENOMEM;
break;
@@ -127,7 +129,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
continue;
} else if (rv == ERANGE) {
rv = 0;
if (flags & XBPS_FLAG_FORCE) {
if (xhp->flags & XBPS_FLAG_FORCE) {
xbps_warn_printf("'%s': SHA256 "
"mismatch, forcing removal...\n",
file);
@@ -136,7 +138,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
"mismatch, preserving file...\n",
file);
}
if ((flags & XBPS_FLAG_FORCE) == 0) {
if ((xhp->flags & XBPS_FLAG_FORCE) == 0) {
free(path);
continue;
}
@@ -151,13 +153,13 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
* Remove the object if possible.
*/
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",
curobj, file, strerror(errno));
} else {
/* Success */
if (flags & XBPS_FLAG_VERBOSE)
if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Removed %s: `%s'\n", curobj, file);
}
free(path);
@@ -170,6 +172,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict, const char *key)
int
xbps_remove_pkg(const char *pkgname, const char *version, bool update)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
char *buf;
int rv = 0;
@@ -178,6 +181,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
assert(pkgname != NULL);
assert(version != NULL);
xhp = xbps_handle_get();
/*
* 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)
return ENOMEM;
if (chdir(xbps_get_rootdir()) == -1) {
if (chdir(xhp->rootdir) == -1) {
free(buf);
return EINVAL;
}

View File

@@ -39,6 +39,7 @@
int HIDDEN
xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd)
{
const struct xbps_handle *xhp;
prop_object_iterator_t iter, iter2;
prop_object_t obj, obj2;
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 *oldhash;
char *file;
int rv = 0, flags = xbps_get_flags();
int rv = 0;
bool found, dodirs = false, dolinks = false;
assert(oldd != NULL);
assert(newd != NULL);
xhp = xbps_handle_get();
again:
iter = xbps_get_array_iter_from_dict(oldd, array_str);
@@ -135,7 +137,7 @@ again:
free(file);
continue;
}
if (flags & XBPS_FLAG_VERBOSE)
if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_printf("Removed obsolete entry: %s\n",
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
xbps_requiredby_pkg_remove(const char *pkgname)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
char *plist;
int rv = 0;
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);
if (plist == NULL)
return ENOMEM;

View File

@@ -141,6 +141,7 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
int
xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict = NULL, pkgd;
prop_array_t array;
char *plist;
@@ -148,8 +149,9 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
bool newpkg = false;
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);
if (plist == NULL)
return ENOMEM;

View File

@@ -166,9 +166,9 @@ unpack_archive(prop_dictionary_t pkg_repod,
prop_array_t array;
struct archive_entry *entry;
size_t nmetadata = 0, entry_idx = 0;
const char *rootdir, *entry_pname, *transact;
const char *entry_pname, *transact;
char *buf;
int rv, flags, xflags;
int rv, flags;
bool preserve, update;
assert(ar != NULL);
@@ -177,10 +177,8 @@ unpack_archive(prop_dictionary_t pkg_repod,
assert(version != NULL);
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 "
"`%s-%s': %s\n", pkgname, version, strerror(errno));
return errno;
@@ -389,7 +387,7 @@ unpack_archive(prop_dictionary_t pkg_repod,
pkgname, version, strerror(rv));
goto out;
} else {
if (xflags & XBPS_FLAG_VERBOSE)
if (xhp->flags & XBPS_FLAG_VERBOSE)
xbps_warn_printf("ignoring existing "
"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
xbps_get_pkg_dict_from_metadata_plist(const char *pkgn, const char *plist)
{
const struct xbps_handle *xhp;
prop_dictionary_t plistd = NULL;
char *plistf;
assert(pkgn != NULL);
assert(plist != NULL);
xhp = xbps_handle_get();
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)
return NULL;

View File

@@ -66,6 +66,7 @@ static pthread_mutex_t refcnt_mtx = PTHREAD_MUTEX_INITIALIZER;
prop_dictionary_t
xbps_regpkgdb_dictionary_get(void)
{
const struct xbps_handle *xhp;
char *plist;
if (regpkgdb_initialized) {
@@ -75,7 +76,8 @@ xbps_regpkgdb_dictionary_get(void)
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);
if (plist == NULL)
return NULL;

View File

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

View File

@@ -40,6 +40,7 @@
int
xbps_repository_register(const char *uri)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
prop_array_t array;
prop_object_t obj = NULL;
@@ -47,8 +48,9 @@ xbps_repository_register(const char *uri)
int rv = 0;
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);
if (plist == NULL)
return errno;
@@ -120,6 +122,7 @@ out:
int
xbps_repository_unregister(const char *uri)
{
const struct xbps_handle *xhp;
prop_dictionary_t dict;
prop_array_t array;
const char *pkgindexdir;
@@ -127,8 +130,9 @@ xbps_repository_unregister(const char *uri)
int rv = 0;
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);
if (plist == NULL)
return errno;

View File

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

View File

@@ -51,10 +51,6 @@
* @brief Utility routines
* @defgroup util Utility functions
*/
static const char *rootdir;
static const char *cachedir;
static int flags;
static void
digest2string(const uint8_t *digest, char *string, size_t len)
{
@@ -318,16 +314,18 @@ xbps_get_pkgpattern_version(const char *pkg)
static char *
get_pkg_index_remote_plist(const char *uri)
{
const struct xbps_handle *xhp;
char *uri_fixed, *repodir;
assert(uri != NULL);
xhp = xbps_handle_get();
uri_fixed = xbps_get_remote_repo_string(uri);
if (uri_fixed == NULL)
return NULL;
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) {
free(uri_fixed);
return NULL;
@@ -356,7 +354,8 @@ xbps_get_pkg_index_plist(const char *uri)
char *
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;
assert(pkg_repod != NULL);
@@ -369,14 +368,11 @@ xbps_get_binpkg_repo_uri(prop_dictionary_t pkg_repod, const char *repoloc)
"architecture", &arch))
return NULL;
cdir = xbps_get_cachedir();
if (cdir == NULL)
return NULL;
xhp = xbps_handle_get();
/*
* 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)
return NULL;
@@ -404,68 +400,6 @@ xbps_pkg_has_rundeps(prop_dictionary_t pkg)
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
char *
xbps_xasprintf(const char *fmt, ...)