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-{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
at the same time the package to be replaced also needs to be updated
in the transaction. A real example:

View File

@ -91,6 +91,7 @@ out:
int
xbps_check_pkg_integrity(const char *pkgname)
{
const struct xbps_handle *xhp;
prop_dictionary_t pkgd, propsd = NULL, filesd = NULL;
prop_array_t array;
prop_object_t obj;
@ -101,6 +102,7 @@ xbps_check_pkg_integrity(const char *pkgname)
bool broken = false, files_broken = false;
assert(pkgname != NULL);
xhp = xbps_handle_get();
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (pkgd == NULL) {
@ -158,8 +160,7 @@ xbps_check_pkg_integrity(const char *pkgname)
}
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) {
prop_object_iterator_release(iter);
rv = errno;
@ -209,8 +210,7 @@ xbps_check_pkg_integrity(const char *pkgname)
}
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) {
prop_object_iterator_release(iter);
rv = ENOMEM;

View File

@ -71,6 +71,7 @@ match_files_by_pattern(prop_dictionary_t pkg_filesd, prop_dictionary_keysym_t ke
int
find_files_in_packages(const char *pattern)
{
const struct xbps_handle *xhp;
prop_dictionary_t pkg_filesd;
prop_array_t files_keys;
DIR *dirp;
@ -79,7 +80,8 @@ find_files_in_packages(const char *pattern)
int rv = 0;
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);
if (path == NULL)
return -1;

View File

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

View File

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

View File

@ -7,7 +7,7 @@
.\" Source: \ \&
.\" Language: English
.\"
.TH "XBPS\-BIN" "8" "02/05/2011" "\ \&" "\ \&"
.TH "XBPS\-BIN" "8" "02/21/2011" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * 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
.RS 4
Sets the cache directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to
\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\&.
\fI/var/cache/xbps\fR\&.
.RE
.PP
\fB\-d\fR

View File

@ -442,9 +442,10 @@ int
main(int argc, char **argv)
{
prop_dictionary_t plistd, confd = NULL;
struct xbps_handle xh;
FILE *f = NULL;
char *outfile = NULL;
const char *conf_file = NULL;
const char *conf_file = NULL, *rootdir = NULL;
int c;
bool revdeps = false;
@ -468,7 +469,7 @@ main(int argc, char **argv)
break;
case 'r':
/* Set different rootdir. */
xbps_set_rootdir(optarg);
rootdir = optarg;
break;
case '?':
default:
@ -482,6 +483,11 @@ main(int argc, char **argv)
if (argc != 1)
usage();
/* Initialize libxbps */
memset(&xh, 0, sizeof(xh));
xh.rootdir = rootdir;
xbps_init(&xh);
/*
* 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_fetch_progress_data xfpd;
prop_dictionary_t pkgd;
char *root;
const char *rootdir, *cachedir;
int c, rv = 0;
bool with_debug = false;
while ((c = getopt(argc, argv, "Vcdr:")) != -1) {
rootdir = cachedir = NULL;
while ((c = getopt(argc, argv, "Vc:dr:")) != -1) {
switch (c) {
case 'c':
xbps_set_cachedir(optarg);
cachedir = optarg;
break;
case 'd':
with_debug = true;
break;
case 'r':
/* To specify the root directory */
root = optarg;
xbps_set_rootdir(root);
rootdir = optarg;
break;
case 'V':
printf("%s\n", XBPS_RELVER);
@ -119,6 +120,8 @@ main(int argc, char **argv)
xh.with_debug = with_debug;
xh.xbps_fetch_cb = fetch_file_progress_cb;
xh.xfpd = &xfpd;
xh.rootdir = rootdir;
xh.cachedir = cachedir;
xbps_init(&xh);
if ((rv = xbps_repository_pool_init()) != 0) {

View File

@ -163,11 +163,13 @@ unregister_repository(const char *uri)
int
register_repository(const char *uri)
{
const struct xbps_handle *xhp;
struct repoinfo *rpi = NULL;
const char *idxstr = NULL;
char *metadir, *plist;
int rv = 0;
xhp = xbps_handle_get();
if ((idxstr = sanitize_url(uri)) == NULL)
return errno;
@ -189,7 +191,7 @@ register_repository(const char *uri)
/*
* Create metadir if necessary.
*/
metadir = xbps_xasprintf("%s/%s", xbps_get_rootdir(),
metadir = xbps_xasprintf("%s/%s", xhp->rootdir,
XBPS_META_PATH);
if (metadir == NULL)
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
.\" -----------------------------------------------------------------
@ -24,14 +24,7 @@ The xbps\-repo(8) command is used to handle local or remote binary package repos
Sets the
\fIcache\fR
directory to store downloaded binary packages from remote repositories\&. By default it\(cqs set to
\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\&.
\fI/var/cache/xbps\fR\&.
.RE
.PP
\fB\-d\fR

View File

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

View File

@ -133,7 +133,8 @@ void xbps_warn_printf(const char *, ...);
* @brief Generic XBPS structure handler for initialization.
*
* 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 {
/**
@ -164,6 +165,28 @@ struct xbps_handle {
* as argument to the \a xbps_fetch_cb function callback.
*/
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
*
@ -175,9 +198,12 @@ struct xbps_handle {
/**
* Initialize the XBPS library with the following steps:
*
* - Sets the function callbacks for fetching and unpacking.
* - Sets default cache connections for libfetch.
* - Initializes the debug printfs.
* - Set function callbacks for fetching and unpacking.
* - Set root directory.
* - 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
* assumed that this pointer is not NULL.
@ -189,6 +215,11 @@ void xbps_init(struct xbps_handle *xh);
*/
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 */
@ -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.
*/
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
@ -1363,36 +1394,6 @@ const char *xbps_get_pkg_revision(const char *pkg);
*/
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
* 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);
/**
* 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

View File

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

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, ...)