libxbps: require a pointer to xbps_handle in functions that need it.

This removes 2 global vars from lib/initend.c and easier to know
what functions require access to xbps_handle.
This commit is contained in:
Juan RP
2012-06-14 08:22:11 +02:00
parent a3adbcda95
commit 3e9e87fc2a
60 changed files with 1143 additions and 901 deletions

View File

@@ -41,7 +41,8 @@
#include "xbps_api_impl.h"
void HIDDEN
xbps_set_cb_fetch(off_t file_size,
xbps_set_cb_fetch(struct xbps_handle *xhp,
off_t file_size,
off_t file_offset,
off_t file_dloaded,
const char *file_name,
@@ -49,7 +50,6 @@ xbps_set_cb_fetch(off_t file_size,
bool cb_update,
bool cb_end)
{
const struct xbps_handle *xhp = xbps_handle_get();
struct xbps_fetch_cb_data xfcd;
if (xhp->fetch_cb == NULL)
@@ -62,11 +62,12 @@ xbps_set_cb_fetch(off_t file_size,
xfcd.cb_start = cb_start;
xfcd.cb_update = cb_update;
xfcd.cb_end = cb_end;
(*xhp->fetch_cb)(&xfcd, xhp->fetch_cb_data);
(*xhp->fetch_cb)(xhp, &xfcd, xhp->fetch_cb_data);
}
void HIDDEN
xbps_set_cb_state(xbps_state_t state,
xbps_set_cb_state(struct xbps_handle *xhp,
xbps_state_t state,
int err,
const char *pkgname,
const char *version,
@@ -74,7 +75,6 @@ xbps_set_cb_state(xbps_state_t state,
...)
{
struct xbps_state_cb_data xscd;
const struct xbps_handle *xhp = xbps_handle_get();
char *buf = NULL;
va_list va;
int retval;
@@ -95,7 +95,7 @@ xbps_set_cb_state(xbps_state_t state,
else
xscd.desc = buf;
}
(*xhp->state_cb)(&xscd, xhp->fetch_cb_data);
(*xhp->state_cb)(xhp, &xscd, xhp->fetch_cb_data);
if (buf != NULL)
free(buf);
}

View File

@@ -88,12 +88,12 @@ xbps_fetch_error_string(void)
}
int
xbps_fetch_file(const char *uri,
xbps_fetch_file(struct xbps_handle *xhp,
const char *uri,
const char *outputdir,
bool refetch,
const char *flags)
{
struct xbps_handle *xhp;
struct stat st;
struct url *url = NULL;
struct url_stat url_st;
@@ -110,7 +110,6 @@ xbps_fetch_file(const char *uri,
fetchLastErrCode = 0;
xhp = xbps_handle_get();
fetchTimeout = xhp->fetch_timeout;
/*
* Get the filename specified in URI argument.
@@ -196,20 +195,20 @@ xbps_fetch_file(const char *uri,
}
/* debug stuff */
xbps_dbg_printf("st.st_size: %zd\n", (ssize_t)st.st_size);
xbps_dbg_printf("st.st_atime: %s\n", print_time(&st.st_atime));
xbps_dbg_printf("st.st_mtime: %s\n", print_time(&st.st_mtime));
xbps_dbg_printf("url->scheme: %s\n", url->scheme);
xbps_dbg_printf("url->host: %s\n", url->host);
xbps_dbg_printf("url->port: %d\n", url->port);
xbps_dbg_printf("url->doc: %s\n", url->doc);
xbps_dbg_printf("url->offset: %zd\n", (ssize_t)url->offset);
xbps_dbg_printf("url->length: %zu\n", url->length);
xbps_dbg_printf("url->last_modified: %s\n",
xbps_dbg_printf(xhp, "st.st_size: %zd\n", (ssize_t)st.st_size);
xbps_dbg_printf(xhp, "st.st_atime: %s\n", print_time(&st.st_atime));
xbps_dbg_printf(xhp, "st.st_mtime: %s\n", print_time(&st.st_mtime));
xbps_dbg_printf(xhp, "url->scheme: %s\n", url->scheme);
xbps_dbg_printf(xhp, "url->host: %s\n", url->host);
xbps_dbg_printf(xhp, "url->port: %d\n", url->port);
xbps_dbg_printf(xhp, "url->doc: %s\n", url->doc);
xbps_dbg_printf(xhp, "url->offset: %zd\n", (ssize_t)url->offset);
xbps_dbg_printf(xhp, "url->length: %zu\n", url->length);
xbps_dbg_printf(xhp, "url->last_modified: %s\n",
print_time(&url->last_modified));
xbps_dbg_printf("url_stat.size: %zd\n", (ssize_t)url_st.size);
xbps_dbg_printf("url_stat.atime: %s\n", print_time(&url_st.atime));
xbps_dbg_printf("url_stat.mtime: %s\n", print_time(&url_st.mtime));
xbps_dbg_printf(xhp, "url_stat.size: %zd\n", (ssize_t)url_st.size);
xbps_dbg_printf(xhp, "url_stat.atime: %s\n", print_time(&url_st.atime));
xbps_dbg_printf(xhp, "url_stat.mtime: %s\n", print_time(&url_st.mtime));
if (fio == NULL && fetchLastErrCode != FETCH_OK) {
if (!refetch && restart && fetchLastErrCode == FETCH_UNAVAIL) {
@@ -226,7 +225,7 @@ xbps_fetch_file(const char *uri,
goto out;
}
if (url_st.size == -1) {
xbps_dbg_printf("Remote file size is unknown, resume "
xbps_dbg_printf(xhp, "Remote file size is unknown, resume "
"not possible...\n");
restart = false;
} else if (st.st_size > url_st.size) {
@@ -234,7 +233,7 @@ xbps_fetch_file(const char *uri,
* Remove local file if bigger than remote, and refetch the
* whole shit again.
*/
xbps_dbg_printf("Local file %s is greater than remote, "
xbps_dbg_printf(xhp, "Local file %s is greater than remote, "
"removing local file and refetching...\n", filename);
(void)remove(destfile);
} else if (restart && url_st.mtime && url_st.size &&
@@ -259,7 +258,7 @@ xbps_fetch_file(const char *uri,
* and let the user know that the transfer is going to start
* immediately.
*/
xbps_set_cb_fetch(url_st.size, url->offset, url->offset,
xbps_set_cb_fetch(xhp, url_st.size, url->offset, url->offset,
filename, true, false, false);
/*
* Start fetching requested file.
@@ -267,7 +266,7 @@ xbps_fetch_file(const char *uri,
while ((bytes_read = fetchIO_read(fio, buf, sizeof(buf))) > 0) {
bytes_written = write(fd, buf, (size_t)bytes_read);
if (bytes_written != bytes_read) {
xbps_dbg_printf("Couldn't write to %s!\n", destfile);
xbps_dbg_printf(xhp, "Couldn't write to %s!\n", destfile);
rv = -1;
goto out;
}
@@ -276,11 +275,12 @@ xbps_fetch_file(const char *uri,
* Let the fetch progress callback know that
* we are sucking more bytes from it.
*/
xbps_set_cb_fetch(url_st.size, url->offset, url->offset + bytes_dload,
xbps_set_cb_fetch(xhp, url_st.size, url->offset,
url->offset + bytes_dload,
filename, false, true, false);
}
if (bytes_read == -1) {
xbps_dbg_printf("IO error while fetching %s: %s\n", filename,
xbps_dbg_printf(xhp, "IO error while fetching %s: %s\n", filename,
fetchLastErrString);
errno = EIO;
rv = -1;
@@ -294,7 +294,7 @@ xbps_fetch_file(const char *uri,
* Let the fetch progress callback know that the file
* has been fetched.
*/
xbps_set_cb_fetch(url_st.size, url->offset, bytes_dload,
xbps_set_cb_fetch(xhp, url_st.size, url->offset, bytes_dload,
filename, false, false, true);
/*
* Update mtime in local file to match remote file if transfer

19
lib/external/dewey.c vendored
View File

@@ -137,19 +137,12 @@ mkcomponent(arr_t *ap, const char *num)
if (ap->c == ap->size) {
if (ap->size == 0) {
ap->size = 62;
if ((ap->v = malloc(ap->size * sizeof(int))) == NULL) {
xbps_dbg_printf("%s: malloc ENOMEM\n",
__func__);
exit(EXIT_FAILURE);
}
ap->v = malloc(ap->size * sizeof(int));
assert(ap->v != NULL);
} else {
ap->size *= 2;
ap->v = realloc(ap->v, ap->size * sizeof(int));
if (ap->v == NULL) {
xbps_dbg_printf("%s: realloc ENOMEM\n",
__func__);
exit(EXIT_FAILURE);
}
assert(ap->v != NULL);
}
}
if (isdigit((unsigned char)*num)) {
@@ -177,10 +170,8 @@ mkcomponent(arr_t *ap, const char *num)
cp = strchr(alphas, tolower((unsigned char)*num));
if (ap->c == ap->size) {
ap->size *= 2;
if ((ap->v = realloc(ap->v, ap->size * sizeof(int))) == NULL) {
xbps_dbg_printf("%s: ENOMEM!\n", __func__);
exit(EXIT_FAILURE);
}
ap->v = realloc(ap->v, ap->size * sizeof(int));
assert(ap->v != NULL);
}
ap->v[ap->c++] = (int)(cp - alphas) + 1;
return 1;

12
lib/external/fexec.c vendored
View File

@@ -38,9 +38,8 @@
#include "xbps_api_impl.h"
static int
pfcexec(const char *file, const char **argv)
pfcexec(struct xbps_handle *xhp, const char *file, const char **argv)
{
struct xbps_handle *xhp;
pid_t child;
int status;
@@ -53,7 +52,6 @@ pfcexec(const char *file, const char **argv)
*
* It's assumed that cwd is the target rootdir.
*/
xhp = xbps_handle_get();
if (strcmp(xhp->rootdir, "/")) {
if (getuid() == 0 && access("bin/sh", X_OK) == 0) {
if (chroot(xhp->rootdir) == -1)
@@ -81,7 +79,7 @@ pfcexec(const char *file, const char **argv)
}
static int
vfcexec(const char *arg, va_list ap)
vfcexec(struct xbps_handle *xhp, const char *arg, va_list ap)
{
const char **argv;
size_t argv_size, argc;
@@ -111,20 +109,20 @@ vfcexec(const char *arg, va_list ap)
} while (arg != NULL);
retval = pfcexec(argv[0], argv);
retval = pfcexec(xhp, argv[0], argv);
free(argv);
return retval;
}
int HIDDEN
xbps_file_exec(const char *arg, ...)
xbps_file_exec(struct xbps_handle *xhp, const char *arg, ...)
{
va_list ap;
int result;
va_start(ap, arg);
result = vfcexec(arg, ap);
result = vfcexec(xhp, arg, ap);
va_end(ap);
return result;

View File

@@ -39,9 +39,7 @@
* Use these functions to initialize some parameters before start
* using libxbps and finalize usage to release resources at the end.
*/
static bool debug;
static bool xbps_initialized;
static struct xbps_handle *xhp;
static char *
set_cachedir(struct xbps_handle *xh)
@@ -89,7 +87,7 @@ cb_validate_virtual(cfg_t *cfg, cfg_opt_t *opt)
}
int
xbps_init(struct xbps_handle *xh)
xbps_init(struct xbps_handle *xhp)
{
cfg_opt_t vpkg_opts[] = {
CFG_STR_LIST(__UNCONST("targets"), NULL, CFGF_NONE),
@@ -119,11 +117,7 @@ xbps_init(struct xbps_handle *xh)
int rv, cc, cch;
bool syslog_enabled = false;
assert(xh != NULL);
xhp = xh;
if (xhp->flags & XBPS_FLAG_DEBUG)
debug = true;
assert(xhp != NULL);
if (xhp->conffile == NULL)
xhp->conffile = XBPS_CONF_DEF;
@@ -150,7 +144,7 @@ xbps_init(struct xbps_handle *xh)
return ENOTSUP;
}
}
xbps_dbg_printf("Configuration file: %s\n",
xbps_dbg_printf(xhp, "Configuration file: %s\n",
xhp->conffile ? xhp->conffile : "not found");
/*
* Respect client setting in struct xbps_handle for {root,cache}dir;
@@ -196,14 +190,14 @@ xbps_init(struct xbps_handle *xh)
xbps_fetch_set_cache_connection(cc, cch);
xbps_dbg_printf("Rootdir=%s\n", xhp->rootdir);
xbps_dbg_printf("Metadir=%s\n", xhp->metadir);
xbps_dbg_printf("Cachedir=%s\n", xhp->cachedir);
xbps_dbg_printf("FetchTimeout=%u\n", xhp->fetch_timeout);
xbps_dbg_printf("FetchCacheconn=%u\n", cc);
xbps_dbg_printf("FetchCacheconnHost=%u\n", cch);
xbps_dbg_printf("Syslog=%u\n", syslog_enabled);
xbps_dbg_printf("TransactionFrequencyFlush=%u\n",
xbps_dbg_printf(xhp, "Rootdir=%s\n", xhp->rootdir);
xbps_dbg_printf(xhp, "Metadir=%s\n", xhp->metadir);
xbps_dbg_printf(xhp, "Cachedir=%s\n", xhp->cachedir);
xbps_dbg_printf(xhp, "FetchTimeout=%u\n", xhp->fetch_timeout);
xbps_dbg_printf(xhp, "FetchCacheconn=%u\n", cc);
xbps_dbg_printf(xhp, "FetchCacheconnHost=%u\n", cch);
xbps_dbg_printf(xhp, "Syslog=%u\n", syslog_enabled);
xbps_dbg_printf(xhp, "TransactionFrequencyFlush=%u\n",
xhp->transaction_frequency_flush);
xbps_initialized = true;
@@ -212,7 +206,7 @@ xbps_init(struct xbps_handle *xh)
}
void
xbps_end(void)
xbps_end(struct xbps_handle *xhp)
{
if (!xbps_initialized)
return;
@@ -232,12 +226,6 @@ xbps_end(void)
xbps_initialized = false;
}
struct xbps_handle *
xbps_handle_get(void)
{
return xhp;
}
static void
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
{
@@ -248,11 +236,11 @@ common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
}
void
xbps_dbg_printf_append(const char *fmt, ...)
xbps_dbg_printf_append(struct xbps_handle *xhp, const char *fmt, ...)
{
va_list ap;
if (!debug)
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
return;
va_start(ap, fmt);
@@ -261,11 +249,11 @@ xbps_dbg_printf_append(const char *fmt, ...)
}
void
xbps_dbg_printf(const char *fmt, ...)
xbps_dbg_printf(struct xbps_handle *xhp, const char *fmt, ...)
{
va_list ap;
if (!debug)
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
return;
va_start(ap, fmt);

View File

@@ -76,7 +76,8 @@ out:
* Returns 1 if entry should be installed, 0 if don't or -1 on error.
*/
int HIDDEN
xbps_entry_install_conf_file(prop_dictionary_t filesd,
xbps_entry_install_conf_file(struct xbps_handle *xhp,
prop_dictionary_t filesd,
struct archive_entry *entry,
const char *entry_pname,
const char *pkgname,
@@ -103,12 +104,12 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
* Get original hash for the file from current
* installed package.
*/
xbps_dbg_printf("%s: processing conf_file %s\n",
xbps_dbg_printf(xhp, "%s: processing conf_file %s\n",
pkgname, entry_pname);
forigd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
forigd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (forigd == NULL) {
xbps_dbg_printf("%s: conf_file %s not currently installed\n",
xbps_dbg_printf(xhp, "%s: conf_file %s not currently installed\n",
pkgname, entry_pname);
rv = 1;
goto out;
@@ -141,7 +142,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
* First case: original hash not found, install new file.
*/
if (sha256_orig == NULL) {
xbps_dbg_printf("%s: conf_file %s unknown orig sha256\n",
xbps_dbg_printf(xhp, "%s: conf_file %s unknown orig sha256\n",
pkgname, entry_pname);
rv = 1;
goto out;
@@ -170,7 +171,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
/*
* File not installed, install new one.
*/
xbps_dbg_printf("%s: conf_file %s not "
xbps_dbg_printf(xhp, "%s: conf_file %s not "
"installed\n", pkgname, entry_pname);
rv = 1;
break;
@@ -187,7 +188,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
if ((strcmp(sha256_orig, sha256_cur) == 0) &&
(strcmp(sha256_orig, sha256_new) == 0) &&
(strcmp(sha256_cur, sha256_new) == 0)) {
xbps_dbg_printf("%s: conf_file %s orig = X,"
xbps_dbg_printf(xhp, "%s: conf_file %s orig = X,"
"cur = X, new = X\n", pkgname, entry_pname);
rv = 1;
break;
@@ -199,7 +200,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_orig, sha256_cur) == 0) &&
(strcmp(sha256_orig, sha256_new)) &&
(strcmp(sha256_cur, sha256_new))) {
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version,
"Updating configuration file `%s' provided "
"by version `%s'.", cffile, version);
@@ -212,7 +213,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_orig, sha256_new) == 0) &&
(strcmp(sha256_cur, sha256_new)) &&
(strcmp(sha256_orig, sha256_cur))) {
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version,
"Keeping modified configuration file `%s'.",
cffile);
@@ -225,7 +226,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
} else if ((strcmp(sha256_cur, sha256_new) == 0) &&
(strcmp(sha256_orig, sha256_new)) &&
(strcmp(sha256_orig, sha256_cur))) {
xbps_dbg_printf("%s: conf_file %s orig = X,"
xbps_dbg_printf(xhp, "%s: conf_file %s orig = X,"
"cur = Y, new = Y\n", pkgname, entry_pname);
rv = 0;
break;
@@ -242,7 +243,7 @@ xbps_entry_install_conf_file(prop_dictionary_t filesd,
rv = -1;
break;
}
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
0, pkgname, version,
"Installing new configuration file to "
"`%s.new-%s'.", cffile, version);
@@ -261,7 +262,7 @@ out:
prop_object_iterator_release(iter);
xbps_dbg_printf("%s: conf_file %s returned %d\n",
xbps_dbg_printf(xhp, "%s: conf_file %s returned %d\n",
pkgname, entry_pname, rv);
return rv;

View File

@@ -47,9 +47,8 @@
* state is XBPS_PKG_STATE_INSTALLED.
*/
int
xbps_configure_packages(bool flush)
xbps_configure_packages(struct xbps_handle *xhp, bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_object_t obj;
const char *pkgname;
size_t i;
@@ -61,23 +60,23 @@ xbps_configure_packages(bool flush)
for (i = 0; i < prop_array_count(xhp->pkgdb); i++) {
obj = prop_array_get(xhp->pkgdb, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
rv = xbps_configure_pkg(pkgname, true, false, false);
rv = xbps_configure_pkg(xhp, pkgname, true, false, false);
if (rv != 0)
break;
}
if (flush)
rv = xbps_pkgdb_update(true);
rv = xbps_pkgdb_update(xhp, true);
return rv;
}
int
xbps_configure_pkg(const char *pkgname,
xbps_configure_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool check_state,
bool update,
bool flush)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd;
const char *version, *pkgver;
char *buf;
@@ -85,9 +84,8 @@ xbps_configure_pkg(const char *pkgname,
pkg_state_t state = 0;
assert(pkgname != NULL);
xhp = xbps_handle_get();
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL)
return ENOENT;
@@ -96,9 +94,9 @@ xbps_configure_pkg(const char *pkgname,
if (check_state) {
rv = xbps_pkg_state_dictionary(pkgd, &state);
xbps_dbg_printf("%s: state %d rv %d\n", pkgname, state, rv);
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgname, state, rv);
if (rv != 0) {
xbps_dbg_printf("%s: [configure] failed to get "
xbps_dbg_printf(xhp, "%s: [configure] failed to get "
"pkg state: %s\n", pkgname, strerror(rv));
prop_object_release(pkgd);
return EINVAL;
@@ -115,7 +113,7 @@ xbps_configure_pkg(const char *pkgname,
}
}
prop_object_release(pkgd);
xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
XBPS_META_PATH, pkgname);
@@ -123,8 +121,8 @@ xbps_configure_pkg(const char *pkgname,
return ENOMEM;
if (chdir(xhp->rootdir) == -1) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
pkgname, version,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(errno));
free(buf);
@@ -132,11 +130,11 @@ xbps_configure_pkg(const char *pkgname,
}
if (access(buf, X_OK) == 0) {
if (xbps_file_exec(buf, "post",
if (xbps_file_exec(xhp, buf, "post",
pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL) != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
pkgname, version,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] INSTALL script failed to execute "
"the post ACTION: %s", pkgver, strerror(errno));
free(buf);
@@ -144,8 +142,8 @@ xbps_configure_pkg(const char *pkgname,
}
} else {
if (errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, errno,
pkgname, version,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
errno, pkgname, version,
"%s: [configure] INSTALL script cannot be "
"executed: %s", pkgver, strerror(errno));
free(buf);
@@ -153,17 +151,17 @@ xbps_configure_pkg(const char *pkgname,
}
}
free(buf);
rv = xbps_set_pkg_state_installed(pkgname, version,
rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_INSTALLED);
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv,
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
pkgname, version,
"%s: [configure] failed to set state to installed: %s",
pkgver, strerror(rv));
}
if (flush) {
if ((rv = xbps_pkgdb_update(true)) != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv,
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
pkgname, version,
"%s: [configure] failed to update pkgdb: %s\n",
pkgver, strerror(rv));

View File

@@ -52,7 +52,7 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
/*
* Check if current pkg conflicts with an installed package.
*/
if ((pkgd = xbps_pkgdb_get_pkgd(cfpkg, true))) {
if ((pkgd = xbps_pkgdb_get_pkgd(xhp, cfpkg, true))) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
buf = xbps_xasprintf("%s conflicts with "

View File

@@ -65,7 +65,10 @@ struct orphan_data {
};
static int
find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
find_orphan_pkg(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
struct orphan_data *od = arg;
prop_array_t reqby;
@@ -79,6 +82,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
int rv = 0;
pkg_state_t state;
(void)xhp;
(void)loop_done;
/*
* Skip packages that were not installed automatically.
@@ -164,7 +168,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
}
prop_array_t
xbps_find_pkg_orphans(prop_array_t orphans_user)
xbps_find_pkg_orphans(struct xbps_handle *xhp, prop_array_t orphans_user)
{
prop_array_t array = NULL;
struct orphan_data od;
@@ -180,7 +184,7 @@ xbps_find_pkg_orphans(prop_array_t orphans_user)
* order in which packages were installed.
*/
od.orphans_user = orphans_user;
rv = xbps_pkgdb_foreach_reverse_cb(find_orphan_pkg, &od);
rv = xbps_pkgdb_foreach_reverse_cb(xhp, find_orphan_pkg, &od);
if (rv != 0) {
errno = rv;
prop_object_release(od.array);

View File

@@ -40,9 +40,8 @@
*/
int
xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd = NULL;
prop_array_t provides, reqby;
const char *pkgname, *version, *desc, *pkgver;
@@ -51,8 +50,6 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
xhp = xbps_handle_get();
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgrd, "version", &version);
prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc);
@@ -61,38 +58,42 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
provides = prop_dictionary_get(pkgrd, "provides");
reqby = prop_dictionary_get(pkgrd, "requiredby");
xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
assert(pkgname != NULL);
assert(version != NULL);
assert(desc != NULL);
assert(pkgver != NULL);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) {
rv = ENOENT;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version)) {
xbps_dbg_printf("%s: invalid version for %s\n", __func__, pkgname);
xbps_dbg_printf(xhp, "%s: invalid version for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgver", pkgver)) {
xbps_dbg_printf("%s: invalid pkgver for %s\n", __func__, pkgname);
xbps_dbg_printf(xhp, "%s: invalid pkgver for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"short_desc", desc)) {
xbps_dbg_printf("%s: invalid short_desc for %s\n", __func__, pkgname);
xbps_dbg_printf(xhp, "%s: invalid short_desc for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
if (reqby && !prop_dictionary_set(pkgd, "requiredby", reqby)) {
xbps_dbg_printf("%s: invalid requiredby for %s\n", __func__, pkgname);
xbps_dbg_printf(xhp, "%s: invalid requiredby for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
@@ -104,13 +105,15 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
if (!prop_dictionary_set_bool(pkgd,
"automatic-install", autoinst)) {
xbps_dbg_printf("%s: invalid autoinst for %s\n", __func__, pkgname);
xbps_dbg_printf(xhp, "%s: invalid autoinst for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
if (provides) {
if (!prop_dictionary_set(pkgd, "provides", provides)) {
xbps_dbg_printf("%s: invalid provides for %s\n",
xbps_dbg_printf(xhp,
"%s: invalid provides for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
@@ -121,13 +124,15 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
*/
if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) {
if ((rv = xbps_requiredby_pkg_add(xhp, pkgrd)) != 0) {
xbps_dbg_printf("%s: requiredby add failed for %s\n",
xbps_dbg_printf(xhp,
"%s: requiredby add failed for %s\n",
__func__, pkgname);
goto out;
}
}
if (!xbps_pkgdb_replace_pkgd(pkgd, pkgname, false, flush)) {
xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n",
if (!xbps_pkgdb_replace_pkgd(xhp, pkgd, pkgname, false, flush)) {
xbps_dbg_printf(xhp,
"%s: failed to replace pkgd dict for %s\n",
__func__, pkgname);
goto out;
}
@@ -136,7 +141,7 @@ out:
prop_object_release(pkgd);
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REGISTER_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
rv, pkgname, version,
"%s: failed to register package: %s",
pkgver, strerror(rv));
@@ -146,14 +151,17 @@ out:
}
int
xbps_unregister_pkg(const char *pkgname, const char *version, bool flush)
xbps_unregister_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool flush)
{
assert(pkgname != NULL);
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
if (!xbps_pkgdb_remove_pkgd(pkgname, false, flush)) {
xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL,
if (!xbps_pkgdb_remove_pkgd(xhp, pkgname, false, flush)) {
xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER_FAIL,
errno, pkgname, version,
"%s: failed to unregister package: %s",
pkgname, strerror(errno));

View File

@@ -74,10 +74,10 @@
* data type is specified on its edge, i.e string, array, integer, dictionary.
*/
static int
remove_pkg_metadata(const char *pkgname,
remove_pkg_metadata(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
const char *pkgver,
const char *rootdir)
const char *pkgver)
{
struct dirent *dp;
DIR *dirp;
@@ -85,9 +85,8 @@ remove_pkg_metadata(const char *pkgname,
int rv = 0;
assert(pkgname != NULL);
assert(rootdir != NULL);
metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir,
metadir = xbps_xasprintf("%s/%s/metadata/%s", xhp->rootdir,
XBPS_META_PATH, pkgname);
if (metadir == NULL)
return ENOMEM;
@@ -111,7 +110,7 @@ remove_pkg_metadata(const char *pkgname,
}
if (unlink(path) == -1) {
xbps_set_cb_state(XBPS_STATE_PURGE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_PURGE_FAIL,
errno, pkgname, version,
"%s: [purge] failed to remove metafile `%s': %s",
pkgver, path, strerror(errno));
@@ -128,11 +127,11 @@ remove_pkg_metadata(const char *pkgname,
}
int
xbps_remove_pkg_files(prop_dictionary_t dict,
xbps_remove_pkg_files(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key,
const char *pkgver)
{
struct xbps_handle *xhp;
struct stat st;
prop_array_t array;
prop_object_iterator_t iter;
@@ -144,7 +143,6 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
xhp = xbps_handle_get();
array = prop_dictionary_get(dict, key);
if ((prop_object_type(array) != PROP_TYPE_ARRAY) ||
@@ -186,7 +184,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
rv = xbps_file_hash_check(path, sha256);
if (rv == ENOENT) {
/* missing file, ignore it */
xbps_set_cb_state(
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
rv, pkgname, version,
"%s: failed to check hash for %s `%s': %s",
@@ -198,7 +196,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
rv = 0;
if ((xhp->flags &
XBPS_FLAG_FORCE_REMOVE_FILES) == 0) {
xbps_set_cb_state(
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
0, pkgname, version,
"%s: %s `%s' SHA256 mismatch, "
@@ -207,7 +205,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
free(path);
continue;
} else {
xbps_set_cb_state(
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
0, pkgname, version,
"%s: %s `%s' SHA256 mismatch, "
@@ -215,7 +213,7 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
curobj, file);
}
} else if (rv != 0 && rv != ERANGE) {
xbps_set_cb_state(
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
rv, pkgname, version,
"%s: [remove] failed to check hash for "
@@ -245,14 +243,14 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
* Remove the object if possible.
*/
if (remove(path) == -1) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
errno, pkgname, version,
"%s: failed to remove %s `%s': %s", pkgver,
curobj, file, strerror(errno));
errno = 0;
} else {
/* success */
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
0, pkgname, version,
"Removed %s `%s'", curobj, file);
}
@@ -266,10 +264,12 @@ xbps_remove_pkg_files(prop_dictionary_t dict,
}
int
xbps_remove_pkg(const char *pkgname, const char *version, bool update,
xbps_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
bool update,
bool soft_replace)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd = NULL;
char *buf = NULL, *pkgver = NULL;
int rv = 0;
@@ -279,8 +279,6 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
assert(pkgname != NULL);
assert(version != NULL);
xhp = xbps_handle_get();
buf = xbps_xasprintf("%s/metadata/%s/REMOVE",
XBPS_META_PATH, pkgname);
if (buf == NULL) {
@@ -294,15 +292,15 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
goto out;
}
if ((rv = xbps_pkg_state_installed(pkgname, &state)) != 0)
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0)
goto out;
if (!update)
xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
if (chdir(xhp->rootdir) == -1) {
rv = errno;
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(rv));
@@ -316,9 +314,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
*/
if (access(buf, X_OK) == 0) {
rmfile_exists = true;
if (xbps_file_exec(buf, "pre", pkgname, version,
if (xbps_file_exec(xhp, buf, "pre", pkgname, version,
update ? "yes" : "no", xhp->conffile, NULL) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgname, version,
"%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s",
@@ -328,7 +326,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
}
} else {
if (errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
errno, pkgname, version,
"%s: [remove] REMOVE script failed to "
"execute pre ACTION: %s",
@@ -345,7 +343,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
if (update) {
free(pkgver);
free(buf);
return xbps_requiredby_pkg_remove(pkgname);
return xbps_requiredby_pkg_remove(xhp, pkgname);
} else if (soft_replace) {
/*
* Soft replace a package. Do not remove its files, but
@@ -355,19 +353,19 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
goto softreplace;
}
pkgd = xbps_dictionary_from_metadata_plist(pkgname, XBPS_PKGFILES);
pkgd = xbps_dictionary_from_metadata_plist(xhp, pkgname, XBPS_PKGFILES);
if (pkgd) {
/* Remove regular files */
if ((rv = xbps_remove_pkg_files(pkgd, "files", pkgver)) != 0)
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0)
goto out;
/* Remove configuration files */
if ((rv = xbps_remove_pkg_files(pkgd, "conf_files", pkgver)) != 0)
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "conf_files", pkgver)) != 0)
goto out;
/* Remove links */
if ((rv = xbps_remove_pkg_files(pkgd, "links", pkgver)) != 0)
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "links", pkgver)) != 0)
goto out;
/* Remove dirs */
if ((rv = xbps_remove_pkg_files(pkgd, "dirs", pkgver)) != 0)
if ((rv = xbps_remove_pkg_files(xhp, pkgd, "dirs", pkgver)) != 0)
goto out;
}
/*
@@ -375,9 +373,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
* updating the package.
*/
if (rmfile_exists &&
((rv = xbps_file_exec(buf, "post", pkgname, version, "no",
((rv = xbps_file_exec(xhp, buf, "post", pkgname, version, "no",
xhp->conffile, NULL)) != 0)) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] REMOVE script failed to execute "
"post ACTION: %s", pkgver, strerror(rv));
@@ -386,8 +384,8 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update,
/*
* Update the requiredby array of all required dependencies.
*/
if ((rv = xbps_requiredby_pkg_remove(pkgname)) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
if ((rv = xbps_requiredby_pkg_remove(xhp, pkgname)) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] failed to remove requiredby entries: %s",
pkgver, strerror(rv));
@@ -398,10 +396,10 @@ softreplace:
/*
* Set package state to "half-removed".
*/
rv = xbps_set_pkg_state_installed(pkgname, version,
rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_HALF_REMOVED);
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: [remove] failed to set state to half-removed: %s",
pkgver, strerror(rv));
@@ -413,9 +411,9 @@ purge:
* Execute the purge REMOVE action if file exists.
*/
if (access(buf, X_OK) == 0) {
if ((rv = xbps_file_exec(buf, "purge", pkgname, version, "no",
if ((rv = xbps_file_exec(xhp, buf, "purge", pkgname, version, "no",
xhp->conffile, NULL)) != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: REMOVE script failed to execute "
"purge ACTION: %s", pkgver, strerror(rv));
@@ -425,9 +423,9 @@ purge:
/*
* Remove package metadata directory.
*/
rv = remove_pkg_metadata(pkgname, version, pkgver, xhp->rootdir);
rv = remove_pkg_metadata(xhp, pkgname, version, pkgver);
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
rv, pkgname, version,
"%s: failed to remove metadata files: %s",
pkgver, strerror(rv));
@@ -437,10 +435,10 @@ purge:
/*
* Unregister package from pkgdb.
*/
if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0)
if ((rv = xbps_unregister_pkg(xhp, pkgname, version, false)) != 0)
goto out;
xbps_set_cb_state(XBPS_STATE_REMOVE_DONE,
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE,
0, pkgname, version, NULL);
out:

View File

@@ -36,7 +36,8 @@
#include "xbps_api_impl.h"
int HIDDEN
xbps_remove_obsoletes(const char *pkgname,
xbps_remove_obsoletes(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
const char *pkgver,
prop_dictionary_t oldd,
@@ -131,14 +132,16 @@ again:
* Obsolete obj found, remove it.
*/
if (remove(file) == -1) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
errno, pkgname, version,
"%s: failed to remove obsolete entry `%s': %s",
pkgver, file, strerror(errno));
free(file);
continue;
}
xbps_set_cb_state(XBPS_STATE_REMOVE_FILE_OBSOLETE,
xbps_set_cb_state(xhp,
XBPS_STATE_REMOVE_FILE_OBSOLETE,
0, pkgname, version,
"Removed obsolete entry: %s", file);
free(file);

View File

@@ -32,7 +32,9 @@
#include "xbps_api_impl.h"
static int
add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
add_pkg_into_reqby(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkgver)
{
prop_array_t reqby;
prop_string_t reqstr;
@@ -57,7 +59,7 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
if (xbps_match_pkgname_in_array(reqby, pkgname)) {
if (!xbps_remove_pkgname_from_array(reqby, pkgname)) {
xbps_dbg_printf("%s: failed to remove %s reqby entry: "
xbps_dbg_printf(xhp, "%s: failed to remove %s reqby entry: "
"%s\n", __func__, pkgname, strerror(errno));
free(pkgname);
return EINVAL;
@@ -95,11 +97,15 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
}
static int
remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
remove_pkg_from_reqby(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
prop_array_t reqby;
const char *pkgname = arg;
(void)xhp;
(void)loop_done;
reqby = prop_dictionary_get(obj, "requiredby");
@@ -115,10 +121,10 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
}
int HIDDEN
xbps_requiredby_pkg_remove(const char *pkgname)
xbps_requiredby_pkg_remove(struct xbps_handle *xhp, const char *pkgname)
{
assert(pkgname != NULL);
return xbps_pkgdb_foreach_cb(remove_pkg_from_reqby, __UNCONST(pkgname));
return xbps_pkgdb_foreach_cb(xhp, remove_pkg_from_reqby, __UNCONST(pkgname));
}
int HIDDEN
@@ -147,10 +153,11 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
rv = EINVAL;
break;
}
xbps_dbg_printf("%s: adding reqby entry for %s\n", __func__, str);
xbps_dbg_printf(xhp, "%s: adding reqby entry for %s\n",
__func__, str);
pkgd_pkgdb = xbps_find_virtualpkg_conf_in_array_by_pattern(
xhp->pkgdb, str);
xhp, xhp->pkgdb, str);
if (pkgd_pkgdb == NULL) {
pkgd_pkgdb =
xbps_find_virtualpkg_in_array_by_pattern(
@@ -160,13 +167,14 @@ xbps_requiredby_pkg_add(struct xbps_handle *xhp, prop_dictionary_t pkgd)
xhp->pkgdb, str, NULL);
if (pkgd_pkgdb == NULL) {
rv = ENOENT;
xbps_dbg_printf("%s: couldnt find `%s' "
xbps_dbg_printf(xhp,
"%s: couldnt find `%s' "
"entry in pkgdb\n", __func__, str);
break;
}
}
}
rv = add_pkg_into_reqby(pkgd_pkgdb, pkgver);
rv = add_pkg_into_reqby(xhp, pkgd_pkgdb, pkgver);
if (rv != 0)
break;
}

View File

@@ -93,14 +93,16 @@ get_state(prop_dictionary_t dict)
}
int
xbps_pkg_state_installed(const char *pkgname, pkg_state_t *state)
xbps_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
pkg_state_t *state)
{
prop_dictionary_t pkgd;
assert(pkgname != NULL);
assert(state != NULL);
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL)
return ENOENT;
@@ -156,17 +158,16 @@ set_pkg_objs(prop_dictionary_t pkgd, const char *name, const char *version)
}
int
xbps_set_pkg_state_installed(const char *pkgname,
xbps_set_pkg_state_installed(struct xbps_handle *xhp,
const char *pkgname,
const char *version,
pkg_state_t state)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd;
bool newpkg = false;
int rv;
assert(pkgname != NULL);
xhp = xbps_handle_get();
if (xhp->pkgdb == NULL) {
xhp->pkgdb = prop_array_create();
@@ -198,7 +199,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
return EINVAL;
}
} else {
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
if (pkgd == NULL) {
newpkg = true;
pkgd = prop_dictionary_create();

View File

@@ -49,7 +49,8 @@ set_extract_flags(void)
}
static int
extract_metafile(struct archive *ar,
extract_metafile(struct xbps_handle *xhp,
struct archive *ar,
struct archive_entry *entry,
const char *file,
const char *pkgver,
@@ -85,7 +86,7 @@ extract_metafile(struct archive *ar,
dname = dirname(dirc);
if (access(dname, X_OK) == -1) {
if (xbps_mkpath(dname, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to create metadir `%s': %s",
pkgver, dname, strerror(errno));
@@ -100,7 +101,7 @@ extract_metafile(struct archive *ar,
if (archive_read_extract(ar, entry, flags) != 0) {
rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to extract metafile `%s': %s",
pkgver, file, strerror(rv));
@@ -115,7 +116,9 @@ extract_metafile(struct archive *ar,
}
static int
remove_metafile(const char *file, const char *pkgver)
remove_metafile(struct xbps_handle *xhp,
const char *file,
const char *pkgver)
{
const char *version;
char *buf, *pkgname;
@@ -136,7 +139,7 @@ remove_metafile(const char *file, const char *pkgver)
}
if (unlink(buf) == -1) {
if (errno && errno != ENOENT) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to remove metafile `%s': %s",
pkgver, file, strerror(errno));
@@ -152,11 +155,12 @@ remove_metafile(const char *file, const char *pkgver)
}
static int
unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
unpack_archive(struct xbps_handle *xhp,
prop_dictionary_t pkg_repod,
struct archive *ar)
{
prop_dictionary_t propsd = NULL, filesd = NULL, old_filesd = NULL;
prop_array_t array;
const struct xbps_handle *xhp = xbps_handle_get();
const struct stat *entry_statp;
struct stat st;
struct xbps_unpack_cb_data *xucd = NULL;
@@ -205,7 +209,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
}
}
if (chdir(xhp->rootdir) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to chdir to rootdir `%s': %s",
pkgver, xhp->rootdir, strerror(errno));
@@ -218,9 +222,9 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
* Always remove current INSTALL/REMOVE scripts in pkg's metadir,
* as security measures.
*/
if ((rv = remove_metafile("INSTALL", pkgver)) != 0)
if ((rv = remove_metafile(xhp, "INSTALL", pkgver)) != 0)
goto out;
if ((rv = remove_metafile("REMOVE", pkgver)) != 0)
if ((rv = remove_metafile(xhp, "REMOVE", pkgver)) != 0)
goto out;
/*
@@ -263,18 +267,19 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
rv = ENOMEM;
goto out;
}
rv = extract_metafile(ar, entry, "INSTALL",
pkgver, true, flags);
rv = extract_metafile(xhp, ar, entry,
"INSTALL", pkgver, true, flags);
if (rv != 0)
goto out;
rv = xbps_file_exec(buf, "pre",
rv = xbps_file_exec(xhp, buf, "pre",
pkgname, version, update ? "yes" : "no",
xhp->conffile, NULL);
free(buf);
buf = NULL;
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] INSTALL script failed "
"to execute pre ACTION: %s",
@@ -285,8 +290,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
continue;
} else if (strcmp("./REMOVE", entry_pname) == 0) {
rv = extract_metafile(ar, entry, "REMOVE",
pkgver, true, flags);
rv = extract_metafile(xhp, ar, entry,
"REMOVE", pkgver, true, flags);
if (rv != 0)
goto out;
@@ -308,12 +313,12 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
continue;
} else if (strcmp("./props.plist", entry_pname) == 0) {
rv = extract_metafile(ar, entry, XBPS_PKGPROPS,
rv = extract_metafile(xhp, ar, entry, XBPS_PKGPROPS,
pkgver, false, flags);
if (rv != 0)
goto out;
propsd = xbps_dictionary_from_metadata_plist(
propsd = xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS);
if (propsd == NULL) {
rv = errno;
@@ -334,7 +339,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
* This is not an XBPS binary package.
*/
if (entry_idx >= 3) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp,
XBPS_STATE_UNPACK_FAIL,
ENODEV, pkgname, version,
"%s: [unpack] invalid binary package `%s'.",
pkgver, fname);
@@ -379,13 +385,14 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
buf[x] = entry_pname[i];
buf[x] = '\0';
file_exists = true;
rv = xbps_file_hash_check_dictionary(filesd,
rv = xbps_file_hash_check_dictionary(xhp, filesd,
conf_file ? "conf_files" : "files", buf);
free(buf);
if (rv == -1) {
/* error */
xbps_dbg_printf("%s-%s: failed to check"
xbps_dbg_printf(xhp,
"%s-%s: failed to check"
" hash for `%s': %s\n", pkgname,
version, entry_pname,
strerror(errno));
@@ -397,7 +404,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/
if (chmod(entry_pname,
entry_statp->st_mode) != 0) {
xbps_dbg_printf("%s-%s: failed "
xbps_dbg_printf(xhp,
"%s-%s: failed "
"to set perms %s to %s: %s\n",
pkgname, version,
archive_entry_strmode(entry),
@@ -406,14 +414,16 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
rv = EINVAL;
goto out;
}
xbps_dbg_printf("%s-%s: entry %s perms "
xbps_dbg_printf(xhp,
"%s-%s: entry %s perms "
"to %s.\n", pkgname, version,
entry_pname,
archive_entry_strmode(entry));
/*
* hash match, skip extraction.
*/
xbps_dbg_printf("%s-%s: entry %s "
xbps_dbg_printf(xhp,
"%s-%s: entry %s "
"matches current SHA256, "
"skipping...\n", pkgname,
version, entry_pname);
@@ -435,7 +445,8 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
(void)rename(entry_pname, buf);
free(buf);
buf = NULL;
xbps_set_cb_state(XBPS_STATE_CONFIG_FILE, 0,
xbps_set_cb_state(xhp,
XBPS_STATE_CONFIG_FILE, 0,
pkgname, version,
"Renamed old configuration file "
"`%s' to `%s.old'.", entry_pname, entry_pname);
@@ -449,7 +460,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
if (xucd != NULL)
xucd->entry_is_conf = true;
rv = xbps_entry_install_conf_file(filesd,
rv = xbps_entry_install_conf_file(xhp, filesd,
entry, entry_pname, pkgname, version);
if (rv == -1) {
/* error */
@@ -468,21 +479,21 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/
if (archive_read_extract(ar, entry, flags) != 0) {
rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to extract file `%s': %s",
pkgver, entry_pname, strerror(rv));
}
if (xucd != NULL) {
xucd->entry_extract_count++;
(*xhp->unpack_cb)(xucd, xhp->unpack_cb_data);
(*xhp->unpack_cb)(xhp, xucd, xhp->unpack_cb_data);
}
}
/*
* If there was any error extracting files from archive, error out.
*/
if ((rv = archive_errno(ar)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to extract files: %s",
pkgver, fname, archive_error_string(ar));
@@ -509,7 +520,7 @@ unpack_archive(prop_dictionary_t pkg_repod, struct archive *ar)
*/
old_filesd = prop_dictionary_internalize_from_zfile(pkgfilesd);
if (prop_object_type(old_filesd) == PROP_TYPE_DICTIONARY) {
rv = xbps_remove_obsoletes(pkgname, version,
rv = xbps_remove_obsoletes(xhp, pkgname, version,
pkgver, old_filesd, filesd);
prop_object_release(old_filesd);
if (rv != 0) {
@@ -530,7 +541,7 @@ out1:
goto out;
}
if (xbps_mkpath(buf, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to create pkg metadir `%s': %s",
buf, pkgver, strerror(errno));
@@ -542,7 +553,7 @@ out1:
*/
if (!prop_dictionary_externalize_to_zfile(filesd, pkgfilesd)) {
rv = errno;
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] failed to extract metadata file `%s': %s",
pkgver, XBPS_PKGFILES, strerror(errno));
@@ -564,7 +575,7 @@ out:
}
int HIDDEN
xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
{
struct archive *ar = NULL;
const char *pkgname, *version, *repoloc, *pkgver, *fname;
@@ -579,11 +590,11 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
xbps_set_cb_state(XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc);
bpkg = xbps_path_from_repository_uri(xhp, pkg_repod, repoloc);
if (bpkg == NULL) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
errno, pkgname, version,
"%s: [unpack] cannot determine binary package "
"file for `%s': %s", pkgver, fname, strerror(errno));
@@ -604,7 +615,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
if (archive_read_open_filename(ar, bpkg, ARCHIVE_READ_BLOCKSIZE) != 0) {
rv = archive_errno(ar);
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to open binary package `%s': %s",
pkgver, fname, strerror(rv));
@@ -617,9 +628,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/*
* Set package state to half-unpacked.
*/
if ((rv = xbps_set_pkg_state_installed(pkgname, version,
if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_HALF_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to set state to half-unpacked: %s",
pkgver, strerror(rv));
@@ -628,8 +639,8 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/*
* Extract archive files.
*/
if ((rv = unpack_archive(pkg_repod, ar)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
if ((rv = unpack_archive(xhp, pkg_repod, ar)) != 0) {
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to unpack files from archive: %s",
pkgver, strerror(rv));
@@ -638,9 +649,9 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/*
* Set package state to unpacked.
*/
if ((rv = xbps_set_pkg_state_installed(pkgname, version,
if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
XBPS_PKG_STATE_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version,
"%s: [unpack] failed to set state to unpacked: %s",
pkgver, strerror(rv));

View File

@@ -64,22 +64,21 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
if (xhp->pkgdb != NULL)
return 0;
if ((rv = xbps_pkgdb_update(false)) != 0) {
if ((rv = xbps_pkgdb_update(xhp, false)) != 0) {
if (rv != ENOENT)
xbps_dbg_printf("[pkgdb] cannot internalize "
xbps_dbg_printf(xhp, "[pkgdb] cannot internalize "
"pkgdb array: %s\n", strerror(rv));
return rv;
}
xbps_dbg_printf("[pkgdb] initialized ok.\n");
xbps_dbg_printf(xhp, "[pkgdb] initialized ok.\n");
return 0;
}
int
xbps_pkgdb_update(bool flush)
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
char *plist;
int rv = 0;
@@ -92,7 +91,8 @@ xbps_pkgdb_update(bool flush)
if (access(xhp->metadir, X_OK) == -1) {
if (errno == ENOENT) {
if (xbps_mkpath(xhp->metadir, 0755) != 0) {
xbps_dbg_printf("[pkgdb] failed to "
xbps_dbg_printf(xhp,
"[pkgdb] failed to "
"create metadir %s: %s\n",
xhp->metadir,
strerror(errno));
@@ -133,46 +133,47 @@ xbps_pkgdb_release(struct xbps_handle *xhp)
prop_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
xbps_dbg_printf("[pkgdb] released ok.\n");
xbps_dbg_printf(xhp, "[pkgdb] released ok.\n");
}
static int
foreach_pkg_cb(int (*fn)(prop_object_t, void *, bool *),
foreach_pkg_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg,
bool reverse)
{
struct xbps_handle *xhp = xbps_handle_get();
int rv;
if ((rv = xbps_pkgdb_init(xhp)) != 0)
return rv;
if (reverse)
rv = xbps_callback_array_iter_reverse(xhp->pkgdb, fn, arg);
rv = xbps_callback_array_iter_reverse(xhp, xhp->pkgdb, fn, arg);
else
rv = xbps_callback_array_iter(xhp->pkgdb, fn, arg);
rv = xbps_callback_array_iter(xhp, xhp->pkgdb, fn, arg);
return rv;
}
int
xbps_pkgdb_foreach_reverse_cb(int (*fn)(prop_object_t, void *, bool *),
xbps_pkgdb_foreach_reverse_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
return foreach_pkg_cb(fn, arg, true);
return foreach_pkg_cb(xhp, fn, arg, true);
}
int
xbps_pkgdb_foreach_cb(int (*fn)(prop_object_t, void *, bool *),
xbps_pkgdb_foreach_cb(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
return foreach_pkg_cb(fn, arg, false);
return foreach_pkg_cb(xhp, fn, arg, false);
}
prop_dictionary_t
xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern)
xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL;
if (xbps_pkgdb_init(xhp) != 0)
@@ -190,9 +191,8 @@ xbps_pkgdb_get_pkgd(const char *pkg, bool bypattern)
}
prop_dictionary_t
xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver)
xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd = NULL;
if (xbps_pkgdb_init(xhp) != 0)
@@ -206,9 +206,11 @@ xbps_pkgdb_get_pkgd_by_pkgver(const char *pkgver)
}
bool
xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush)
xbps_pkgdb_remove_pkgd(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
bool rv = false;
if (xbps_pkgdb_init(xhp) != 0)
@@ -222,19 +224,19 @@ xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush)
if (!flush || !rv)
return rv;
if ((xbps_pkgdb_update(true)) != 0)
if ((xbps_pkgdb_update(xhp, true)) != 0)
return false;
return true;
}
bool
xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
xbps_pkgdb_replace_pkgd(struct xbps_handle *xhp,
prop_dictionary_t pkgd,
const char *pkg,
bool bypattern,
bool flush)
{
struct xbps_handle *xhp = xbps_handle_get();
int rv;
if (xbps_pkgdb_init(xhp) != 0)
@@ -248,7 +250,7 @@ xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
if (!flush)
return rv != 0 ? false : true;
if ((xbps_pkgdb_update(true)) != 0)
if ((xbps_pkgdb_update(xhp, true)) != 0)
return false;
return true;

View File

@@ -74,9 +74,10 @@ xbps_add_obj_to_array(prop_array_t array, prop_object_t obj)
}
int
xbps_callback_array_iter(prop_array_t array,
int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_callback_array_iter(struct xbps_handle *xhp,
prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
prop_object_t obj;
prop_object_iterator_t iter;
@@ -91,7 +92,7 @@ xbps_callback_array_iter(prop_array_t array,
return ENOMEM;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
rv = (*fn)(obj, arg, &loop_done);
rv = (*fn)(xhp, obj, arg, &loop_done);
if (rv != 0 || loop_done)
break;
}
@@ -101,10 +102,11 @@ xbps_callback_array_iter(prop_array_t array,
}
int
xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
const char *key,
int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_callback_array_iter_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
prop_object_t obj;
prop_array_t array;
@@ -113,6 +115,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
bool cbloop_done = false;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(xhp != NULL);
assert(key != NULL);
assert(fn != NULL);
@@ -124,7 +127,7 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
obj = prop_array_get(array, i);
if (obj == NULL)
continue;
rv = (*fn)(obj, arg, &cbloop_done);
rv = (*fn)(xhp, obj, arg, &cbloop_done);
if (rv != 0 || cbloop_done)
break;
}
@@ -133,9 +136,10 @@ xbps_callback_array_iter_in_dict(prop_dictionary_t dict,
}
int
xbps_callback_array_iter_reverse(prop_array_t array,
int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_callback_array_iter_reverse(struct xbps_handle *xhp,
prop_array_t array,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
prop_object_t obj;
unsigned int cnt;
@@ -144,6 +148,7 @@ xbps_callback_array_iter_reverse(prop_array_t array,
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(fn != NULL);
assert(xhp != NULL);
if ((cnt = prop_array_count(array)) == 0)
return 0;
@@ -152,7 +157,7 @@ xbps_callback_array_iter_reverse(prop_array_t array,
obj = prop_array_get(array, cnt);
if (obj == NULL)
continue;
rv = (*fn)(obj, arg, &loop_done);
rv = (*fn)(xhp, obj, arg, &loop_done);
if (rv != 0 || loop_done)
break;
}
@@ -161,24 +166,26 @@ xbps_callback_array_iter_reverse(prop_array_t array,
}
int
xbps_callback_array_iter_reverse_in_dict(prop_dictionary_t dict,
const char *key,
int (*fn)(prop_object_t, void *, bool *),
void *arg)
xbps_callback_array_iter_reverse_in_dict(struct xbps_handle *xhp,
prop_dictionary_t dict,
const char *key,
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
void *arg)
{
prop_array_t array;
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
assert(key != NULL);
assert(fn != NULL);
assert(xhp != NULL);
array = prop_dictionary_get(dict, key);
if (prop_object_type(array) != PROP_TYPE_ARRAY) {
xbps_dbg_printf("invalid key '%s' for dictionary", key);
xbps_dbg_printf(xhp, "invalid key '%s' for dictionary", key);
return EINVAL;
}
return xbps_callback_array_iter_reverse(array, fn, arg);
return xbps_callback_array_iter_reverse(xhp, array, fn, arg);
}
prop_object_iterator_t
@@ -259,17 +266,16 @@ xbps_array_replace_dict_by_pattern(prop_array_t array,
}
prop_dictionary_t
xbps_dictionary_from_metadata_plist(const char *pkgname,
xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
const char *pkgname,
const char *plist)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd, plistd = NULL;
const char *savedpkgname;
char *plistf;
assert(pkgname != NULL);
assert(plist != NULL);
xhp = xbps_handle_get();
savedpkgname = pkgname;
plistf = xbps_xasprintf("%s/metadata/%s/%s", xhp->metadir,
@@ -278,9 +284,9 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
return NULL;
if (access(plistf, R_OK) == -1) {
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false);
pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false);
if (pkgd == NULL)
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (pkgd != NULL) {
free(plistf);
@@ -297,7 +303,7 @@ xbps_dictionary_from_metadata_plist(const char *pkgname,
plistd = prop_dictionary_internalize_from_zfile(plistf);
free(plistf);
if (plistd == NULL) {
xbps_dbg_printf("cannot read from metadata %s for %s: %s\n",
xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n",
plist, savedpkgname, strerror(errno));
return NULL;
}

View File

@@ -52,8 +52,6 @@ fetch_archive_open(struct archive *a, void *client_data)
(void)a;
xbps_dbg_printf("%s: establishing connection to `%s'...\n",
__func__, f->url->host);
f->fetch = fetchGet(f->url, NULL);
if (f->fetch == NULL)
return ENOENT;
@@ -69,9 +67,6 @@ fetch_archive_read(struct archive *a, void *client_data, const void **buf)
(void)a;
*buf = f->buffer;
xbps_dbg_printf("%s: fetching data from `%s'...\n",
__func__, f->url->doc);
return fetchIO_read(f->fetch, f->buffer, sizeof(f->buffer));
}
@@ -82,11 +77,8 @@ fetch_archive_close(struct archive *a, void *client_data)
(void)a;
if (f->fetch != NULL) {
xbps_dbg_printf("%s: closing connection to `%s'...\n",
__func__, f->url->host);
if (f->fetch != NULL)
fetchIO_close(f->fetch);
}
free(f);
return 0;

View File

@@ -161,14 +161,14 @@ xbps_find_virtualpkg_in_array_by_pattern(prop_array_t array, const char *pattern
}
static const char *
find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
find_virtualpkg_user_in_conf(struct xbps_handle *xhp,
const char *vpkg,
bool bypattern)
{
const struct xbps_handle *xhp;
const char *vpkgver, *pkg = NULL;
char *vpkgname = NULL, *tmp;
size_t i, j, cnt;
xhp = xbps_handle_get();
if (xhp->cfg == NULL)
return NULL;
@@ -205,7 +205,8 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
}
/* virtual package matched in conffile */
pkg = cfg_title(sec);
xbps_dbg_printf("matched vpkg in conf `%s' for %s\n",
xbps_dbg_printf(xhp,
"matched vpkg in conf `%s' for %s\n",
pkg, vpkg);
free(vpkgname);
break;
@@ -215,7 +216,8 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
}
static prop_dictionary_t
find_virtualpkg_user_in_array(prop_array_t array,
find_virtualpkg_user_in_array(struct xbps_handle *xhp,
prop_array_t array,
const char *str,
bool bypattern)
{
@@ -224,7 +226,7 @@ find_virtualpkg_user_in_array(prop_array_t array,
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
assert(str != NULL);
vpkgname = find_virtualpkg_user_in_conf(str, bypattern);
vpkgname = find_virtualpkg_user_in_conf(xhp, str, bypattern);
if (vpkgname == NULL)
return NULL;
@@ -232,15 +234,19 @@ find_virtualpkg_user_in_array(prop_array_t array,
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_name(prop_array_t array, const char *name)
xbps_find_virtualpkg_conf_in_array_by_name(struct xbps_handle *xhp,
prop_array_t array,
const char *name)
{
return find_virtualpkg_user_in_array(array, name, false);
return find_virtualpkg_user_in_array(xhp, array, name, false);
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_array_by_pattern(prop_array_t array, const char *p)
xbps_find_virtualpkg_conf_in_array_by_pattern(struct xbps_handle *xhp,
prop_array_t array,
const char *p)
{
return find_virtualpkg_user_in_array(array, p, true);
return find_virtualpkg_user_in_array(xhp, array, p, true);
}
static prop_dictionary_t
@@ -314,19 +320,20 @@ xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d,
}
static prop_dictionary_t
find_pkgd_installed(const char *str, bool bypattern, bool virtual)
find_pkgd_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern,
bool virtual)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd, rpkgd = NULL;
pkg_state_t state = 0;
int rv;
assert(str != NULL);
xhp = xbps_handle_get();
if ((rv = xbps_pkgdb_init(xhp)) != 0) {
if (rv != ENOENT) {
xbps_dbg_printf("%s: couldn't initialize "
xbps_dbg_printf(xhp, "%s: couldn't initialize "
"pkgdb: %s\n", strerror(rv));
return NULL;
} else if (rv == ENOENT)
@@ -339,7 +346,7 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
find_pkg_in_array(xhp->pkgdb, str, bypattern, false, NULL);
} else {
/* virtual pkg set by user in conf */
pkgd = find_virtualpkg_user_in_array(xhp->pkgdb,
pkgd = find_virtualpkg_user_in_array(xhp, xhp->pkgdb,
str, bypattern);
if (pkgd == NULL) {
/* any virtual pkg in array matching pattern */
@@ -369,13 +376,17 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual)
}
prop_dictionary_t
xbps_find_pkg_dict_installed(const char *str, bool bypattern)
xbps_find_pkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern)
{
return find_pkgd_installed(str, bypattern, false);
return find_pkgd_installed(xhp, str, bypattern, false);
}
prop_dictionary_t
xbps_find_virtualpkg_dict_installed(const char *str, bool bypattern)
xbps_find_virtualpkg_dict_installed(struct xbps_handle *xhp,
const char *str,
bool bypattern)
{
return find_pkgd_installed(str, bypattern, true);
return find_pkgd_installed(xhp, str, bypattern, true);
}

View File

@@ -31,12 +31,12 @@
#include "xbps_api_impl.h"
static int
store_dependency(prop_array_t transd_unsorted,
store_dependency(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd,
pkg_state_t repo_pkg_state,
size_t *depth)
{
const struct xbps_handle *xhp = xbps_handle_get();
prop_array_t unsorted;
int rv;
/*
* Overwrite package state in dictionary with same state than the
@@ -52,7 +52,8 @@ store_dependency(prop_array_t transd_unsorted,
/*
* Add the dictionary into the array.
*/
if (!prop_array_add(transd_unsorted, repo_pkgd))
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (!prop_array_add(unsorted, repo_pkgd))
return EINVAL;
if (xhp->flags & XBPS_FLAG_DEBUG) {
@@ -63,19 +64,20 @@ store_dependency(prop_array_t transd_unsorted,
"repository", &repo);
prop_dictionary_get_cstring_nocopy(repo_pkgd,
"pkgver", &pkgver);
xbps_dbg_printf(" ");
xbps_dbg_printf(xhp, " ");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append("%s: added into "
xbps_dbg_printf_append(xhp, "%s: added into "
"the transaction (%s).\n", pkgver, repo);
}
return 0;
}
static int
add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
add_missing_reqdep(struct xbps_handle *xhp, const char *reqpkg)
{
prop_array_t mdeps;
prop_string_t reqpkg_str;
prop_object_iterator_t iter = NULL;
prop_object_t obj;
@@ -83,16 +85,16 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
bool add_pkgdep, pkgfound, update_pkgdep;
int rv = 0;
assert(prop_object_type(missing_rdeps) == PROP_TYPE_ARRAY);
assert(reqpkg != NULL);
add_pkgdep = update_pkgdep = pkgfound = false;
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
reqpkg_str = prop_string_create_cstring_nocopy(reqpkg);
if (reqpkg_str == NULL)
return errno;
iter = prop_array_iterator(missing_rdeps);
iter = prop_array_iterator(mdeps);
if (iter == NULL)
goto out;
@@ -126,7 +128,7 @@ add_missing_reqdep(prop_array_t missing_rdeps, const char *reqpkg)
* if new dependency version is greater than current
* one, store it.
*/
xbps_dbg_printf("Missing pkgdep name matched, "
xbps_dbg_printf(xhp, "Missing pkgdep name matched, "
"curver: %s newver: %s\n", curver, pkgver);
if (xbps_cmpver(curver, pkgver) <= 0) {
add_pkgdep = false;
@@ -149,8 +151,8 @@ out:
if (iter)
prop_object_iterator_release(iter);
if (update_pkgdep)
prop_array_remove(missing_rdeps, idx);
if (add_pkgdep && !xbps_add_obj_to_array(missing_rdeps, reqpkg_str)) {
prop_array_remove(mdeps, idx);
if (add_pkgdep && !xbps_add_obj_to_array(mdeps, reqpkg_str)) {
prop_object_release(reqpkg_str);
return errno;
}
@@ -161,13 +163,11 @@ out:
#define MAX_DEPTH 512
static int
find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
prop_array_t trans_mdeps, /* transaction missing deps array */
find_repo_deps(struct xbps_handle *xhp,
prop_array_t pkg_rdeps_array, /* current pkg rundeps array */
const char *curpkg, /* current pkgver */
size_t *depth) /* max recursion depth */
{
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t curpkgd, tmpd;
prop_array_t curpkgrdeps, unsorted;
pkg_state_t state;
@@ -186,11 +186,11 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
for (i = 0; i < prop_array_count(pkg_rdeps_array); i++) {
prop_array_get_cstring_nocopy(pkg_rdeps_array, i, &reqpkg);
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append("%s: requires dependency '%s': ",
curpkg ? curpkg : " ", reqpkg);
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append(xhp, "%s: requires dependency '%s': ",
curpkg != NULL ? curpkg : " ", reqpkg);
}
/*
* Pass 1: check if required dependency is already installed
@@ -198,19 +198,19 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
*/
if ((pkgname = xbps_pkgpattern_name(reqpkg)) == NULL) {
rv = EINVAL;
xbps_dbg_printf("failed to get "
xbps_dbg_printf(xhp, "failed to get "
"pkgname from `%s'!", reqpkg);
break;
}
/*
* Look for a real package installed...
*/
tmpd = xbps_find_pkg_dict_installed(pkgname, false);
tmpd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
if (tmpd == NULL) {
if (errno && errno != ENOENT) {
/* error */
rv = errno;
xbps_dbg_printf("failed to find "
xbps_dbg_printf(xhp, "failed to find "
"installed pkg for `%s': %s\n",
reqpkg, strerror(errno));
break;
@@ -219,20 +219,21 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* real package not installed, try looking for
* a virtual package instead.
*/
tmpd = xbps_find_virtualpkg_dict_installed(pkgname, false);
tmpd = xbps_find_virtualpkg_dict_installed(xhp,
pkgname, false);
}
free(pkgname);
if (tmpd == NULL) {
if (errno && errno != ENOENT) {
/* error */
rv = errno;
xbps_dbg_printf("failed to find "
xbps_dbg_printf(xhp, "failed to find "
"installed virtual pkg for `%s': %s\n",
reqpkg, strerror(errno));
break;
}
/* Required pkgdep not installed */
xbps_dbg_printf_append("not installed. ");
xbps_dbg_printf_append(xhp, "not installed. ");
reason = "install";
state = XBPS_PKG_STATE_NOT_INSTALLED;
} else {
@@ -255,7 +256,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* package and is satisfied by an
* installed package.
*/
xbps_dbg_printf_append("[virtual] satisfied by "
xbps_dbg_printf_append(xhp,
"[virtual] satisfied by "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
@@ -266,7 +268,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is installed but does not match
* the dependency pattern, update pkg.
*/
xbps_dbg_printf_append("installed `%s', "
xbps_dbg_printf_append(xhp,
"installed `%s', "
"must be updated.\n", pkgver_q);
reason = "update";
} else if (rv == 1) {
@@ -277,7 +280,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern but was only unpacked,
* configure pkg.
*/
xbps_dbg_printf_append("installed `%s'"
xbps_dbg_printf_append(xhp,
"installed `%s'"
", must be configured.\n",
pkgver_q);
reason = "configure";
@@ -287,7 +291,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* pattern and is fully installed,
* skip to next one.
*/
xbps_dbg_printf_append("installed "
xbps_dbg_printf_append(xhp,
"installed "
"`%s'.\n", pkgver_q);
prop_object_release(tmpd);
continue;
@@ -295,7 +300,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else {
/* error matching pkgpattern */
prop_object_release(tmpd);
xbps_dbg_printf("failed to match "
xbps_dbg_printf(xhp, "failed to match "
"pattern %s with %s\n", reqpkg, pkgver_q);
break;
}
@@ -304,9 +309,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Pass 2: check if required dependency has been already
* added in the transaction dictionary.
*/
unsorted = prop_dictionary_get(transd, "unsorted_deps");
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (((curpkgd = xbps_find_pkg_in_array_by_pattern(unsorted, reqpkg, NULL)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_conf_in_array_by_pattern(xhp, unsorted, reqpkg)) == NULL) &&
((curpkgd = xbps_find_virtualpkg_in_array_by_pattern(unsorted, reqpkg)) == NULL)) {
/* error matching required pkgdep */
if (errno && errno != ENOENT) {
@@ -316,7 +321,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} else {
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
xbps_dbg_printf_append(" (%s queued "
xbps_dbg_printf_append(xhp, " (%s queued "
"in transaction).\n", pkgver_q);
continue;
}
@@ -325,35 +330,37 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* If dependency does not match add pkg into the missing
* deps array and pass to next one.
*/
if (((curpkgd = xbps_rpool_find_virtualpkg_conf(reqpkg, true)) == NULL) &&
((curpkgd = xbps_rpool_find_pkg(reqpkg, true, true)) == NULL) &&
((curpkgd = xbps_rpool_find_virtualpkg(reqpkg, true)) == NULL)) {
if (((curpkgd = xbps_rpool_find_virtualpkg_conf(xhp, reqpkg, true)) == NULL) &&
((curpkgd = xbps_rpool_find_pkg(xhp, reqpkg, true, true)) == NULL) &&
((curpkgd = xbps_rpool_find_virtualpkg(xhp, reqpkg, true)) == NULL)) {
/* pkg not found, there was some error */
if (errno && errno != ENOENT) {
xbps_dbg_printf("failed to find pkg "
xbps_dbg_printf(xhp, "failed to find pkg "
"for `%s' in rpool: %s\n",
reqpkg, strerror(errno));
rv = errno;
break;
}
rv = add_missing_reqdep(trans_mdeps, reqpkg);
rv = add_missing_reqdep(xhp, reqpkg);
if (rv != 0 && rv != EEXIST) {
xbps_dbg_printf_append("`%s': "
xbps_dbg_printf_append(xhp, "`%s': "
"add_missing_reqdep failed %s\n",
reqpkg);
break;
} else if (rv == EEXIST) {
xbps_dbg_printf_append("`%s' missing "
xbps_dbg_printf_append(xhp, "`%s' missing "
"dep already added.\n", reqpkg);
rv = 0;
continue;
} else {
xbps_dbg_printf_append("`%s' added "
xbps_dbg_printf_append(xhp, "`%s' added "
"into the missing deps array.\n",
reqpkg);
continue;
}
}
prop_dictionary_get_cstring_nocopy(curpkgd,
"pkgver", &pkgver_q);
/*
* Check if package has matched conflicts.
*/
@@ -362,9 +369,9 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Package is on repo, add it into the transaction dictionary.
*/
prop_dictionary_set_cstring_nocopy(curpkgd, "transaction", reason);
rv = store_dependency(unsorted, curpkgd, state, depth);
rv = store_dependency(xhp, curpkgd, state, depth);
if (rv != 0) {
xbps_dbg_printf("store_dependency failed for "
xbps_dbg_printf(xhp, "store_dependency failed for "
"`%s': %s\n", reqpkg, strerror(rv));
prop_object_release(curpkgd);
break;
@@ -379,21 +386,20 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
}
prop_object_release(curpkgd);
if (xhp->flags & XBPS_FLAG_DEBUG) {
xbps_dbg_printf("");
xbps_dbg_printf(xhp, "");
for (x = 0; x < *depth; x++)
xbps_dbg_printf_append(" ");
xbps_dbg_printf_append(xhp, " ");
xbps_dbg_printf_append(" %s: finding dependencies:\n",
pkgver_q);
xbps_dbg_printf_append(xhp,
"%s: finding dependencies:\n", pkgver_q);
}
/*
* Recursively find rundeps for current pkg dictionary.
*/
(*depth)++;
rv = find_repo_deps(transd, trans_mdeps, curpkgrdeps,
pkgver_q, depth);
rv = find_repo_deps(xhp, curpkgrdeps, pkgver_q, depth);
if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n",
xbps_dbg_printf(xhp, "Error checking %s for rundeps: %s\n",
reqpkg, strerror(rv));
break;
}
@@ -407,7 +413,7 @@ int HIDDEN
xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
prop_dictionary_t repo_pkgd)
{
prop_array_t mdeps, pkg_rdeps;
prop_array_t pkg_rdeps;
const char *pkgver;
size_t depth = 0;
@@ -416,11 +422,10 @@ xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
return 0;
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver);
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
xbps_dbg_printf(xhp, "Finding required dependencies for '%s':\n", pkgver);
/*
* This will find direct and indirect deps, if any of them is not
* there it will be added into the missing_deps array.
*/
return find_repo_deps(xhp->transd, mdeps, pkg_rdeps, pkgver, &depth);
return find_repo_deps(xhp, pkg_rdeps, pkgver, &depth);
}

View File

@@ -64,7 +64,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
/*
* If index file is not there, skip.
*/
plist = xbps_pkg_index_plist(repouri);
plist = xbps_pkg_index_plist(xhp, repouri);
if (plist == NULL) {
rv = errno;
goto out;
@@ -72,7 +72,8 @@ xbps_rpool_init(struct xbps_handle *xhp)
array = prop_array_internalize_from_zfile(plist);
free(plist);
if (array == NULL) {
xbps_dbg_printf("[rpool] `%s' cannot be internalized:"
xbps_dbg_printf(xhp,
"[rpool] `%s' cannot be internalized:"
" %s\n", repouri, strerror(errno));
nmissing++;
continue;
@@ -102,7 +103,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
prop_object_release(d);
goto out;
}
xbps_dbg_printf("[rpool] `%s' registered.\n", repouri);
xbps_dbg_printf(xhp, "[rpool] `%s' registered.\n", repouri);
}
if (ntotal - nmissing == 0) {
/* no repositories available, error out */
@@ -111,7 +112,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
}
prop_array_make_immutable(xhp->repo_pool);
xbps_dbg_printf("[rpool] initialized ok.\n");
xbps_dbg_printf(xhp, "[rpool] initialized ok.\n");
out:
if (rv != 0)
xbps_rpool_release(xhp);
@@ -135,18 +136,18 @@ xbps_rpool_release(struct xbps_handle *xhp)
d = prop_array_get(xhp->repo_pool, i);
idx = prop_dictionary_get(d, "index");
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
xbps_dbg_printf("[rpool] unregistered repository '%s'\n", uri);
xbps_dbg_printf(xhp, "[rpool] unregistered repository '%s'\n",
uri);
prop_object_release(idx);
prop_object_release(d);
}
xhp->repo_pool = NULL;
xbps_dbg_printf("[rpool] released ok.\n");
xbps_dbg_printf(xhp, "[rpool] released ok.\n");
}
int
xbps_rpool_sync(const char *uri)
xbps_rpool_sync(struct xbps_handle *xhp, const char *uri)
{
const struct xbps_handle *xhp = xbps_handle_get();
const char *repouri;
size_t i;
@@ -161,8 +162,9 @@ xbps_rpool_sync(const char *uri)
/*
* Fetch repository index.
*/
if (xbps_repository_sync_pkg_index(repouri, XBPS_PKGINDEX) == -1) {
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n",
if (xbps_repository_sync_pkg_index(xhp, repouri, XBPS_PKGINDEX) == -1) {
xbps_dbg_printf(xhp,
"[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string());
continue;
@@ -170,9 +172,10 @@ xbps_rpool_sync(const char *uri)
/*
* Fetch repository files index.
*/
if (xbps_repository_sync_pkg_index(repouri,
if (xbps_repository_sync_pkg_index(xhp, repouri,
XBPS_PKGINDEX_FILES) == -1) {
xbps_dbg_printf("[rpool] `%s' failed to fetch: %s\n",
xbps_dbg_printf(xhp,
"[rpool] `%s' failed to fetch: %s\n",
repouri, fetchLastErrCode == 0 ? strerror(errno) :
xbps_fetch_error_string());
continue;
@@ -182,10 +185,11 @@ xbps_rpool_sync(const char *uri)
}
int
xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *arg)
xbps_rpool_foreach(struct xbps_handle *xhp,
int (*fn)(struct xbps_handle *, struct xbps_rpool_index *, void *, bool *),
void *arg)
{
prop_dictionary_t d;
struct xbps_handle *xhp = xbps_handle_get();
struct xbps_rpool_index rpi;
size_t i;
int rv = 0;
@@ -195,9 +199,11 @@ xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *a
/* Initialize repository pool */
if ((rv = xbps_rpool_init(xhp)) != 0) {
if (rv == ENOTSUP) {
xbps_dbg_printf("[rpool] empty repository list.\n");
xbps_dbg_printf(xhp,
"[rpool] empty repository list.\n");
} else if (rv != ENOENT && rv != ENOTSUP) {
xbps_dbg_printf("[rpool] couldn't initialize: %s\n",
xbps_dbg_printf(xhp,
"[rpool] couldn't initialize: %s\n",
strerror(rv));
}
return rv;
@@ -207,7 +213,7 @@ xbps_rpool_foreach(int (*fn)(struct xbps_rpool_index *, void *, bool *), void *a
d = prop_array_get(xhp->repo_pool, i);
prop_dictionary_get_cstring_nocopy(d, "uri", &rpi.uri);
rpi.repo = prop_dictionary_get(d, "index");
rv = (*fn)(&rpi, arg, &done);
rv = (*fn)(xhp, &rpi, arg, &done);
if (rv != 0 || done)
break;
}

View File

@@ -45,10 +45,15 @@ struct repo_pool_fpkg {
};
static int
repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_virtualpkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_in_array_by_pattern(rpi->repo,
@@ -68,18 +73,21 @@ repo_find_virtualpkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
}
static int
repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_virtualpkg_conf_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_pattern(rpi->repo,
rpf->pattern);
xbps_find_virtualpkg_conf_in_array_by_pattern(xhp,
rpi->repo, rpf->pattern);
} else {
rpf->pkgd =
xbps_find_virtualpkg_conf_in_array_by_name(rpi->repo,
rpf->pattern);
xbps_find_virtualpkg_conf_in_array_by_name(xhp,
rpi->repo, rpf->pattern);
}
if (rpf->pkgd) {
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -91,10 +99,15 @@ repo_find_virtualpkg_conf_cb(struct xbps_rpool_index *rpi, void *arg, bool *done
}
static int
repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
(void)xhp;
if (rpf->exact) {
/* exact match by pkgver */
rpf->pkgd = xbps_find_pkg_in_array_by_pkgver(rpi->repo,
@@ -122,13 +135,17 @@ repo_find_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
}
static int
repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
repo_find_best_pkg_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
const char *repopkgver;
prop_dictionary_t pkgd;
(void)done;
(void)xhp;
if (rpf->bypattern) {
pkgd = xbps_find_pkg_in_array_by_pattern(rpi->repo,
@@ -141,14 +158,16 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
if (errno && errno != ENOENT)
return errno;
xbps_dbg_printf("[rpool] Package '%s' not found in repository "
xbps_dbg_printf(xhp,
"[rpool] Package '%s' not found in repository "
"'%s'.\n", rpf->pattern, rpi->uri);
return 0;
}
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &repopkgver);
if (rpf->bestpkgver == NULL) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n",
xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -160,7 +179,8 @@ repo_find_best_pkg_cb(struct xbps_rpool_index *rpi, void *arg, bool *done)
* version from current package in repository.
*/
if (xbps_cmpver(repopkgver, rpf->bestpkgver) == 1) {
xbps_dbg_printf("[rpool] Found best match '%s' (%s).\n",
xbps_dbg_printf(xhp,
"[rpool] Found best match '%s' (%s).\n",
repopkgver, rpi->uri);
rpf->pkgd = pkgd;
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
@@ -178,7 +198,10 @@ typedef enum {
} pkg_repo_type_t;
static prop_dictionary_t
repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
repo_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
pkg_repo_type_t type)
{
struct repo_pool_fpkg rpf;
int rv = 0;
@@ -195,31 +218,31 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
* Find exact pkg version.
*/
rpf.exact = true;
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break;
case BEST_PKG:
/*
* Find best pkg version.
*/
rv = xbps_rpool_foreach(repo_find_best_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_best_pkg_cb, &rpf);
break;
case VIRTUAL_PKG:
/*
* Find virtual pkg.
*/
rv = xbps_rpool_foreach(repo_find_virtualpkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_cb, &rpf);
break;
case VIRTUAL_CONF_PKG:
/*
* Find virtual pkg as specified in configuration file.
*/
rv = xbps_rpool_foreach(repo_find_virtualpkg_conf_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_virtualpkg_conf_cb, &rpf);
break;
case REAL_PKG:
/*
* Find real pkg.
*/
rv = xbps_rpool_foreach(repo_find_pkg_cb, &rpf);
rv = xbps_rpool_foreach(xhp, repo_find_pkg_cb, &rpf);
break;
}
if (rv != 0) {
@@ -231,42 +254,51 @@ repo_find_pkg(const char *pkg, bool bypattern, pkg_repo_type_t type)
}
prop_dictionary_t
xbps_rpool_find_virtualpkg(const char *pkg, bool bypattern)
xbps_rpool_find_virtualpkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{
assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_PKG);
return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_PKG);
}
prop_dictionary_t
xbps_rpool_find_virtualpkg_conf(const char *pkg, bool bypattern)
xbps_rpool_find_virtualpkg_conf(struct xbps_handle *xhp,
const char *pkg,
bool bypattern)
{
assert(pkg != NULL);
return repo_find_pkg(pkg, bypattern, VIRTUAL_CONF_PKG);
return repo_find_pkg(xhp, pkg, bypattern, VIRTUAL_CONF_PKG);
}
prop_dictionary_t
xbps_rpool_find_pkg(const char *pkg, bool bypattern, bool best)
xbps_rpool_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best)
{
assert(pkg != NULL);
if (best)
return repo_find_pkg(pkg, bypattern, BEST_PKG);
return repo_find_pkg(xhp, pkg, bypattern, BEST_PKG);
return repo_find_pkg(pkg, bypattern, REAL_PKG);
return repo_find_pkg(xhp, pkg, bypattern, REAL_PKG);
}
prop_dictionary_t
xbps_rpool_find_pkg_exact(const char *pkgver)
xbps_rpool_find_pkg_exact(struct xbps_handle *xhp, const char *pkgver)
{
assert(pkgver != NULL);
return repo_find_pkg(pkgver, false, EXACT_PKG);
return repo_find_pkg(xhp, pkgver, false, EXACT_PKG);
}
prop_dictionary_t
xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf)
xbps_rpool_dictionary_metadata_plist(struct xbps_handle *xhp,
const char *pattern,
const char *plistf)
{
prop_dictionary_t pkgd = NULL, plistd = NULL;
const char *repoloc;
@@ -284,15 +316,15 @@ xbps_rpool_dictionary_metadata_plist(const char *pattern, const char *plistf)
* libfetch!
*/
if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(pattern, true, false);
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else
pkgd = xbps_rpool_find_pkg(pattern, false, true);
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
if (pkgd == NULL)
goto out;
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repoloc);
url = xbps_path_from_repository_uri(pkgd, repoloc);
url = xbps_path_from_repository_uri(xhp, pkgd, repoloc);
if (url == NULL) {
errno = EINVAL;
goto out;

View File

@@ -86,10 +86,11 @@ xbps_get_remote_repo_string(const char *uri)
* size and/or mtime match) and 1 if downloaded successfully.
*/
int
xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
xbps_repository_sync_pkg_index(struct xbps_handle *xhp,
const char *uri,
const char *plistf)
{
prop_array_t array;
struct xbps_handle *xhp;
struct url *url = NULL;
struct stat st;
const char *fetch_outputdir, *fetchstr = NULL;
@@ -100,7 +101,6 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
assert(uri != NULL);
tmp_metafile = rpidx = lrepodir = lrepofile = NULL;
xhp = xbps_handle_get();
/* ignore non remote repositories */
if (!xbps_check_is_repository_uri_remote(uri))
@@ -118,7 +118,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Create metadir if necessary.
*/
if ((rv = xbps_mkpath(xhp->metadir, 0755)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL,
errno, NULL, NULL,
"[reposync] failed to create metadir `%s': %s",
xhp->metadir, strerror(errno));
@@ -162,15 +162,15 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
fetch_outputdir = xhp->metadir;
/* reposync start cb */
xbps_set_cb_state(XBPS_STATE_REPOSYNC, 0, NULL, NULL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC, 0, NULL, NULL,
"Synchronizing %s for `%s'...", plistf, uri);
/*
* Download plist index file from repository.
*/
if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) {
if (xbps_fetch_file(xhp, rpidx, fetch_outputdir, true, NULL) == -1) {
/* reposync error cb */
fetchstr = xbps_fetch_error_string();
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL,
fetchLastErrCode != 0 ? fetchLastErrCode : errno,
NULL, NULL,
"[reposync] failed to fetch file `%s': %s",
@@ -183,11 +183,11 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
/*
* Make sure that downloaded plist file can be internalized, i.e
* some HTTP servers don't return proper errors and sometimes
* you get an HTML ASCII file :-)
you get an HTML ASCII file :-)
*/
array = prop_array_internalize_from_zfile(tmp_metafile);
if (array == NULL) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, 0, NULL, NULL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, 0, NULL, NULL,
"[reposync] downloaded file `%s' is not valid.", rpidx);
(void)unlink(tmp_metafile);
rv = -1;
@@ -204,7 +204,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Create local repodir to store plist index file.
*/
if ((rv = xbps_mkpath(lrepodir, 0755)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
"[reposync] failed to create repodir for `%s': %s",
lrepodir, strerror(rv));
goto out;
@@ -214,7 +214,7 @@ xbps_repository_sync_pkg_index(const char *uri, const char *plistf)
* Rename to destination file now it has been fetched successfully.
*/
if ((rv = rename(tmp_metafile, lrepofile)) == -1) {
xbps_set_cb_state(XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
xbps_set_cb_state(xhp, XBPS_STATE_REPOSYNC_FAIL, errno, NULL, NULL,
"[reposync] failed to rename index file `%s' to `%s': %s",
tmp_metafile, lrepofile, strerror(errno));
} else {

View File

@@ -57,7 +57,7 @@
*/
static int
check_binpkgs_hash(prop_object_iterator_t iter)
check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
{
prop_object_t obj;
const char *pkgver, *repoloc, *filen, *sha256, *trans;
@@ -83,17 +83,17 @@ check_binpkgs_hash(prop_object_iterator_t iter)
"filename-sha256", &sha256);
assert(sha256 != NULL);
binfile = xbps_path_from_repository_uri(obj, repoloc);
binfile = xbps_path_from_repository_uri(xhp, obj, repoloc);
if (binfile == NULL) {
rv = EINVAL;
break;
}
xbps_set_cb_state(XBPS_STATE_VERIFY, 0, pkgname, version,
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgname, version,
"Verifying `%s' package integrity...", filen, repoloc);
rv = xbps_file_hash_check(binfile, sha256);
if (rv != 0) {
free(binfile);
xbps_set_cb_state(XBPS_STATE_VERIFY_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY_FAIL,
rv, pkgname, version,
"Failed to verify `%s' package integrity: %s",
filen, strerror(rv));
@@ -130,7 +130,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
assert(filen != NULL);
binfile = xbps_path_from_repository_uri(obj, repoloc);
binfile = xbps_path_from_repository_uri(xhp, obj, repoloc);
if (binfile == NULL) {
rv = EINVAL;
break;
@@ -146,7 +146,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
* Create cachedir.
*/
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
errno, pkgname, version,
"%s: [trans] cannot create cachedir `%s': %s",
pkgver, xhp->cachedir, strerror(errno));
@@ -154,17 +154,17 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
rv = errno;
break;
}
xbps_set_cb_state(XBPS_STATE_DOWNLOAD,
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
0, pkgname, version,
"Downloading binary package `%s' (from `%s')...",
filen, repoloc);
/*
* Fetch binary package.
*/
rv = xbps_fetch_file(binfile, xhp->cachedir, false, NULL);
rv = xbps_fetch_file(xhp, binfile, xhp->cachedir, false, NULL);
if (rv == -1) {
fetchstr = xbps_fetch_error_string();
xbps_set_cb_state(XBPS_STATE_DOWNLOAD_FAIL,
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
fetchLastErrCode != 0 ? fetchLastErrCode : errno,
pkgname, version,
"%s: [trans] failed to download binary package "
@@ -182,9 +182,8 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
}
int
xbps_transaction_commit(void)
xbps_transaction_commit(struct xbps_handle *xhp)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_object_t obj;
prop_object_iterator_t iter;
size_t i;
@@ -201,26 +200,26 @@ xbps_transaction_commit(void)
/*
* Download binary packages (if they come from a remote repository).
*/
xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out;
/*
* Check SHA256 hashes for binary packages in transaction.
*/
xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
if ((rv = check_binpkgs_hash(iter)) != 0)
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
if ((rv = check_binpkgs_hash(xhp, iter)) != 0)
goto out;
/*
* Install, update, configure or remove packages as specified
* in the transaction dictionary.
*/
xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
i = 0;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if ((xhp->transaction_frequency_flush > 0) &&
(++i >= xhp->transaction_frequency_flush)) {
rv = xbps_pkgdb_update(true);
rv = xbps_pkgdb_update(xhp, true);
if (rv != 0 && rv != ENOENT)
goto out;
@@ -241,14 +240,14 @@ xbps_transaction_commit(void)
prop_dictionary_get_bool(obj, "remove-and-update",
&update);
prop_dictionary_get_bool(obj, "softreplace", &sr);
rv = xbps_remove_pkg(pkgname, version, update, sr);
rv = xbps_remove_pkg(xhp, pkgname, version, update, sr);
if (rv != 0)
goto out;
} else if (strcmp(tract, "configure") == 0) {
/*
* Reconfigure pending package.
*/
rv = xbps_configure_pkg(pkgname, false, false, false);
rv = xbps_configure_pkg(xhp, pkgname, false, false, false);
if (rv != 0)
goto out;
} else {
@@ -265,12 +264,12 @@ xbps_transaction_commit(void)
* Update a package: execute pre-remove
* action if found before unpacking.
*/
xbps_set_cb_state(XBPS_STATE_UPDATE, 0,
xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0,
pkgname, version, NULL);
rv = xbps_remove_pkg(pkgname, version,
rv = xbps_remove_pkg(xhp, pkgname, version,
true, false);
if (rv != 0) {
xbps_set_cb_state(
xbps_set_cb_state(xhp,
XBPS_STATE_UPDATE_FAIL,
rv, pkgname, version,
"%s: [trans] failed to update "
@@ -280,25 +279,25 @@ xbps_transaction_commit(void)
}
} else {
/* Install a package */
xbps_set_cb_state(XBPS_STATE_INSTALL, 0,
pkgname, version, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_INSTALL,
0, pkgname, version, NULL);
}
/*
* Unpack binary package.
*/
if ((rv = xbps_unpack_binary_pkg(obj)) != 0)
if ((rv = xbps_unpack_binary_pkg(xhp, obj)) != 0)
goto out;
/*
* Register package.
*/
if ((rv = xbps_register_pkg(obj, false)) != 0)
if ((rv = xbps_register_pkg(xhp, obj, false)) != 0)
goto out;
}
}
prop_object_iterator_reset(iter);
/* force a flush now packages were removed/unpacked */
if ((rv = xbps_pkgdb_update(true)) != 0)
if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out;
/* if there are no packages to install or update we are done */
@@ -307,13 +306,13 @@ xbps_transaction_commit(void)
/*
* Configure all unpacked packages.
*/
xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
i = 0;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (xhp->transaction_frequency_flush > 0 &&
++i >= xhp->transaction_frequency_flush) {
if ((rv = xbps_pkgdb_update(true)) != 0)
if ((rv = xbps_pkgdb_update(xhp, true)) != 0)
goto out;
i = 0;
@@ -330,7 +329,7 @@ xbps_transaction_commit(void)
if (strcmp(tract, "update") == 0)
update = true;
rv = xbps_configure_pkg(pkgname, false, update, false);
rv = xbps_configure_pkg(xhp, pkgname, false, update, false);
if (rv != 0)
goto out;
/*
@@ -338,16 +337,16 @@ xbps_transaction_commit(void)
* installed or updated.
*/
if (update) {
xbps_set_cb_state(XBPS_STATE_UPDATE_DONE, 0,
xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
pkgname, version, NULL);
} else {
xbps_set_cb_state(XBPS_STATE_INSTALL_DONE, 0,
xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
pkgname, version, NULL);
}
}
/* Force a flush now that packages are configured */
rv = xbps_pkgdb_update(true);
rv = xbps_pkgdb_update(xhp, true);
out:
prop_object_iterator_release(iter);

View File

@@ -53,7 +53,7 @@
*/
static int
compute_transaction_stats(prop_dictionary_t transd)
compute_transaction_stats(struct xbps_handle *xhp)
{
prop_dictionary_t pkg_metad;
prop_object_iterator_t iter;
@@ -66,7 +66,7 @@ compute_transaction_stats(prop_dictionary_t transd)
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
tsize = dlsize = instsize = rmsize = 0;
iter = xbps_array_iter_from_dict(transd, "packages");
iter = xbps_array_iter_from_dict(xhp->transd, "packages");
if (iter == NULL)
return EINVAL;
@@ -98,8 +98,8 @@ compute_transaction_stats(prop_dictionary_t transd)
if ((strcmp(tract, "remove") == 0) ||
(strcmp(tract, "update") == 0)) {
pkg_metad =
xbps_dictionary_from_metadata_plist(pkgname,
XBPS_PKGPROPS);
xbps_dictionary_from_metadata_plist(xhp,
pkgname, XBPS_PKGPROPS);
if (pkg_metad == NULL)
continue;
prop_dictionary_get_uint64(pkg_metad,
@@ -121,25 +121,25 @@ compute_transaction_stats(prop_dictionary_t transd)
}
if (inst_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-install-pkgs",
!prop_dictionary_set_uint32(xhp->transd, "total-install-pkgs",
inst_pkgcnt)) {
rv = EINVAL;
goto out;
}
if (up_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-update-pkgs",
!prop_dictionary_set_uint32(xhp->transd, "total-update-pkgs",
up_pkgcnt)) {
rv = EINVAL;
goto out;
}
if (cf_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-configure-pkgs",
!prop_dictionary_set_uint32(xhp->transd, "total-configure-pkgs",
cf_pkgcnt)) {
rv = EINVAL;
goto out;
}
if (rm_pkgcnt &&
!prop_dictionary_set_uint32(transd, "total-remove-pkgs",
!prop_dictionary_set_uint32(xhp->transd, "total-remove-pkgs",
rm_pkgcnt)) {
rv = EINVAL;
goto out;
@@ -158,7 +158,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total installed
* size that it will take.
*/
if (!prop_dictionary_set_uint64(transd,
if (!prop_dictionary_set_uint64(xhp->transd,
"total-installed-size", instsize)) {
rv = EINVAL;
goto out;
@@ -167,7 +167,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total download
* size that needs to be sucked in.
*/
if (!prop_dictionary_set_uint64(transd,
if (!prop_dictionary_set_uint64(xhp->transd,
"total-download-size", dlsize)) {
rv = EINVAL;
goto out;
@@ -176,7 +176,7 @@ compute_transaction_stats(prop_dictionary_t transd)
* Add object in transaction dictionary with total size to be
* freed from packages to be removed.
*/
if (!prop_dictionary_set_uint64(transd,
if (!prop_dictionary_set_uint64(xhp->transd,
"total-removed-size", rmsize)) {
rv = EINVAL;
goto out;
@@ -233,10 +233,9 @@ xbps_transaction_init(struct xbps_handle *xhp)
}
int
xbps_transaction_prepare(void)
xbps_transaction_prepare(struct xbps_handle *xhp)
{
prop_array_t mdeps, conflicts;
struct xbps_handle *xhp = xbps_handle_get();
int rv = 0;
if (xhp->transd == NULL)
@@ -259,7 +258,7 @@ xbps_transaction_prepare(void)
/*
* Check for packages to be replaced.
*/
if ((rv = xbps_transaction_package_replace(xhp->transd)) != 0) {
if ((rv = xbps_transaction_package_replace(xhp)) != 0) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return rv;
@@ -277,7 +276,7 @@ xbps_transaction_prepare(void)
* number of packages to be installed, updated, configured
* and removed to the transaction dictionary.
*/
if ((rv = compute_transaction_stats(xhp->transd)) != 0) {
if ((rv = compute_transaction_stats(xhp)) != 0) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return rv;

View File

@@ -57,12 +57,15 @@ enum {
};
static int
transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
transaction_find_pkg(struct xbps_handle *xhp,
const char *pkg,
bool bypattern,
bool best,
bool exact,
int action)
{
prop_dictionary_t pkg_pkgdb, pkg_repod;
prop_array_t unsorted;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *repoloc, *repover, *instver, *reason;
int rv = 0;
pkg_state_t state = 0;
@@ -74,7 +77,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
reason = "install";
} else {
/* update */
if ((pkg_pkgdb = xbps_pkgdb_get_pkgd(pkg, false)) == NULL)
if ((pkg_pkgdb = xbps_pkgdb_get_pkgd(xhp, pkg, false)) == NULL)
return ENODEV;
reason = "update";
@@ -85,22 +88,24 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
*/
if (action == TRANS_INSTALL) {
if (exact) {
if ((pkg_repod = xbps_rpool_find_pkg_exact(pkg)) == NULL) {
pkg_repod = xbps_rpool_find_pkg_exact(xhp, pkg);
if (pkg_repod == NULL) {
/* not found */
rv = errno;
goto out;
}
} else {
if (((pkg_repod = xbps_rpool_find_pkg(pkg, bypattern, best)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg_conf(pkg, bypattern)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg(pkg, bypattern)) == NULL)) {
if (((pkg_repod = xbps_rpool_find_pkg(xhp, pkg, bypattern, best)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg_conf(xhp, pkg, bypattern)) == NULL) &&
((pkg_repod = xbps_rpool_find_virtualpkg(xhp, pkg, bypattern)) == NULL)) {
/* not found */
rv = errno;
goto out;
}
}
} else {
if ((pkg_repod = xbps_rpool_find_pkg(pkg, false, true)) == NULL) {
pkg_repod = xbps_rpool_find_pkg(xhp, pkg, false, true);
if (pkg_repod == NULL) {
/* not found */
rv = errno;
goto out;
@@ -118,7 +123,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
"version", &instver);
prop_object_release(pkg_pkgdb);
if (xbps_cmpver(repover, instver) <= 0) {
xbps_dbg_printf("[rpool] Skipping `%s-%s' "
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
"(installed: %s-%s) from repository `%s'\n",
pkgname, repover, pkgname, instver, repoloc);
rv = EEXIST;
@@ -146,7 +151,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
* Set package state in dictionary with same state than the
* package currently uses, otherwise not-installed.
*/
if ((rv = xbps_pkg_state_installed(pkgname, &state)) != 0) {
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
if (rv != ENOENT)
goto out;
/* Package not installed, don't error out */
@@ -186,7 +191,7 @@ transaction_find_pkg(const char *pkg, bool bypattern, bool best, bool exact,
rv = errno;
goto out;
}
xbps_dbg_printf("%s-%s: added into the transaction (%s).\n",
xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n",
pkgname, repover, repoloc);
out:
@@ -197,10 +202,9 @@ out:
}
int
xbps_transaction_update_packages(void)
xbps_transaction_update_packages(struct xbps_handle *xhp)
{
prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *holdpkgname;
bool newpkg_found = false;
int rv = 0;
@@ -215,12 +219,12 @@ xbps_transaction_update_packages(void)
for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) {
holdpkgname = cfg_getnstr(xhp->cfg, "PackagesOnHold", x);
if (strcmp(pkgname, holdpkgname) == 0) {
xbps_dbg_printf("[rpool] package %s on hold, "
xbps_dbg_printf(xhp, "[rpool] package %s on hold, "
"ignoring updates.\n", pkgname);
continue;
}
}
rv = transaction_find_pkg(pkgname, false, true,
rv = transaction_find_pkg(xhp, pkgname, false, true,
false, TRANS_UPDATE);
if (rv == 0)
newpkg_found = true;
@@ -237,13 +241,16 @@ xbps_transaction_update_packages(void)
}
int
xbps_transaction_update_pkg(const char *pkgname)
xbps_transaction_update_pkg(struct xbps_handle *xhp, const char *pkgname)
{
return transaction_find_pkg(pkgname, false, true, false, TRANS_UPDATE);
return transaction_find_pkg(xhp, pkgname, false,
true, false, TRANS_UPDATE);
}
int
xbps_transaction_install_pkg(const char *pkg, bool reinstall)
xbps_transaction_install_pkg(struct xbps_handle *xhp,
const char *pkg,
bool reinstall)
{
prop_dictionary_t pkgd = NULL;
pkg_state_t state;
@@ -266,10 +273,10 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
}
if (exact) {
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false);
free(pkgname);
} else
pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern);
pkgd = xbps_pkgdb_get_pkgd(xhp, pkg, bypattern);
if (pkgd) {
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
@@ -282,24 +289,25 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
return EEXIST;
}
}
rv = transaction_find_pkg(pkg, bypattern, best, exact, TRANS_INSTALL);
rv = transaction_find_pkg(xhp, pkg, bypattern, best, exact, TRANS_INSTALL);
return rv;
}
int
xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
xbps_transaction_remove_pkg(struct xbps_handle *xhp,
const char *pkgname,
bool recursive)
{
prop_dictionary_t pkgd;
prop_array_t orphans, orphans_pkg, unsorted, reqby;
prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver;
size_t count;
int rv = 0;
assert(pkgname != NULL);
if ((pkgd = xbps_pkgdb_get_pkgd(pkgname, false)) == NULL) {
if ((pkgd = xbps_pkgdb_get_pkgd(xhp, pkgname, false)) == NULL) {
/* pkg not installed */
return ENOENT;
}
@@ -323,7 +331,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
}
prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
orphans = xbps_find_pkg_orphans(orphans_pkg);
orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
prop_object_release(orphans_pkg);
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) {
rv = EINVAL;
@@ -336,7 +344,7 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_set_cstring_nocopy(obj, "transaction", "remove");
prop_array_add(unsorted, obj);
xbps_dbg_printf("%s: added into transaction (remove).\n", pkgver);
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
}
prop_object_release(orphans);
rmpkg:
@@ -346,7 +354,7 @@ rmpkg:
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_set_cstring_nocopy(pkgd, "transaction", "remove");
prop_array_add(unsorted, pkgd);
xbps_dbg_printf("%s: added into transaction (remove).\n", pkgver);
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n", pkgver);
reqby = prop_dictionary_get(pkgd, "requiredby");
/*
* If target pkg is required by any installed pkg, the client must be aware
@@ -363,16 +371,15 @@ out:
}
int
xbps_transaction_autoremove_pkgs(void)
xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp)
{
prop_array_t orphans, unsorted;
prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver;
size_t count;
int rv = 0;
orphans = xbps_find_pkg_orphans(NULL);
orphans = xbps_find_pkg_orphans(xhp, NULL);
if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
return EINVAL;
@@ -397,7 +404,7 @@ xbps_transaction_autoremove_pkgs(void)
prop_dictionary_set_cstring_nocopy(obj,
"transaction", "remove");
prop_array_add(unsorted, obj);
xbps_dbg_printf("%s: added into transaction (remove).\n",
xbps_dbg_printf(xhp, "%s: added into transaction (remove).\n",
pkgver);
}
out:

View File

@@ -34,9 +34,8 @@
#include "xbps_api_impl.h"
int HIDDEN
xbps_transaction_package_replace(prop_dictionary_t transd)
xbps_transaction_package_replace(struct xbps_handle *xhp)
{
struct xbps_handle *xhp = xbps_handle_get();
prop_array_t replaces, instd_reqby, transd_unsorted;
prop_dictionary_t instd, pkg_repod, reppkgd, filesd;
prop_object_t obj;
@@ -46,9 +45,7 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
bool instd_auto, sr;
size_t idx;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
transd_unsorted = prop_dictionary_get(transd, "unsorted_deps");
transd_unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
for (idx = 0; idx < prop_array_count(transd_unsorted); idx++) {
pkg_repod = prop_array_get(transd_unsorted, idx);
@@ -67,14 +64,15 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
* Find the installed package that matches the pattern
* to be replaced.
*/
instd = xbps_find_pkg_dict_installed(pattern, true);
instd =
xbps_find_pkg_dict_installed(xhp, pattern, true);
if (instd == NULL) {
/*
* No package installed has been matched,
* try looking for a virtual package.
*/
instd = xbps_find_virtualpkg_dict_installed(
pattern, true);
xhp, pattern, true);
if (instd == NULL)
continue;
}
@@ -86,14 +84,16 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
"pkgname", &curpkgname);
prop_dictionary_get_cstring_nocopy(instd,
"pkgver", &curpkgver);
xbps_dbg_printf("Package `%s' will be replaced by `%s', "
xbps_dbg_printf(xhp,
"Package `%s' will be replaced by `%s', "
"matched with `%s'\n", curpkgver, pkgver, pattern);
/*
* Check that we are not replacing the same package,
* due to virtual packages.
*/
if (strcmp(pkgname, curpkgname) == 0) {
xbps_dbg_printf("replaced and new package "
xbps_dbg_printf(xhp,
"replaced and new package "
"are equal (%s)\n", pkgname);
prop_object_release(instd);
continue;
@@ -110,7 +110,8 @@ xbps_transaction_package_replace(prop_dictionary_t transd)
reppkgd = xbps_find_pkg_in_array_by_name(
transd_unsorted, curpkgname, NULL);
if (reppkgd) {
xbps_dbg_printf("found replaced pkg "
xbps_dbg_printf(xhp,
"found replaced pkg "
"in transaction\n");
prop_dictionary_set_bool(instd,
"remove-and-update", true);

View File

@@ -147,44 +147,19 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
static void
pkgdep_end(prop_array_t sorted)
{
prop_dictionary_t sorted_pkgd;
struct pkgdep *pd;
const char *trans;
while ((pd = TAILQ_FIRST(&pkgdep_list)) != NULL) {
TAILQ_REMOVE(&pkgdep_list, pd, pkgdep_entries);
if (sorted != NULL && pd->d != NULL) {
/*
* Do not add duplicate pkg dictionaries with the
* same transaction reason into the sorted array.
*/
sorted_pkgd =
xbps_find_pkg_in_array_by_name(sorted, pd->name, NULL);
if (sorted_pkgd == NULL) {
/* find virtualpkg if no match */
sorted_pkgd =
xbps_find_virtualpkg_in_array_by_name(
sorted, pd->name);
}
if (sorted_pkgd == NULL) {
prop_array_add(sorted, pd->d);
pkgdep_release(pd);
continue;
}
prop_dictionary_get_cstring_nocopy(sorted_pkgd,
"transaction", &trans);
if (strcmp(trans, pd->trans) == 0) {
pkgdep_release(pd);
continue;
}
if (sorted != NULL && pd->d != NULL)
prop_array_add(sorted, pd->d);
}
pkgdep_release(pd);
}
}
static int
sort_pkg_rundeps(prop_dictionary_t transd,
sort_pkg_rundeps(struct xbps_handle *xhp,
struct pkgdep *pd,
prop_array_t pkg_rundeps)
{
@@ -196,7 +171,7 @@ sort_pkg_rundeps(prop_dictionary_t transd,
size_t i, idx = 0;
int rv = 0;
xbps_dbg_printf_append("\n");
xbps_dbg_printf_append(xhp, "\n");
curpkgidx = pkgdep_find_idx(pd->name, pd->trans);
again:
@@ -207,17 +182,17 @@ again:
rv = ENOMEM;
break;
}
xbps_dbg_printf(" Required dependency '%s': ", str);
xbps_dbg_printf(xhp, " Required dependency '%s': ", str);
pdn = pkgdep_find(pkgnamedep, NULL);
if ((pdn == NULL) &&
xbps_check_is_installed_pkg_by_pattern(str)) {
xbps_check_is_installed_pkg_by_name(xhp, pkgnamedep)) {
/*
* Package dependency is installed, just add to
* the list but just mark it as "installed", to avoid
* calling xbps_check_is_installed_pkg_by_name(),
* which is expensive.
*/
xbps_dbg_printf_append("installed.\n");
xbps_dbg_printf_append(xhp, "installed.\n");
lpd = pkgdep_alloc(NULL, pkgnamedep, "installed");
if (lpd == NULL) {
rv = ENOMEM;
@@ -231,17 +206,17 @@ again:
* Package was added previously into the list
* and is installed, skip.
*/
xbps_dbg_printf_append("installed.\n");
xbps_dbg_printf_append(xhp, "installed.\n");
free(pkgnamedep);
continue;
}
/* Find pkg by name */
curpkgd = xbps_find_pkg_in_dict_by_name(transd,
curpkgd = xbps_find_pkg_in_dict_by_name(xhp->transd,
"unsorted_deps", pkgnamedep);
if (curpkgd == NULL) {
/* find virtualpkg by name if no match */
curpkgd =
xbps_find_virtualpkg_in_dict_by_name(transd,
xbps_find_virtualpkg_in_dict_by_name(xhp->transd,
"unsorted_deps", pkgnamedep);
}
if (curpkgd == NULL) {
@@ -264,7 +239,7 @@ again:
*/
TAILQ_INSERT_TAIL(&pkgdep_list, lpd, pkgdep_entries);
idx = i;
xbps_dbg_printf_append("added into the tail, "
xbps_dbg_printf_append(xhp, "added into the tail, "
"checking again...\n");
free(pkgnamedep);
goto again;
@@ -279,7 +254,7 @@ again:
*/
free(pkgnamedep);
if (pkgdepidx < curpkgidx) {
xbps_dbg_printf_append("already sorted.\n");
xbps_dbg_printf_append(xhp, "already sorted.\n");
pkgdep_release(lpd);
} else {
/*
@@ -289,7 +264,8 @@ again:
TAILQ_REMOVE(&pkgdep_list, pdn, pkgdep_entries);
pkgdep_release(pdn);
TAILQ_INSERT_BEFORE(pd, lpd, pkgdep_entries);
xbps_dbg_printf_append("added before `%s'.\n", pd->name);
xbps_dbg_printf_append(xhp,
"added before `%s'.\n", pd->name);
}
}
@@ -301,14 +277,12 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
{
prop_array_t sorted, unsorted, rundeps;
prop_object_t obj;
prop_object_iterator_t iter;
struct pkgdep *pd;
size_t ndeps = 0, cnt = 0;
size_t i, ndeps = 0, cnt = 0;
const char *pkgname, *pkgver, *tract;
int rv = 0;
sorted = prop_array_create();
if (sorted == NULL)
if ((sorted = prop_array_create()) == NULL)
return ENOMEM;
/*
* Add sorted packages array into transaction dictionary (empty).
@@ -330,25 +304,16 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
* all objects in the unsorted array.
*/
ndeps = prop_array_count(unsorted);
if (!prop_array_ensure_capacity(sorted, ndeps)) {
xbps_dbg_printf("failed to set capacity to the sorted "
"pkgdeps array\n");
return ENOMEM;
}
iter = prop_array_iterator(unsorted);
if (iter == NULL) {
rv = ENOMEM;
goto out;
}
/*
* Iterate over the unsorted package dictionaries and sort all
* its package dependencies.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
for (i = 0; i < ndeps; i++) {
obj = prop_array_get(unsorted, i);
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
xbps_dbg_printf("Sorting package '%s' (%s): ", pkgver, tract);
xbps_dbg_printf(xhp, "Sorting package '%s' (%s): ", pkgver, tract);
pd = pkgdep_find(pkgname, tract);
if (pd == NULL) {
@@ -358,16 +323,15 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
pd = pkgdep_alloc(obj, pkgname, tract);
if (pd == NULL) {
pkgdep_end(NULL);
prop_object_iterator_release(iter);
rv = ENOMEM;
goto out;
}
if (strcmp(pd->trans, "remove") == 0) {
xbps_dbg_printf_append("added into head.");
xbps_dbg_printf_append(xhp, "added into head.");
TAILQ_INSERT_HEAD(&pkgdep_list, pd,
pkgdep_entries);
} else {
xbps_dbg_printf_append("added into tail.");
xbps_dbg_printf_append(xhp, "added into tail.");
TAILQ_INSERT_TAIL(&pkgdep_list, pd,
pkgdep_entries);
}
@@ -378,21 +342,19 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
*/
rundeps = prop_dictionary_get(obj, "run_depends");
if (rundeps == NULL || prop_array_count(rundeps) == 0) {
xbps_dbg_printf_append("\n");
xbps_dbg_printf_append(xhp, "\n");
cnt++;
continue;
}
/*
* Sort package run-time dependencies for this package.
*/
if ((rv = sort_pkg_rundeps(xhp->transd, pd, rundeps)) != 0) {
if ((rv = sort_pkg_rundeps(xhp, pd, rundeps)) != 0) {
pkgdep_end(NULL);
prop_object_iterator_release(iter);
goto out;
}
cnt++;
}
prop_object_iterator_release(iter);
/*
* We are done, now we have to copy all pkg dictionaries
* from the sorted list into the "packages" array, and at

View File

@@ -60,16 +60,17 @@ xbps_check_is_repository_uri_remote(const char *uri)
}
int
xbps_check_is_installed_pkg_by_pattern(const char *pattern)
xbps_check_is_installed_pkg_by_pattern(struct xbps_handle *xhp,
const char *pattern)
{
prop_dictionary_t dict;
pkg_state_t state;
assert(pattern != NULL);
dict = xbps_find_virtualpkg_dict_installed(pattern, true);
dict = xbps_find_virtualpkg_dict_installed(xhp, pattern, true);
if (dict == NULL) {
dict = xbps_find_pkg_dict_installed(pattern, true);
dict = xbps_find_pkg_dict_installed(xhp, pattern, true);
if (dict == NULL) {
if (errno == ENOENT) {
errno = 0;
@@ -96,14 +97,15 @@ xbps_check_is_installed_pkg_by_pattern(const char *pattern)
}
bool
xbps_check_is_installed_pkg_by_name(const char *pkgname)
xbps_check_is_installed_pkg_by_name(struct xbps_handle *xhp,
const char *pkgname)
{
prop_dictionary_t pkgd;
assert(pkgname != NULL);
if (((pkgd = xbps_find_pkg_dict_installed(pkgname, false)) == NULL) &&
((pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false)) == NULL))
if (((pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false)) == NULL) &&
((pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false)) == NULL))
return false;
prop_object_release(pkgd);
@@ -190,14 +192,14 @@ xbps_pkgpattern_version(const char *pkg)
}
static char *
get_pkg_index_remote_plist(const char *uri, const char *plistf)
get_pkg_index_remote_plist(struct xbps_handle *xhp,
const char *uri,
const char *plistf)
{
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;
@@ -208,30 +210,31 @@ get_pkg_index_remote_plist(const char *uri, const char *plistf)
}
char *
xbps_pkg_index_plist(const char *uri)
xbps_pkg_index_plist(struct xbps_handle *xhp, const char *uri)
{
assert(uri != NULL);
if (xbps_check_is_repository_uri_remote(uri))
return get_pkg_index_remote_plist(uri, XBPS_PKGINDEX);
return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX);
return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX);
}
char *
xbps_pkg_index_files_plist(const char *uri)
xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri)
{
assert(uri != NULL);
if (xbps_check_is_repository_uri_remote(uri))
return get_pkg_index_remote_plist(uri, XBPS_PKGINDEX_FILES);
return get_pkg_index_remote_plist(xhp, uri, XBPS_PKGINDEX_FILES);
return xbps_xasprintf("%s/%s", uri, XBPS_PKGINDEX_FILES);
}
char *
xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
xbps_path_from_repository_uri(struct xbps_handle *xhp,
prop_dictionary_t pkg_repod,
const char *repoloc)
{
struct xbps_handle *xhp;
const char *filen, *arch;
char *lbinpkg = NULL;
@@ -242,7 +245,6 @@ xbps_path_from_repository_uri(prop_dictionary_t pkg_repod, const char *repoloc)
"filename", &filen))
return NULL;
xhp = xbps_handle_get();
/*
* First check if binpkg is available in cachedir.
*/

View File

@@ -174,11 +174,11 @@ xbps_file_hash_dictionary(prop_dictionary_t d,
}
int
xbps_file_hash_check_dictionary(prop_dictionary_t d,
xbps_file_hash_check_dictionary(struct xbps_handle *xhp,
prop_dictionary_t d,
const char *key,
const char *file)
{
struct xbps_handle *xhp = xbps_handle_get();
const char *sha256d = NULL;
char *buf;
int rv;