New pkgdb (0.21) and repo index (1.7) format, see NEWS for info.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2011-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2011-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -74,8 +74,7 @@ void HIDDEN
|
||||
xbps_set_cb_state(struct xbps_handle *xhp,
|
||||
xbps_state_t state,
|
||||
int err,
|
||||
const char *arg0,
|
||||
const char *arg1,
|
||||
const char *arg,
|
||||
const char *fmt,
|
||||
...)
|
||||
{
|
||||
@@ -90,8 +89,7 @@ xbps_set_cb_state(struct xbps_handle *xhp,
|
||||
xscd.xhp = xhp;
|
||||
xscd.state = state;
|
||||
xscd.err = err;
|
||||
xscd.arg0 = arg0;
|
||||
xscd.arg1 = arg1;
|
||||
xscd.arg = arg;
|
||||
if (fmt != NULL) {
|
||||
va_start(va, fmt);
|
||||
retval = vasprintf(&buf, fmt, va);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -64,8 +64,7 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
prop_dictionary_t filesd,
|
||||
struct archive_entry *entry,
|
||||
const char *entry_pname,
|
||||
const char *pkgname,
|
||||
const char *version)
|
||||
const char *pkgver)
|
||||
{
|
||||
prop_dictionary_t forigd;
|
||||
prop_object_t obj, obj2;
|
||||
@@ -77,8 +76,7 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
assert(prop_object_type(filesd) == PROP_TYPE_DICTIONARY);
|
||||
assert(entry != NULL);
|
||||
assert(entry_pname != NULL);
|
||||
assert(pkgname != NULL);
|
||||
assert(version != NULL);
|
||||
assert(pkgver != NULL);
|
||||
|
||||
iter = xbps_array_iter_from_dict(filesd, "conf_files");
|
||||
if (iter == NULL)
|
||||
@@ -88,13 +86,13 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
* Get original hash for the file from current
|
||||
* installed package.
|
||||
*/
|
||||
xbps_dbg_printf(xhp, "%s-%s: processing conf_file %s\n",
|
||||
pkgname, version, entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: processing conf_file %s\n",
|
||||
pkgver, entry_pname);
|
||||
|
||||
forigd = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
|
||||
forigd = xbps_pkgdb_get_pkg_metadata(xhp, pkgver);
|
||||
if (forigd == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently "
|
||||
"installed\n", pkgname, version, entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s not currently "
|
||||
"installed\n", pkgver, entry_pname);
|
||||
rv = 1;
|
||||
goto out;
|
||||
}
|
||||
@@ -120,8 +118,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
* First case: original hash not found, install new file.
|
||||
*/
|
||||
if (sha256_orig == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not installed\n",
|
||||
pkgname, version, entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s not installed\n",
|
||||
pkgver, entry_pname);
|
||||
rv = 1;
|
||||
goto out;
|
||||
}
|
||||
@@ -145,9 +143,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
/*
|
||||
* File not installed, install new one.
|
||||
*/
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not "
|
||||
"installed\n", pkgname, version,
|
||||
entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s not "
|
||||
"installed\n", pkgver, entry_pname);
|
||||
rv = 1;
|
||||
break;
|
||||
} else {
|
||||
@@ -163,9 +160,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
if ((strcmp(sha256_orig, sha256_cur) == 0) &&
|
||||
(strcmp(sha256_orig, sha256_new) == 0) &&
|
||||
(strcmp(sha256_cur, sha256_new) == 0)) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s orig = X, "
|
||||
"cur = X, new = X\n", pkgname, version,
|
||||
entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s orig = X, "
|
||||
"cur = X, new = X\n", pkgver, entry_pname);
|
||||
rv = 0;
|
||||
break;
|
||||
/*
|
||||
@@ -177,9 +173,9 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
(strcmp(sha256_orig, sha256_new)) &&
|
||||
(strcmp(sha256_cur, sha256_new))) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
|
||||
0, pkgname, version,
|
||||
0, pkgver,
|
||||
"Updating configuration file `%s' provided "
|
||||
"by version `%s'.", cffile, version);
|
||||
"by `%s'.", cffile, pkgver);
|
||||
rv = 1;
|
||||
break;
|
||||
/*
|
||||
@@ -193,7 +189,7 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
(strcmp(sha256_cur, sha256_new)) &&
|
||||
(strcmp(sha256_orig, sha256_cur))) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
|
||||
0, pkgname, version,
|
||||
0, pkgver,
|
||||
"Keeping modified configuration file `%s'.",
|
||||
cffile);
|
||||
rv = 0;
|
||||
@@ -207,9 +203,8 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
} else if ((strcmp(sha256_cur, sha256_new) == 0) &&
|
||||
(strcmp(sha256_orig, sha256_new)) &&
|
||||
(strcmp(sha256_orig, sha256_cur))) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s orig = X, "
|
||||
"cur = Y, new = Y\n", pkgname, version,
|
||||
entry_pname);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s orig = X, "
|
||||
"cur = Y, new = Y\n", pkgver, entry_pname);
|
||||
rv = 0;
|
||||
break;
|
||||
/*
|
||||
@@ -220,10 +215,14 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
} else if ((strcmp(sha256_orig, sha256_cur)) &&
|
||||
(strcmp(sha256_cur, sha256_new)) &&
|
||||
(strcmp(sha256_orig, sha256_new))) {
|
||||
const char *version;
|
||||
|
||||
version = xbps_pkg_version(pkgver);
|
||||
assert(version);
|
||||
buf = xbps_xasprintf(".%s.new-%s",
|
||||
cffile, version);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIG_FILE,
|
||||
0, pkgname, version,
|
||||
0, pkgver, version,
|
||||
"Installing new configuration file to "
|
||||
"`%s.new-%s'.", cffile, version);
|
||||
archive_entry_set_pathname(entry, buf);
|
||||
@@ -241,8 +240,8 @@ out:
|
||||
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s returned %d\n",
|
||||
pkgname, version, entry_pname, rv);
|
||||
xbps_dbg_printf(xhp, "%s: conf_file %s returned %d\n",
|
||||
pkgver, entry_pname, rv);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,28 +43,30 @@
|
||||
*
|
||||
* @note
|
||||
* If the \a XBPS_FLAG_FORCE_CONFIGURE is set through xbps_init() in the flags
|
||||
* member, the package (or packages) will be reconfigured even if its
|
||||
member, the package (or packages) will be reconfigured even if its
|
||||
* state is XBPS_PKG_STATE_INSTALLED.
|
||||
*/
|
||||
int
|
||||
xbps_configure_packages(struct xbps_handle *xhp, bool flush)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname;
|
||||
const char *pkgver;
|
||||
int rv;
|
||||
|
||||
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
||||
return rv;
|
||||
|
||||
iter = prop_array_iterator(xhp->pkgdb);
|
||||
iter = prop_dictionary_iterator(xhp->pkgdb);
|
||||
assert(iter);
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
rv = xbps_configure_pkg(xhp, pkgname, true, false, false);
|
||||
pkgd = prop_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
rv = xbps_configure_pkg(xhp, pkgver, true, false, false);
|
||||
if (rv != 0) {
|
||||
xbps_dbg_printf(xhp, "%s: failed to configure %s: %s\n",
|
||||
__func__, pkgname, strerror(rv));
|
||||
__func__, pkgver, strerror(rv));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -78,32 +80,27 @@ xbps_configure_packages(struct xbps_handle *xhp, bool flush)
|
||||
|
||||
int
|
||||
xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
const char *pkgver,
|
||||
bool check_state,
|
||||
bool update,
|
||||
bool flush)
|
||||
{
|
||||
prop_dictionary_t pkgd, pkgmetad;
|
||||
const char *version, *pkgver;
|
||||
char *plist;
|
||||
char *pkgname, *plist;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(pkgver != NULL);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgver);
|
||||
if (pkgd == NULL)
|
||||
return ENOENT;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
|
||||
rv = xbps_pkg_state_dictionary(pkgd, &state);
|
||||
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgname, state, rv);
|
||||
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);
|
||||
if (rv != 0) {
|
||||
xbps_dbg_printf(xhp, "%s: [configure] failed to get "
|
||||
"pkg state: %s\n", pkgname, strerror(rv));
|
||||
prop_object_release(pkgd);
|
||||
"pkg state: %s\n", pkgver, strerror(rv));
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
@@ -115,10 +112,13 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgver, NULL);
|
||||
|
||||
/* internalize pkg dictionary from metadir */
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
plist = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
free(pkgname);
|
||||
pkgmetad = prop_dictionary_internalize_from_file(plist);
|
||||
free(plist);
|
||||
assert(pkgmetad);
|
||||
@@ -126,7 +126,7 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [configure] INSTALL script failed to execute "
|
||||
"the post ACTION: %s", pkgver, strerror(rv));
|
||||
return rv;
|
||||
@@ -139,15 +139,13 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
rv = xbps_set_pkg_state_dictionary(pkgd, XBPS_PKG_STATE_INSTALLED);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE_FAIL, rv,
|
||||
pkgname, version,
|
||||
"%s: [configure] failed to set state to installed: %s",
|
||||
pkgver, "%s: [configure] failed to set state to installed: %s",
|
||||
pkgver, strerror(rv));
|
||||
}
|
||||
if (flush) {
|
||||
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, "%s: [configure] failed to update pkgdb: %s\n",
|
||||
pkgver, strerror(rv));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -31,68 +31,48 @@
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
/**
|
||||
* @file lib/package_register.c
|
||||
* @brief Package registration routines
|
||||
* @defgroup pkg_register Package registration functions
|
||||
*
|
||||
* Register and unregister packages into/from the installed
|
||||
* packages database.
|
||||
*/
|
||||
|
||||
int
|
||||
xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
int HIDDEN
|
||||
xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_array_t provides, rundeps;
|
||||
char outstr[64];
|
||||
time_t t;
|
||||
struct tm *tmp;
|
||||
const char *pkgname, *version, *desc, *pkgver;
|
||||
char *buf, *sha256;
|
||||
const char *desc, *pkgver;
|
||||
char *pkgname = NULL, *buf, *sha256;
|
||||
int rv = 0;
|
||||
bool autoinst = false;
|
||||
|
||||
assert(prop_object_type(pkgrd) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
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);
|
||||
prop_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(pkgrd, "short_desc", &desc);
|
||||
prop_dictionary_get_bool(pkgrd, "automatic-install", &autoinst);
|
||||
provides = prop_dictionary_get(pkgrd, "provides");
|
||||
rundeps = prop_dictionary_get(pkgrd, "run_depends");
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER, 0, pkgver, NULL);
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(version != NULL);
|
||||
assert(desc != NULL);
|
||||
assert(pkgver != NULL);
|
||||
assert(desc != NULL);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgver);
|
||||
if (pkgd == NULL) {
|
||||
rv = ENOENT;
|
||||
goto out;
|
||||
}
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd,
|
||||
"version", version)) {
|
||||
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(xhp, "%s: invalid pkgver for %s\n",
|
||||
__func__, pkgname);
|
||||
__func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd,
|
||||
"short_desc", desc)) {
|
||||
xbps_dbg_printf(xhp, "%s: invalid short_desc for %s\n",
|
||||
__func__, pkgname);
|
||||
__func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -105,7 +85,7 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
if (!prop_dictionary_set_bool(pkgd,
|
||||
"automatic-install", autoinst)) {
|
||||
xbps_dbg_printf(xhp, "%s: invalid autoinst for %s\n",
|
||||
__func__, pkgname);
|
||||
__func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -115,34 +95,31 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
t = time(NULL);
|
||||
if ((tmp = localtime(&t)) == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s: localtime failed: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
pkgver, strerror(errno));
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (strftime(outstr, sizeof(outstr)-1, "%F %R %Z", tmp) == 0) {
|
||||
xbps_dbg_printf(xhp, "%s: strftime failed: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
pkgver, strerror(errno));
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (!prop_dictionary_set_cstring(pkgd, "install-date", outstr)) {
|
||||
xbps_dbg_printf(xhp, "%s: install-date set failed!\n", pkgname);
|
||||
xbps_dbg_printf(xhp, "%s: install-date set failed!\n", pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (provides && !prop_dictionary_set(pkgd, "provides", provides)) {
|
||||
xbps_dbg_printf(xhp, "%s: failed to set provides for %s\n",
|
||||
__func__, pkgname);
|
||||
__func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (rundeps == NULL)
|
||||
rundeps = prop_array_create();
|
||||
|
||||
if (!prop_dictionary_set(pkgd, "run_depends", rundeps)) {
|
||||
if (rundeps && !prop_dictionary_set(pkgd, "run_depends", rundeps)) {
|
||||
xbps_dbg_printf(xhp, "%s: failed to set rundeps for %s\n",
|
||||
__func__, pkgname);
|
||||
__func__, pkgver);
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
@@ -150,6 +127,8 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
/*
|
||||
* Create a hash for the pkg's metafile.
|
||||
*/
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
sha256 = xbps_file_hash(buf);
|
||||
assert(sha256);
|
||||
@@ -163,37 +142,42 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
prop_dictionary_remove(pkgd, "transaction");
|
||||
prop_dictionary_remove(pkgd, "skip-obsoletes");
|
||||
|
||||
if (!xbps_pkgdb_replace_pkg(xhp, pkgd, pkgname, flush)) {
|
||||
if (!prop_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
|
||||
xbps_dbg_printf(xhp,
|
||||
"%s: failed to replace pkgd dict for %s\n",
|
||||
__func__, pkgname);
|
||||
"%s: failed to set pkgd for %s\n", __func__, pkgver);
|
||||
goto out;
|
||||
}
|
||||
(void)xbps_pkgdb_update(xhp, true);
|
||||
|
||||
out:
|
||||
if (pkgname)
|
||||
free(pkgname);
|
||||
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
|
||||
rv, pkgname, version,
|
||||
"%s: failed to register package: %s",
|
||||
rv, pkgver, "%s: failed to register package: %s",
|
||||
pkgver, strerror(rv));
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_unregister_pkg(struct xbps_handle *xhp, const char *pkgver, bool flush)
|
||||
int HIDDEN
|
||||
xbps_unregister_pkg(struct xbps_handle *xhp, const char *pkgver)
|
||||
{
|
||||
char *pkgname;
|
||||
|
||||
assert(xhp);
|
||||
assert(pkgver);
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER, 0, pkgver, NULL, NULL);
|
||||
|
||||
if (!xbps_pkgdb_remove_pkg(xhp, pkgver, flush)) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNREGISTER_FAIL,
|
||||
errno, pkgver, NULL,
|
||||
"%s: failed to unregister package: %s",
|
||||
pkgver, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
prop_dictionary_remove(xhp->pkgdb, pkgname);
|
||||
free(pkgname);
|
||||
|
||||
(void)xbps_pkgdb_update(xhp, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -33,45 +33,7 @@
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
/**
|
||||
* @file lib/package_remove.c
|
||||
* @brief Package removal routines
|
||||
* @defgroup pkg_remove Package removal functions
|
||||
*
|
||||
* These functions will remove a package or only a subset of its
|
||||
* files. Package removal steps:
|
||||
* -# Its <b>pre-remove</b> target specified in the REMOVE script
|
||||
* will be executed.
|
||||
* -# Its links, files, conf_files and dirs will be removed.
|
||||
* Modified files (not matchings its sha256 hash) are preserved, unless
|
||||
* XBPS_FLAG_FORCE_REMOVE_FILES flag is set via xbps_init::flags member.
|
||||
* -# Its <b>post-remove</b> target specified in the REMOVE script
|
||||
* will be executed.
|
||||
* -# Its state will be changed to XBPS_PKG_STATE_HALF_REMOVED.
|
||||
* -# Its <b>purge-remove</b> target specified in the REMOVE script
|
||||
* will be executed.
|
||||
* -# Its package metadata file will be removed.
|
||||
* -# Package will be unregistered from package database.
|
||||
*
|
||||
* @note
|
||||
* -# If a package is going to be updated, only steps <b>1</b> and <b>4</b>
|
||||
* will be executed.
|
||||
* -# If a package is going to be removed, all steps will be executed.
|
||||
*
|
||||
* The following image shows the structure of an internalized package's
|
||||
* files.plist dictionary:
|
||||
*
|
||||
* @image html images/xbps_pkg_files_dictionary.png
|
||||
*
|
||||
* Legend:
|
||||
* - <b>Salmon bg box</b>: XBPS_PKGFILES plist file.
|
||||
* - <b>White bg box</b>: mandatory objects.
|
||||
* - <b>Grey bg box</b>: optional objects.
|
||||
*
|
||||
* Text inside of white boxes are the key associated with the object, its
|
||||
* data type is specified on its edge, i.e string, array, integer, dictionary.
|
||||
*/
|
||||
int
|
||||
int HIDDEN
|
||||
xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
prop_dictionary_t dict,
|
||||
const char *key,
|
||||
@@ -81,7 +43,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
prop_array_t array;
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *file, *sha256, *version, *curobj = NULL;
|
||||
const char *file, *sha256, *curobj = NULL;
|
||||
char *path = NULL, *pkgname = NULL;
|
||||
char buf[PATH_MAX];
|
||||
int rv = 0;
|
||||
@@ -109,7 +71,6 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
version = xbps_pkg_version(pkgver);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "file", &file);
|
||||
@@ -128,7 +89,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
/* missing file, ignore it */
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: failed to check hash for %s `%s': %s",
|
||||
pkgver, curobj, file, strerror(rv));
|
||||
free(path);
|
||||
@@ -140,7 +101,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
XBPS_FLAG_FORCE_REMOVE_FILES) == 0) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
||||
0, pkgname, version,
|
||||
0, pkgver,
|
||||
"%s: %s `%s' SHA256 mismatch, "
|
||||
"preserving file", pkgver,
|
||||
curobj, file);
|
||||
@@ -149,7 +110,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
} else {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
||||
0, pkgname, version,
|
||||
0, pkgver,
|
||||
"%s: %s `%s' SHA256 mismatch, "
|
||||
"forcing removal", pkgver,
|
||||
curobj, file);
|
||||
@@ -157,7 +118,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
} else if (rv != 0 && rv != ERANGE) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_HASH_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [remove] failed to check hash for "
|
||||
"%s `%s': %s", pkgver, curobj, file,
|
||||
strerror(rv));
|
||||
@@ -186,15 +147,14 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
*/
|
||||
if (remove(path) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: failed to remove %s `%s': %s", pkgver,
|
||||
curobj, file, strerror(errno));
|
||||
errno = 0;
|
||||
} else {
|
||||
/* success */
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FILE,
|
||||
0, pkgname, version,
|
||||
"Removed %s `%s'", curobj, file);
|
||||
0, pkgver, "Removed %s `%s'", curobj, file);
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
@@ -204,7 +164,7 @@ xbps_remove_pkg_files(struct xbps_handle *xhp,
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
int HIDDEN
|
||||
xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
const char *pkgver,
|
||||
bool update,
|
||||
@@ -231,12 +191,12 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
pkgver, state);
|
||||
|
||||
if (!update)
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgver, NULL);
|
||||
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
rv = errno;
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [remove] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, xhp->rootdir, strerror(rv));
|
||||
goto out;
|
||||
@@ -248,7 +208,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
free(buf);
|
||||
if (pkgd == NULL)
|
||||
xbps_dbg_printf(xhp, "WARNING: metaplist for %s "
|
||||
"doesn't exist!\n", pkgname);
|
||||
"doesn't exist!\n", pkgver);
|
||||
|
||||
/* If package was "half-removed", remove it fully. */
|
||||
if (state == XBPS_PKG_STATE_HALF_REMOVED)
|
||||
@@ -261,7 +221,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
"pre", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [remove] REMOVE script failed to "
|
||||
"execute pre ACTION: %s",
|
||||
pkgver, strerror(rv));
|
||||
@@ -307,7 +267,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [remove] REMOVE script failed to execute "
|
||||
"post ACTION: %s", pkgver, strerror(rv));
|
||||
goto out;
|
||||
@@ -318,11 +278,11 @@ softreplace:
|
||||
/*
|
||||
* Set package state to "half-removed".
|
||||
*/
|
||||
rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
|
||||
rv = xbps_set_pkg_state_installed(xhp, pkgver,
|
||||
XBPS_PKG_STATE_HALF_REMOVED);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [remove] failed to set state to half-removed: %s",
|
||||
pkgver, strerror(rv));
|
||||
goto out;
|
||||
@@ -336,7 +296,7 @@ purge:
|
||||
rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: REMOVE script failed to execute "
|
||||
"purge ACTION: %s", pkgver, strerror(rv));
|
||||
goto out;
|
||||
@@ -350,7 +310,7 @@ purge:
|
||||
if (remove(buf) == -1) {
|
||||
if (errno != ENOENT) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: failed to remove metadata file: %s",
|
||||
pkgver, strerror(errno));
|
||||
}
|
||||
@@ -359,13 +319,12 @@ purge:
|
||||
/*
|
||||
* Unregister package from pkgdb.
|
||||
*/
|
||||
if ((rv = xbps_unregister_pkg(xhp, pkgver, true)) != 0)
|
||||
if ((rv = xbps_unregister_pkg(xhp, pkgver)) != 0)
|
||||
goto out;
|
||||
|
||||
xbps_dbg_printf(xhp, "[remove] unregister %s returned %d\n", pkgver, rv);
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE,
|
||||
0, pkgname, version, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL);
|
||||
out:
|
||||
if (pkgname != NULL)
|
||||
free(pkgname);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2012-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -35,8 +35,7 @@ int
|
||||
xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
const void *blob,
|
||||
const size_t blobsiz,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
const char *pkgver,
|
||||
const char *action,
|
||||
bool update)
|
||||
{
|
||||
@@ -46,8 +45,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
int fd, rv;
|
||||
|
||||
assert(blob);
|
||||
assert(pkgname);
|
||||
assert(version);
|
||||
assert(pkgver);
|
||||
assert(action);
|
||||
|
||||
if (strcmp(xhp->rootdir, "/") == 0) {
|
||||
@@ -87,7 +85,7 @@ xbps_pkg_exec_buffer(struct xbps_handle *xhp,
|
||||
close(fd);
|
||||
|
||||
/* exec script */
|
||||
rv = xbps_file_exec(xhp, fpath, action, pkgname, version,
|
||||
rv = xbps_file_exec(xhp, fpath, action, pkgver,
|
||||
update ? "yes" : "no",
|
||||
xhp->conffile, NULL);
|
||||
|
||||
@@ -105,7 +103,7 @@ xbps_pkg_exec_script(struct xbps_handle *xhp,
|
||||
bool update)
|
||||
{
|
||||
prop_data_t data;
|
||||
const char *pkgname, *version;
|
||||
const char *pkgver;
|
||||
|
||||
assert(xhp);
|
||||
assert(d);
|
||||
@@ -116,10 +114,8 @@ xbps_pkg_exec_script(struct xbps_handle *xhp,
|
||||
if (data == NULL)
|
||||
return 0;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(d, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
|
||||
|
||||
return xbps_pkg_exec_buffer(xhp, prop_data_data(data),
|
||||
prop_data_size(data), pkgname, version,
|
||||
action, update);
|
||||
prop_data_size(data), pkgver, action, update);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -93,15 +93,15 @@ get_state(prop_dictionary_t dict)
|
||||
|
||||
int
|
||||
xbps_pkg_state_installed(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
const char *pkgver,
|
||||
pkg_state_t *state)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(pkgver != NULL);
|
||||
assert(state != NULL);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgver);
|
||||
if (pkgd == NULL)
|
||||
return ENOENT;
|
||||
|
||||
@@ -133,46 +133,32 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
|
||||
}
|
||||
|
||||
static int
|
||||
set_pkg_objs(prop_dictionary_t pkgd, const char *name, const char *version)
|
||||
set_pkg_objs(prop_dictionary_t pkgd, const char *pkgver)
|
||||
{
|
||||
char *pkgver;
|
||||
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", name))
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgver", pkgver))
|
||||
return EINVAL;
|
||||
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "version", version))
|
||||
return EINVAL;
|
||||
|
||||
pkgver = xbps_xasprintf("%s-%s", name, version);
|
||||
assert(pkgver != NULL);
|
||||
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgver", pkgver)) {
|
||||
free(pkgver);
|
||||
return EINVAL;
|
||||
}
|
||||
free(pkgver);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
const char *pkgname,
|
||||
const char *version,
|
||||
const char *pkgver,
|
||||
pkg_state_t state)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
char *pkgname;
|
||||
int rv = 0;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
assert(pkgver != NULL);
|
||||
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
|
||||
pkgd = xbps_pkgdb_get_pkg(xhp, pkgver);
|
||||
if (pkgd == NULL) {
|
||||
pkgd = prop_dictionary_create();
|
||||
if (pkgd == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0) {
|
||||
if ((rv = set_pkg_objs(pkgd, pkgver)) != 0) {
|
||||
prop_object_release(pkgd);
|
||||
return rv;
|
||||
}
|
||||
@@ -180,17 +166,25 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
prop_object_release(pkgd);
|
||||
return rv;
|
||||
}
|
||||
if (!xbps_add_obj_to_array(xhp->pkgdb, pkgd)) {
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!prop_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
|
||||
prop_object_release(pkgd);
|
||||
free(pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(pkgname);
|
||||
} else {
|
||||
if ((rv = set_new_state(pkgd, state)) != 0)
|
||||
return rv;
|
||||
|
||||
if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
|
||||
pkgd, pkgname)) != 0)
|
||||
return rv;
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
if (!prop_dictionary_set(xhp->pkgdb, pkgname, pkgd)) {
|
||||
free(pkgname);
|
||||
return EINVAL;
|
||||
}
|
||||
free(pkgname);
|
||||
}
|
||||
|
||||
return rv;
|
||||
|
||||
@@ -82,9 +82,11 @@ find_pkg_symlink_target(prop_dictionary_t d, const char *file)
|
||||
static int
|
||||
unpack_archive(struct xbps_handle *xhp,
|
||||
prop_dictionary_t pkg_repod,
|
||||
const char *pkgver,
|
||||
const char *fname,
|
||||
struct archive *ar)
|
||||
{
|
||||
prop_dictionary_t pkg_metad = NULL, filesd = NULL, old_filesd = NULL;
|
||||
prop_dictionary_t pkg_metad, propsd, filesd, old_filesd;
|
||||
prop_array_t array, obsoletes;
|
||||
prop_object_t obj;
|
||||
prop_data_t data;
|
||||
@@ -93,12 +95,10 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
struct stat st;
|
||||
struct xbps_unpack_cb_data xucd;
|
||||
struct archive_entry *entry;
|
||||
size_t i, entry_idx = 0;
|
||||
size_t instbufsiz, rembufsiz;
|
||||
size_t i, entry_idx = 0, instbufsiz, rembufsiz;
|
||||
ssize_t entry_size;
|
||||
const char *file, *entry_pname, *transact, *pkgname;
|
||||
const char *version, *pkgver, *fname, *tgtlnk;
|
||||
char *dname, *buf, *buf2, *p, *p2;
|
||||
const char *file, *entry_pname, *transact, *tgtlnk;
|
||||
char *pkgname, *dname, *buf, *buf2, *p, *p2;
|
||||
int ar_rv, rv, rv_stat, flags;
|
||||
bool preserve, update, conf_file, file_exists, skip_obsoletes;
|
||||
bool softreplace, skip_extract, force;
|
||||
@@ -107,6 +107,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
||||
assert(ar != NULL);
|
||||
|
||||
pkg_metad = propsd = filesd = old_filesd = NULL;
|
||||
force = preserve = update = conf_file = file_exists = false;
|
||||
skip_obsoletes = softreplace = false;
|
||||
|
||||
@@ -115,10 +116,6 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
prop_dictionary_get_bool(pkg_repod, "softreplace", &softreplace);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod,
|
||||
"transaction", &transact);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
|
||||
|
||||
euid = geteuid();
|
||||
|
||||
@@ -141,7 +138,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
}
|
||||
if (chdir(xhp->rootdir) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [unpack] failed to chdir to rootdir `%s': %s",
|
||||
pkgver, xhp->rootdir, strerror(errno));
|
||||
rv = errno;
|
||||
@@ -197,11 +194,11 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
}
|
||||
|
||||
rv = xbps_pkg_exec_buffer(xhp, instbuf, instbufsiz,
|
||||
pkgname, version, "pre", update);
|
||||
pkgver, "pre", update);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [unpack] INSTALL script failed "
|
||||
"to execute pre ACTION: %s",
|
||||
pkgver, strerror(rv));
|
||||
@@ -236,15 +233,18 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
}
|
||||
continue;
|
||||
} else if (strcmp("./props.plist", entry_pname) == 0) {
|
||||
/* ignore this one; we use pkg data from repo index */
|
||||
archive_read_data_skip(ar);
|
||||
propsd = xbps_dictionary_from_archive_entry(ar, entry);
|
||||
if (propsd == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
/*
|
||||
* If XBPS_PKGFILES or XBPS_PKGPROPS weren't found
|
||||
* in the archive at this phase, skip all data.
|
||||
*/
|
||||
if (filesd == NULL) {
|
||||
if (propsd == NULL || filesd == NULL) {
|
||||
archive_read_data_skip(ar);
|
||||
/*
|
||||
* If we have processed 4 entries and the two
|
||||
@@ -254,7 +254,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (entry_idx >= 3) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_UNPACK_FAIL,
|
||||
ENODEV, pkgname, version,
|
||||
ENODEV, pkgver,
|
||||
"%s: [unpack] invalid binary package `%s'.",
|
||||
pkgver, fname);
|
||||
rv = ENODEV;
|
||||
@@ -301,14 +301,13 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
* "conf_files" array on its XBPS_PKGPROPS
|
||||
* dictionary.
|
||||
*/
|
||||
if (xbps_entry_is_a_conf_file(pkg_repod, buf)) {
|
||||
if (xbps_entry_is_a_conf_file(propsd, buf)) {
|
||||
conf_file = true;
|
||||
if (xhp->unpack_cb != NULL)
|
||||
xucd.entry_is_conf = true;
|
||||
|
||||
rv = xbps_entry_install_conf_file(xhp,
|
||||
filesd, entry, entry_pname,
|
||||
pkgname, version);
|
||||
filesd, entry, entry_pname, pkgver);
|
||||
if (rv == -1) {
|
||||
/* error */
|
||||
goto out;
|
||||
@@ -324,10 +323,9 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (rv == -1) {
|
||||
/* error */
|
||||
xbps_dbg_printf(xhp,
|
||||
"%s-%s: failed to check"
|
||||
"%s: failed to check"
|
||||
" hash for `%s': %s\n",
|
||||
pkgname, version,
|
||||
entry_pname,
|
||||
pkgver, entry_pname,
|
||||
strerror(errno));
|
||||
goto out;
|
||||
} else if (rv == 0) {
|
||||
@@ -335,10 +333,10 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
* hash match, skip extraction.
|
||||
*/
|
||||
xbps_dbg_printf(xhp,
|
||||
"%s-%s: file %s "
|
||||
"%s: file %s "
|
||||
"matches existing SHA256, "
|
||||
"skipping...\n", pkgname,
|
||||
version, entry_pname);
|
||||
"skipping...\n",
|
||||
pkgver, entry_pname);
|
||||
skip_extract = true;
|
||||
}
|
||||
}
|
||||
@@ -372,9 +370,9 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
"new: %s\n", pkgver, entry_pname, p, p2);
|
||||
|
||||
if (strcmp(p, p2) == 0) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: symlink "
|
||||
xbps_dbg_printf(xhp, "%s: symlink "
|
||||
"%s matched, skipping...\n",
|
||||
pkgname, version, entry_pname);
|
||||
pkgver, entry_pname);
|
||||
skip_extract = true;
|
||||
}
|
||||
free(buf);
|
||||
@@ -389,17 +387,16 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (chmod(entry_pname,
|
||||
entry_statp->st_mode) != 0) {
|
||||
xbps_dbg_printf(xhp,
|
||||
"%s-%s: failed "
|
||||
"%s: failed "
|
||||
"to set perms %s to %s: %s\n",
|
||||
pkgname, version,
|
||||
archive_entry_strmode(entry),
|
||||
pkgver, archive_entry_strmode(entry),
|
||||
entry_pname,
|
||||
strerror(errno));
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
xbps_dbg_printf(xhp, "%s-%s: entry %s changed file "
|
||||
"mode to %s.\n", pkgname, version, entry_pname,
|
||||
xbps_dbg_printf(xhp, "%s: entry %s changed file "
|
||||
"mode to %s.\n", pkgver, entry_pname,
|
||||
archive_entry_strmode(entry));
|
||||
}
|
||||
/*
|
||||
@@ -412,15 +409,13 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (chown(entry_pname,
|
||||
entry_statp->st_uid, entry_statp->st_gid) != 0) {
|
||||
xbps_dbg_printf(xhp,
|
||||
"%s-%s: failed "
|
||||
"%s: failed "
|
||||
"to set uid/gid to %u:%u (%s)\n",
|
||||
pkgname, version,
|
||||
entry_statp->st_uid, entry_statp->st_gid,
|
||||
pkgver, entry_statp->st_uid, entry_statp->st_gid,
|
||||
strerror(errno));
|
||||
} else {
|
||||
xbps_dbg_printf(xhp, "%s-%s: entry %s changed "
|
||||
"uid/gid to %u:%u.\n", pkgname, version,
|
||||
entry_pname,
|
||||
xbps_dbg_printf(xhp, "%s: entry %s changed "
|
||||
"uid/gid to %u:%u.\n", pkgver, entry_pname,
|
||||
entry_statp->st_uid, entry_statp->st_gid);
|
||||
}
|
||||
}
|
||||
@@ -435,8 +430,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_CONFIG_FILE, 0,
|
||||
pkgname, version,
|
||||
XBPS_STATE_CONFIG_FILE, 0, pkgver,
|
||||
"Renamed old configuration file "
|
||||
"`%s' to `%s.old'.", entry_pname, entry_pname);
|
||||
}
|
||||
@@ -456,7 +450,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (archive_read_extract(ar, entry, flags) != 0) {
|
||||
rv = archive_errno(ar);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver, NULL,
|
||||
"%s: [unpack] failed to extract file `%s': %s",
|
||||
pkgver, entry_pname, strerror(rv));
|
||||
} else {
|
||||
@@ -471,7 +465,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
*/
|
||||
if ((rv = archive_errno(ar)) != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver, NULL,
|
||||
"%s: [unpack] failed to extract files: %s",
|
||||
pkgver, fname, archive_error_string(ar));
|
||||
goto out;
|
||||
@@ -490,7 +484,7 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
* - Package upgrade.
|
||||
* - Package with "softreplace" keyword.
|
||||
*/
|
||||
old_filesd = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
|
||||
old_filesd = xbps_pkgdb_get_pkg_metadata(xhp, pkgver);
|
||||
if (old_filesd == NULL)
|
||||
goto out1;
|
||||
|
||||
@@ -501,21 +495,21 @@ unpack_archive(struct xbps_handle *xhp,
|
||||
if (remove(file) == -1) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_OBSOLETE_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver, NULL,
|
||||
"%s: failed to remove obsolete entry `%s': %s",
|
||||
pkgver, file, strerror(errno));
|
||||
continue;
|
||||
}
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_REMOVE_FILE_OBSOLETE,
|
||||
0, pkgname, version,
|
||||
0, pkgver, NULL,
|
||||
"%s: removed obsolete entry: %s", pkgver, file);
|
||||
prop_object_release(obj);
|
||||
}
|
||||
|
||||
out1:
|
||||
prop_dictionary_make_immutable(pkg_repod);
|
||||
pkg_metad = prop_dictionary_copy_mutable(pkg_repod);
|
||||
prop_dictionary_make_immutable(propsd);
|
||||
pkg_metad = prop_dictionary_copy_mutable(propsd);
|
||||
|
||||
/* Add objects from XBPS_PKGFILES */
|
||||
array = prop_dictionary_get(filesd, "files");
|
||||
@@ -550,6 +544,8 @@ out1:
|
||||
prop_dictionary_remove(pkg_metad, "remove-and-update");
|
||||
prop_dictionary_remove(pkg_metad, "transaction");
|
||||
prop_dictionary_remove(pkg_metad, "state");
|
||||
prop_dictionary_remove(pkg_metad, "pkgname");
|
||||
prop_dictionary_remove(pkg_metad, "version");
|
||||
|
||||
/*
|
||||
* Externalize pkg dictionary to metadir.
|
||||
@@ -562,22 +558,29 @@ out1:
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
buf = xbps_xasprintf("%s/.%s.plist", XBPS_META_PATH, pkgname);
|
||||
if (!prop_dictionary_externalize_to_file(pkg_metad, buf)) {
|
||||
rv = errno;
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [unpack] failed to extract metadata file `%s': %s",
|
||||
pkgver, buf, strerror(errno));
|
||||
free(buf);
|
||||
free(pkgname);
|
||||
goto out;
|
||||
}
|
||||
free(buf);
|
||||
free(pkgname);
|
||||
out:
|
||||
if (prop_object_type(pkg_metad) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(pkg_metad);
|
||||
if (prop_object_type(filesd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(filesd);
|
||||
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(propsd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -586,22 +589,19 @@ int HIDDEN
|
||||
xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
{
|
||||
struct archive *ar = NULL;
|
||||
const char *pkgname, *version, *pkgver;
|
||||
const char *pkgver;
|
||||
char *bpkg;
|
||||
int pkg_fd, rv = 0;
|
||||
|
||||
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK, 0, pkgver, NULL, NULL);
|
||||
|
||||
bpkg = xbps_repository_pkg_path(xhp, pkg_repod);
|
||||
if (bpkg == NULL) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [unpack] cannot determine binary package "
|
||||
"file for `%s': %s", pkgver, bpkg, strerror(errno));
|
||||
return errno;
|
||||
@@ -623,7 +623,7 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
if (pkg_fd == -1) {
|
||||
rv = archive_errno(ar);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [unpack] failed to open binary package `%s': %s",
|
||||
pkgver, bpkg, strerror(rv));
|
||||
free(bpkg);
|
||||
@@ -631,14 +631,13 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
return rv;
|
||||
}
|
||||
archive_read_open_fd(ar, pkg_fd, ARCHIVE_READ_BLOCKSIZE);
|
||||
free(bpkg);
|
||||
|
||||
/*
|
||||
* Extract archive files.
|
||||
*/
|
||||
if ((rv = unpack_archive(xhp, pkg_repod, ar)) != 0) {
|
||||
if ((rv = unpack_archive(xhp, pkg_repod, pkgver, bpkg, ar)) != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [unpack] failed to unpack files from archive: %s",
|
||||
pkgver, strerror(rv));
|
||||
goto out;
|
||||
@@ -646,10 +645,10 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
/*
|
||||
* Set package state to unpacked.
|
||||
*/
|
||||
if ((rv = xbps_set_pkg_state_installed(xhp, pkgname, version,
|
||||
if ((rv = xbps_set_pkg_state_installed(xhp, pkgver,
|
||||
XBPS_PKG_STATE_UNPACKED)) != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [unpack] failed to set state to unpacked: %s",
|
||||
pkgver, strerror(rv));
|
||||
}
|
||||
@@ -657,6 +656,8 @@ out:
|
||||
close(pkg_fd);
|
||||
if (ar)
|
||||
archive_read_free(ar);
|
||||
if (bpkg)
|
||||
free(bpkg);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
170
lib/pkgdb.c
170
lib/pkgdb.c
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2012-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -79,7 +79,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
|
||||
int
|
||||
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
|
||||
{
|
||||
prop_array_t pkgdb_storage;
|
||||
prop_dictionary_t pkgdb_storage;
|
||||
char *plist;
|
||||
static int cached_rv;
|
||||
int rv = 0;
|
||||
@@ -89,11 +89,11 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
|
||||
|
||||
plist = xbps_xasprintf("%s/%s", xhp->metadir, XBPS_PKGDB);
|
||||
if (xhp->pkgdb && flush) {
|
||||
pkgdb_storage = prop_array_internalize_from_zfile(plist);
|
||||
pkgdb_storage = prop_dictionary_internalize_from_file(plist);
|
||||
if (pkgdb_storage == NULL ||
|
||||
!prop_array_equals(xhp->pkgdb, pkgdb_storage)) {
|
||||
!prop_dictionary_equals(xhp->pkgdb, pkgdb_storage)) {
|
||||
/* flush dictionary to storage */
|
||||
if (!prop_array_externalize_to_file(xhp->pkgdb, plist)) {
|
||||
if (!prop_dictionary_externalize_to_file(xhp->pkgdb, plist)) {
|
||||
free(plist);
|
||||
return errno;
|
||||
}
|
||||
@@ -106,9 +106,9 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush)
|
||||
cached_rv = 0;
|
||||
}
|
||||
/* update copy in memory */
|
||||
if ((xhp->pkgdb = prop_array_internalize_from_zfile(plist)) == NULL) {
|
||||
if ((xhp->pkgdb = prop_dictionary_internalize_from_file(plist)) == NULL) {
|
||||
if (errno == ENOENT)
|
||||
xhp->pkgdb = prop_array_create();
|
||||
xhp->pkgdb = prop_dictionary_create();
|
||||
else
|
||||
xbps_error_printf("cannot access to pkgdb: %s\n", strerror(errno));
|
||||
|
||||
@@ -135,31 +135,33 @@ xbps_pkgdb_release(struct xbps_handle *xhp)
|
||||
xbps_dbg_printf(xhp, "[pkgdb] released ok.\n");
|
||||
}
|
||||
|
||||
static int
|
||||
foreach_pkg_cb(struct xbps_handle *xhp,
|
||||
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
|
||||
void *arg,
|
||||
bool reverse)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
||||
return rv;
|
||||
|
||||
if (reverse)
|
||||
rv = xbps_callback_array_iter_reverse(xhp, xhp->pkgdb, fn, arg);
|
||||
else
|
||||
rv = xbps_callback_array_iter(xhp, xhp->pkgdb, fn, arg);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
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(xhp, fn, arg, true);
|
||||
prop_array_t allkeys;
|
||||
prop_object_t obj;
|
||||
prop_dictionary_t pkgd;
|
||||
size_t i;
|
||||
int rv;
|
||||
bool done = false;
|
||||
|
||||
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
||||
return rv;
|
||||
|
||||
allkeys = prop_dictionary_all_keys(xhp->pkgdb);
|
||||
assert(allkeys);
|
||||
|
||||
for (i = prop_array_count(allkeys); i > 0; i--) {
|
||||
obj = prop_array_get(allkeys, i);
|
||||
pkgd = prop_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
rv = (*fn)(xhp, pkgd, arg, &done);
|
||||
if (rv != 0 || done)
|
||||
break;
|
||||
}
|
||||
prop_object_release(allkeys);
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -167,7 +169,25 @@ xbps_pkgdb_foreach_cb(struct xbps_handle *xhp,
|
||||
int (*fn)(struct xbps_handle *, prop_object_t, void *, bool *),
|
||||
void *arg)
|
||||
{
|
||||
return foreach_pkg_cb(xhp, fn, arg, false);
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
prop_dictionary_t pkgd;
|
||||
int rv;
|
||||
bool done = false;
|
||||
|
||||
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
||||
return rv;
|
||||
|
||||
iter = prop_dictionary_iterator(xhp->pkgdb);
|
||||
assert(iter);
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
pkgd = prop_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
rv = (*fn)(xhp, pkgd, arg, &done);
|
||||
if (rv != 0 || done)
|
||||
break;
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
return rv;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
@@ -176,7 +196,7 @@ xbps_pkgdb_get_pkg(struct xbps_handle *xhp, const char *pkg)
|
||||
if (xbps_pkgdb_init(xhp) != 0)
|
||||
return NULL;
|
||||
|
||||
return xbps_find_pkg_in_array(xhp->pkgdb, pkg);
|
||||
return xbps_find_pkg_in_dict(xhp->pkgdb, pkg);
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
@@ -185,28 +205,32 @@ xbps_pkgdb_get_virtualpkg(struct xbps_handle *xhp, const char *vpkg)
|
||||
if (xbps_pkgdb_init(xhp) != 0)
|
||||
return NULL;
|
||||
|
||||
return xbps_find_virtualpkg_in_array(xhp, xhp->pkgdb, vpkg);
|
||||
return xbps_find_virtualpkg_in_dict(xhp, xhp->pkgdb, vpkg);
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
get_pkg_metadata(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
||||
{
|
||||
prop_dictionary_t pkg_metad;
|
||||
const char *pkgname;
|
||||
char *plist;
|
||||
const char *pkgver;
|
||||
char *pkgname, *plist;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
if ((pkg_metad = prop_dictionary_get(xhp->pkg_metad, pkgname)) != NULL)
|
||||
if ((pkg_metad = prop_dictionary_get(xhp->pkg_metad, pkgname)) != NULL) {
|
||||
free(pkgname);
|
||||
return pkg_metad;
|
||||
|
||||
}
|
||||
plist = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
pkg_metad = prop_dictionary_internalize_from_zfile(plist);
|
||||
pkg_metad = prop_dictionary_internalize_from_file(plist);
|
||||
free(plist);
|
||||
|
||||
if (pkg_metad == NULL) {
|
||||
xbps_dbg_printf(xhp, "[pkgdb] cannot read %s metadata: %s\n",
|
||||
pkgname, strerror(errno));
|
||||
pkgver, strerror(errno));
|
||||
free(pkgname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -215,6 +239,7 @@ get_pkg_metadata(struct xbps_handle *xhp, prop_dictionary_t pkgd)
|
||||
|
||||
prop_dictionary_set(xhp->pkg_metad, pkgname, pkg_metad);
|
||||
prop_object_release(pkg_metad);
|
||||
free(pkgname);
|
||||
|
||||
return pkg_metad;
|
||||
}
|
||||
@@ -223,7 +248,7 @@ static void
|
||||
generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_array_t rundeps, pkg;
|
||||
prop_dictionary_t pkgmetad;
|
||||
prop_dictionary_t pkgmetad, pkgd;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgver, *pkgdep, *vpkgname;
|
||||
@@ -236,17 +261,18 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
|
||||
xhp->pkgdb_revdeps = prop_dictionary_create();
|
||||
|
||||
iter = prop_array_iterator(xhp->pkgdb);
|
||||
iter = prop_dictionary_iterator(xhp->pkgdb);
|
||||
assert(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
pkgd = prop_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
/*
|
||||
* If run_depends is in pkgdb use it, otherwise fallback to
|
||||
* the slower pkg metadata method.
|
||||
*/
|
||||
rundeps = prop_dictionary_get(obj, "run_depends");
|
||||
rundeps = prop_dictionary_get(pkgd, "run_depends");
|
||||
if (rundeps == NULL) {
|
||||
pkgmetad = get_pkg_metadata(xhp, obj);
|
||||
pkgmetad = get_pkg_metadata(xhp, pkgd);
|
||||
assert(pkgmetad);
|
||||
rundeps = prop_dictionary_get(pkgmetad, "run_depends");
|
||||
}
|
||||
@@ -269,7 +295,7 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
alloc = true;
|
||||
pkg = prop_array_create();
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
prop_array_add_cstring_nocopy(pkg, pkgver);
|
||||
prop_dictionary_set(xhp->pkgdb_revdeps, vpkgname, pkg);
|
||||
free(curpkgname);
|
||||
@@ -283,16 +309,21 @@ generate_full_revdeps_tree(struct xbps_handle *xhp)
|
||||
prop_array_t
|
||||
xbps_pkgdb_get_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
|
||||
{
|
||||
prop_array_t res;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *pkgname;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
|
||||
if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkg)) == NULL)
|
||||
return NULL;
|
||||
|
||||
generate_full_revdeps_tree(xhp);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
res = prop_dictionary_get(xhp->pkgdb_revdeps, pkgname);
|
||||
free(pkgname);
|
||||
|
||||
return prop_dictionary_get(xhp->pkgdb_revdeps, pkgname);
|
||||
return res;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
@@ -306,52 +337,3 @@ xbps_pkgdb_get_pkg_metadata(struct xbps_handle *xhp, const char *pkg)
|
||||
|
||||
return get_pkg_metadata(xhp, pkgd);
|
||||
}
|
||||
|
||||
bool
|
||||
xbps_pkgdb_remove_pkg(struct xbps_handle *xhp, const char *pkg, bool flush)
|
||||
{
|
||||
bool rv = false;
|
||||
|
||||
if (xbps_pkgdb_init(xhp) != 0)
|
||||
return false;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
rv = xbps_remove_pkg_from_array_by_pattern(xhp->pkgdb, pkg);
|
||||
else if (xbps_pkg_version(pkg))
|
||||
rv = xbps_remove_pkg_from_array_by_pkgver(xhp->pkgdb, pkg);
|
||||
else
|
||||
rv = xbps_remove_pkg_from_array_by_name(xhp->pkgdb, pkg);
|
||||
|
||||
if (!flush || !rv)
|
||||
return rv;
|
||||
|
||||
if ((xbps_pkgdb_update(xhp, true)) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
xbps_pkgdb_replace_pkg(struct xbps_handle *xhp,
|
||||
prop_dictionary_t pkgd,
|
||||
const char *pkg,
|
||||
bool flush)
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (xbps_pkgdb_init(xhp) != 0)
|
||||
return false;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
rv = xbps_array_replace_dict_by_pattern(xhp->pkgdb, pkgd, pkg);
|
||||
else
|
||||
rv = xbps_array_replace_dict_by_name(xhp->pkgdb, pkgd, pkg);
|
||||
|
||||
if (!flush)
|
||||
return rv != 0 ? false : true;
|
||||
|
||||
if ((xbps_pkgdb_update(xhp, true)) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
26
lib/plist.c
26
lib/plist.c
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -121,7 +121,7 @@ xbps_callback_array_iter_in_dict(struct xbps_handle *xhp,
|
||||
|
||||
array = prop_dictionary_get(dict, key);
|
||||
if (prop_object_type(array) != PROP_TYPE_ARRAY)
|
||||
return EINVAL;
|
||||
return ENOENT;
|
||||
|
||||
for (i = 0; i < prop_array_count(array); i++) {
|
||||
obj = prop_array_get(array, i);
|
||||
@@ -213,7 +213,8 @@ array_replace_dict(prop_array_t array,
|
||||
{
|
||||
prop_object_t obj;
|
||||
size_t i;
|
||||
const char *curpkgname;
|
||||
const char *curpkgver;
|
||||
char *curpkgname;
|
||||
|
||||
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
|
||||
assert(prop_object_type(dict) == PROP_TYPE_DICTIONARY);
|
||||
@@ -226,8 +227,8 @@ array_replace_dict(prop_array_t array,
|
||||
if (bypattern) {
|
||||
/* pkgpattern match */
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &curpkgname);
|
||||
if (xbps_pkgpattern_match(curpkgname, str)) {
|
||||
"pkgver", &curpkgver);
|
||||
if (xbps_pkgpattern_match(curpkgver, str)) {
|
||||
if (!prop_array_set(array, i, dict))
|
||||
return EINVAL;
|
||||
|
||||
@@ -236,13 +237,18 @@ array_replace_dict(prop_array_t array,
|
||||
} else {
|
||||
/* pkgname match */
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &curpkgname);
|
||||
"pkgver", &curpkgver);
|
||||
curpkgname = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgname);
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
if (!prop_array_set(array, i, dict))
|
||||
if (!prop_array_set(array, i, dict)) {
|
||||
free(curpkgname);
|
||||
return EINVAL;
|
||||
|
||||
}
|
||||
free(curpkgname);
|
||||
return 0;
|
||||
}
|
||||
free(curpkgname);
|
||||
}
|
||||
}
|
||||
/* no match */
|
||||
@@ -252,9 +258,9 @@ array_replace_dict(prop_array_t array,
|
||||
int HIDDEN
|
||||
xbps_array_replace_dict_by_name(prop_array_t array,
|
||||
prop_dictionary_t dict,
|
||||
const char *pkgname)
|
||||
const char *pkgver)
|
||||
{
|
||||
return array_replace_dict(array, dict, pkgname, false);
|
||||
return array_replace_dict(array, dict, pkgver, false);
|
||||
}
|
||||
|
||||
int HIDDEN
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg (at) NetBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -190,7 +190,6 @@ xbps_get_pkg_plist_from_binpkg(const char *fname, const char *plistf)
|
||||
|
||||
break;
|
||||
}
|
||||
archive_read_close(a);
|
||||
archive_read_free(a);
|
||||
|
||||
return plistd;
|
||||
|
||||
179
lib/plist_find.c
179
lib/plist_find.c
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -36,7 +36,8 @@ get_pkg_in_array(prop_array_t array, const char *str, bool virtual)
|
||||
{
|
||||
prop_object_t obj = NULL;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgver, *dpkgn;
|
||||
const char *pkgver;
|
||||
char *dpkgn;
|
||||
bool found = false;
|
||||
|
||||
iter = prop_array_iterator(array);
|
||||
@@ -76,12 +77,16 @@ get_pkg_in_array(prop_array_t array, const char *str, bool virtual)
|
||||
} else {
|
||||
/* match by pkgname */
|
||||
if (!prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &dpkgn))
|
||||
"pkgver", &pkgver))
|
||||
continue;
|
||||
dpkgn = xbps_pkg_name(pkgver);
|
||||
assert(dpkgn);
|
||||
if (strcmp(dpkgn, str) == 0) {
|
||||
free(dpkgn);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
free(dpkgn);
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
@@ -121,3 +126,171 @@ xbps_find_virtualpkg_in_array(struct xbps_handle *x,
|
||||
|
||||
return get_pkg_in_array(a, s, true);
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
match_pkg_by_pkgver(prop_dictionary_t repod, const char *p)
|
||||
{
|
||||
prop_dictionary_t d = NULL;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
|
||||
/* exact match by pkgver */
|
||||
if ((pkgname = xbps_pkg_name(p)) == NULL)
|
||||
return NULL;
|
||||
|
||||
d = prop_dictionary_get(repod, pkgname);
|
||||
if (d) {
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
|
||||
if (strcmp(pkgver, p))
|
||||
d = NULL;
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
match_pkg_by_pattern(prop_dictionary_t repod, const char *p)
|
||||
{
|
||||
prop_dictionary_t d = NULL;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
|
||||
/* match by pkgpattern in pkgver */
|
||||
if ((pkgname = xbps_pkgpattern_name(p)) == NULL) {
|
||||
if ((pkgname = xbps_pkg_name(p)))
|
||||
return match_pkg_by_pkgver(repod, p);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = prop_dictionary_get(repod, pkgname);
|
||||
if (d) {
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
|
||||
assert(pkgver);
|
||||
if (!xbps_pkgpattern_match(pkgver, p))
|
||||
d = NULL;
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
const char HIDDEN *
|
||||
vpkg_user_conf(struct xbps_handle *xhp,
|
||||
const char *vpkg,
|
||||
bool bypattern)
|
||||
{
|
||||
const char *vpkgver, *pkg = NULL;
|
||||
char *vpkgname = NULL, *tmp;
|
||||
size_t i, j, cnt;
|
||||
|
||||
if (xhp->cfg == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((cnt = cfg_size(xhp->cfg, "virtual-package")) == 0) {
|
||||
/* no virtual packages configured */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
cfg_t *sec = cfg_getnsec(xhp->cfg, "virtual-package", i);
|
||||
for (j = 0; j < cfg_size(sec, "targets"); j++) {
|
||||
tmp = NULL;
|
||||
vpkgver = cfg_getnstr(sec, "targets", j);
|
||||
if (strchr(vpkgver, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", vpkgver);
|
||||
vpkgname = xbps_pkg_name(tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
}
|
||||
if (vpkgname == NULL)
|
||||
break;
|
||||
if (bypattern) {
|
||||
if (!xbps_pkgpattern_match(vpkgver, vpkg)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (strcmp(vpkg, vpkgname)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* virtual package matched in conffile */
|
||||
pkg = cfg_title(sec);
|
||||
xbps_dbg_printf(xhp,
|
||||
"matched vpkg in conf `%s' for %s\n",
|
||||
pkg, vpkg);
|
||||
free(vpkgname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_find_virtualpkg_in_dict(struct xbps_handle *xhp,
|
||||
prop_dictionary_t d,
|
||||
const char *pkg)
|
||||
{
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
const char *vpkg;
|
||||
bool found = false, bypattern = false;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
bypattern = true;
|
||||
|
||||
/* Try matching vpkg from configuration files */
|
||||
vpkg = vpkg_user_conf(xhp, pkg, bypattern);
|
||||
if (vpkg != NULL) {
|
||||
if (xbps_pkgpattern_version(vpkg))
|
||||
pkgd = match_pkg_by_pattern(d, vpkg);
|
||||
else if (xbps_pkg_version(vpkg))
|
||||
pkgd = match_pkg_by_pkgver(d, vpkg);
|
||||
else
|
||||
pkgd = prop_dictionary_get(d, vpkg);
|
||||
|
||||
if (pkgd) {
|
||||
found = true;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* ... otherwise match the first one in dictionary */
|
||||
iter = prop_dictionary_iterator(d);
|
||||
assert(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
pkgd = prop_dictionary_get_keysym(d, obj);
|
||||
if (xbps_match_virtual_pkg_in_dict(pkgd, pkg, bypattern)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
out:
|
||||
if (found)
|
||||
return pkgd;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_find_pkg_in_dict(prop_dictionary_t d, const char *pkg)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
pkgd = match_pkg_by_pattern(d, pkg);
|
||||
else if (xbps_pkg_version(pkg))
|
||||
pkgd = match_pkg_by_pkgver(d, pkg);
|
||||
else
|
||||
pkgd = prop_dictionary_get(d, pkg);
|
||||
|
||||
return pkgd;
|
||||
}
|
||||
|
||||
157
lib/rindex_get.c
157
lib/rindex_get.c
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2012-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -36,152 +36,13 @@
|
||||
* @brief Repository index functions
|
||||
* @defgroup rindex Repository index functions
|
||||
*/
|
||||
static prop_dictionary_t
|
||||
match_pkg_by_pkgver(prop_dictionary_t repod, const char *p)
|
||||
{
|
||||
prop_dictionary_t d = NULL;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
|
||||
/* exact match by pkgver */
|
||||
if ((pkgname = xbps_pkg_name(p)) == NULL)
|
||||
return NULL;
|
||||
|
||||
d = prop_dictionary_get(repod, pkgname);
|
||||
if (d) {
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
|
||||
if (strcmp(pkgver, p))
|
||||
d = NULL;
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
match_pkg_by_pattern(prop_dictionary_t repod, const char *p)
|
||||
{
|
||||
prop_dictionary_t d = NULL;
|
||||
const char *pkgver;
|
||||
char *pkgname;
|
||||
|
||||
/* match by pkgpattern in pkgver */
|
||||
if ((pkgname = xbps_pkgpattern_name(p)) == NULL) {
|
||||
if ((pkgname = xbps_pkg_name(p)))
|
||||
return match_pkg_by_pkgver(repod, p);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = prop_dictionary_get(repod, pkgname);
|
||||
if (d) {
|
||||
prop_dictionary_get_cstring_nocopy(d, "pkgver", &pkgver);
|
||||
assert(pkgver);
|
||||
if (!xbps_pkgpattern_match(pkgver, p))
|
||||
d = NULL;
|
||||
}
|
||||
|
||||
free(pkgname);
|
||||
return d;
|
||||
}
|
||||
|
||||
const char HIDDEN *
|
||||
vpkg_user_conf(struct xbps_handle *xhp,
|
||||
const char *vpkg,
|
||||
bool bypattern)
|
||||
{
|
||||
const char *vpkgver, *pkg = NULL;
|
||||
char *vpkgname = NULL, *tmp;
|
||||
size_t i, j, cnt;
|
||||
|
||||
if (xhp->cfg == NULL)
|
||||
return NULL;
|
||||
|
||||
if ((cnt = cfg_size(xhp->cfg, "virtual-package")) == 0) {
|
||||
/* no virtual packages configured */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < cnt; i++) {
|
||||
cfg_t *sec = cfg_getnsec(xhp->cfg, "virtual-package", i);
|
||||
for (j = 0; j < cfg_size(sec, "targets"); j++) {
|
||||
tmp = NULL;
|
||||
vpkgver = cfg_getnstr(sec, "targets", j);
|
||||
if (strchr(vpkgver, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", vpkgver);
|
||||
vpkgname = xbps_pkg_name(tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
}
|
||||
if (vpkgname == NULL)
|
||||
break;
|
||||
if (bypattern) {
|
||||
if (!xbps_pkgpattern_match(vpkgver, vpkg)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (strcmp(vpkg, vpkgname)) {
|
||||
free(vpkgname);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
/* virtual package matched in conffile */
|
||||
pkg = cfg_title(sec);
|
||||
xbps_dbg_printf(xhp,
|
||||
"matched vpkg in conf `%s' for %s\n",
|
||||
pkg, vpkg);
|
||||
free(vpkgname);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pkg;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_rindex_get_virtualpkg(struct xbps_rindex *rpi, const char *pkg)
|
||||
{
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
const char *vpkg;
|
||||
bool found = false, bypattern = false;
|
||||
prop_dictionary_t pkgd;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
bypattern = true;
|
||||
|
||||
/* Try matching vpkg from configuration files */
|
||||
vpkg = vpkg_user_conf(rpi->xhp, pkg, bypattern);
|
||||
if (vpkg != NULL) {
|
||||
if (xbps_pkgpattern_version(vpkg))
|
||||
pkgd = match_pkg_by_pattern(rpi->repod, vpkg);
|
||||
else if (xbps_pkg_version(vpkg))
|
||||
pkgd = match_pkg_by_pkgver(rpi->repod, vpkg);
|
||||
else
|
||||
pkgd = prop_dictionary_get(rpi->repod, vpkg);
|
||||
|
||||
if (pkgd) {
|
||||
found = true;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
/* ... otherwise match the first one in dictionary */
|
||||
iter = prop_dictionary_iterator(rpi->repod);
|
||||
assert(iter);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
pkgd = prop_dictionary_get_keysym(rpi->repod, obj);
|
||||
if (xbps_match_virtual_pkg_in_dict(pkgd, pkg, bypattern)) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
out:
|
||||
if (found) {
|
||||
pkgd = xbps_find_virtualpkg_in_dict(rpi->xhp, rpi->repod, pkg);
|
||||
if (pkgd) {
|
||||
prop_dictionary_set_cstring_nocopy(pkgd,
|
||||
"repository", rpi->uri);
|
||||
return pkgd;
|
||||
@@ -192,15 +53,9 @@ out:
|
||||
prop_dictionary_t
|
||||
xbps_rindex_get_pkg(struct xbps_rindex *rpi, const char *pkg)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
|
||||
if (xbps_pkgpattern_version(pkg))
|
||||
pkgd = match_pkg_by_pattern(rpi->repod, pkg);
|
||||
else if (xbps_pkg_version(pkg))
|
||||
pkgd = match_pkg_by_pkgver(rpi->repod, pkg);
|
||||
else
|
||||
pkgd = prop_dictionary_get(rpi->repod, pkg);
|
||||
prop_dictionary_t pkgd;
|
||||
|
||||
pkgd = xbps_find_pkg_in_dict(rpi->repod, pkg);
|
||||
if (pkgd) {
|
||||
prop_dictionary_set_cstring_nocopy(pkgd,
|
||||
"repository", rpi->uri);
|
||||
|
||||
@@ -158,8 +158,8 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
prop_array_t curpkgrdeps;
|
||||
pkg_state_t state;
|
||||
size_t x;
|
||||
const char *reqpkg, *reqpkgname, *pkgver_q, *reason = NULL;
|
||||
char *pkgname;
|
||||
const char *reqpkg, *pkgver_q, *reason = NULL;
|
||||
char *pkgname, *reqpkgname;
|
||||
int rv = 0;
|
||||
|
||||
if (*depth >= MAX_DEPTH)
|
||||
@@ -317,8 +317,8 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"pkgver", &pkgver_q);
|
||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||
"pkgname", &reqpkgname);
|
||||
reqpkgname = xbps_pkg_name(pkgver_q);
|
||||
assert(reqpkgname);
|
||||
/*
|
||||
* Check dependency validity.
|
||||
*/
|
||||
@@ -329,9 +329,11 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
"%s (depends on itself)]\n",
|
||||
reqpkg);
|
||||
free(pkgname);
|
||||
free(reqpkgname);
|
||||
continue;
|
||||
}
|
||||
free(pkgname);
|
||||
free(reqpkgname);
|
||||
|
||||
/*
|
||||
* Check if package has matched conflicts.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -193,6 +193,7 @@ xbps_rpool_get_pkg_plist(struct xbps_handle *xhp,
|
||||
const char *plistf)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL, plistd = NULL;
|
||||
const char *repo;
|
||||
char *url;
|
||||
|
||||
assert(pkg != NULL);
|
||||
@@ -206,8 +207,8 @@ xbps_rpool_get_pkg_plist(struct xbps_handle *xhp,
|
||||
* This will work locally and remotely, thanks to libarchive and
|
||||
* libfetch!
|
||||
*/
|
||||
pkgd = xbps_rpool_get_pkg(xhp, pkg);
|
||||
if (pkgd == NULL)
|
||||
if (((pkgd = xbps_rpool_get_pkg(xhp, pkg)) == NULL) &&
|
||||
((pkgd = xbps_rpool_get_virtualpkg(xhp, pkg)) == NULL))
|
||||
goto out;
|
||||
|
||||
url = xbps_repository_pkg_path(xhp, pkgd);
|
||||
@@ -216,6 +217,10 @@ xbps_rpool_get_pkg_plist(struct xbps_handle *xhp,
|
||||
goto out;
|
||||
}
|
||||
plistd = xbps_get_pkg_plist_from_binpkg(url, plistf);
|
||||
if (plistd) {
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "repository", &repo);
|
||||
prop_dictionary_set_cstring_nocopy(plistd, "repository", repo);
|
||||
}
|
||||
free(url);
|
||||
|
||||
out:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -60,9 +60,8 @@ static int
|
||||
check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filen, *sha256, *trans;
|
||||
const char *pkgname, *version;
|
||||
char *binfile;
|
||||
const char *pkgver, *arch, *repoloc, *sha256, *trans;
|
||||
char *binfile, *filen;
|
||||
int rv = 0;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
@@ -71,11 +70,9 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
(strcmp(trans, "configure") == 0))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"filename-sha256", &sha256);
|
||||
|
||||
@@ -84,18 +81,22 @@ check_binpkgs_hash(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
rv = EINVAL;
|
||||
break;
|
||||
}
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver, filen,
|
||||
filen = xbps_xasprintf("%s.%s.xbps", pkgver, arch);
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY, 0, pkgver,
|
||||
"Verifying `%s' package integrity...", filen, repoloc);
|
||||
rv = xbps_file_hash_check(binfile, sha256);
|
||||
if (rv != 0) {
|
||||
free(binfile);
|
||||
free(filen);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_VERIFY_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"Failed to verify `%s' package integrity: %s",
|
||||
filen, strerror(rv));
|
||||
break;
|
||||
}
|
||||
free(binfile);
|
||||
free(filen);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
@@ -106,9 +107,8 @@ static int
|
||||
download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
{
|
||||
prop_object_t obj;
|
||||
const char *pkgver, *repoloc, *filen, *trans;
|
||||
const char *pkgname, *version, *fetchstr;
|
||||
char *binfile;
|
||||
const char *pkgver, *arch, *fetchstr, *repoloc, *trans;
|
||||
char *binfile, *filen;
|
||||
int rv = 0;
|
||||
bool state_dload = false;
|
||||
|
||||
@@ -118,11 +118,9 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
(strcmp(trans, "configure") == 0))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repoloc);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
|
||||
|
||||
binfile = xbps_repository_pkg_path(xhp, obj);
|
||||
if (binfile == NULL) {
|
||||
@@ -142,7 +140,7 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
if (access(xhp->cachedir, R_OK|X_OK|W_OK) == -1) {
|
||||
if (xbps_mkpath(xhp->cachedir, 0755) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [trans] cannot create cachedir `%s':"
|
||||
"%s", pkgver, xhp->cachedir,
|
||||
strerror(errno));
|
||||
@@ -153,24 +151,25 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
}
|
||||
if (state_dload == false) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_DOWNLOAD,
|
||||
0, NULL, NULL, NULL);
|
||||
0, NULL, NULL);
|
||||
state_dload = true;
|
||||
}
|
||||
filen = xbps_xasprintf("%s.%s.xbps", pkgver, arch);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD,
|
||||
0, pkgname, version,
|
||||
"Downloading binary package `%s' (from `%s')...",
|
||||
0, pkgver, "Downloading binary package `%s' (from `%s')...",
|
||||
filen, repoloc);
|
||||
/*
|
||||
* Fetch binary package.
|
||||
*/
|
||||
if (chdir(xhp->cachedir) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
|
||||
errno, pkgname, version,
|
||||
errno, pkgver,
|
||||
"%s: [trans] failed to change dir to cachedir"
|
||||
"`%s': %s", pkgver, xhp->cachedir,
|
||||
strerror(errno));
|
||||
rv = errno;
|
||||
free(binfile);
|
||||
free(filen);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -179,15 +178,16 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
|
||||
fetchstr = xbps_fetch_error_string();
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_DOWNLOAD_FAIL,
|
||||
fetchLastErrCode != 0 ? fetchLastErrCode : errno,
|
||||
pkgname, version,
|
||||
"%s: [trans] failed to download binary package "
|
||||
pkgver, "%s: [trans] failed to download binary package "
|
||||
"`%s' from `%s': %s", pkgver, filen, repoloc,
|
||||
fetchstr ? fetchstr : strerror(errno));
|
||||
free(binfile);
|
||||
free(filen);
|
||||
break;
|
||||
}
|
||||
rv = 0;
|
||||
free(binfile);
|
||||
free(filen);
|
||||
}
|
||||
prop_object_iterator_reset(iter);
|
||||
|
||||
@@ -199,7 +199,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *version, *pkgver, *tract;
|
||||
const char *pkgver, *tract;
|
||||
int rv = 0;
|
||||
bool update, install, sr;
|
||||
|
||||
@@ -217,20 +217,18 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
/*
|
||||
* Check SHA256 hashes for binary packages in transaction.
|
||||
*/
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_VERIFY, 0, 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(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_RUN, 0, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
update = false;
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
|
||||
if (strcmp(tract, "remove") == 0) {
|
||||
@@ -245,14 +243,14 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
rv = xbps_remove_pkg(xhp, pkgver, update, sr);
|
||||
if (rv != 0) {
|
||||
xbps_dbg_printf(xhp, "[trans] failed to "
|
||||
"remove %s-%s\n", pkgname, version);
|
||||
"remove %s\n", pkgver);
|
||||
goto out;
|
||||
}
|
||||
} else if (strcmp(tract, "configure") == 0) {
|
||||
/*
|
||||
* Reconfigure pending package.
|
||||
*/
|
||||
rv = xbps_configure_pkg(xhp, pkgname, false, false, false);
|
||||
rv = xbps_configure_pkg(xhp, pkgver, false, false, false);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
} else {
|
||||
@@ -264,27 +262,27 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
else
|
||||
install = true;
|
||||
|
||||
if (update && xbps_pkgdb_get_pkg(xhp, pkgname)) {
|
||||
if (update && xbps_pkgdb_get_pkg(xhp, pkgver)) {
|
||||
/*
|
||||
* Update a package: execute pre-remove
|
||||
* action if found before unpacking.
|
||||
*/
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UPDATE, 0,
|
||||
pkgname, version, NULL);
|
||||
pkgver, NULL);
|
||||
rv = xbps_remove_pkg(xhp, pkgver, true, false);
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp,
|
||||
XBPS_STATE_UPDATE_FAIL,
|
||||
rv, pkgname, version,
|
||||
rv, pkgver,
|
||||
"%s: [trans] failed to update "
|
||||
"package to `%s': %s", pkgver,
|
||||
version, strerror(rv));
|
||||
"package `%s'", pkgver,
|
||||
strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
} else {
|
||||
/* Install a package */
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_INSTALL,
|
||||
0, pkgname, version, NULL);
|
||||
0, pkgver, NULL);
|
||||
}
|
||||
/*
|
||||
* Unpack binary package.
|
||||
@@ -294,7 +292,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
/*
|
||||
* Register package.
|
||||
*/
|
||||
if ((rv = xbps_register_pkg(xhp, obj, true)) != 0)
|
||||
if ((rv = xbps_register_pkg(xhp, obj)) != 0)
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -307,7 +305,7 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
/*
|
||||
* Configure all unpacked packages.
|
||||
*/
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL);
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter)) != NULL) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
||||
@@ -315,16 +313,15 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
(strcmp(tract, "configure") == 0))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
update = false;
|
||||
if (strcmp(tract, "update") == 0)
|
||||
update = true;
|
||||
|
||||
rv = xbps_configure_pkg(xhp, pkgname, false, update, true);
|
||||
rv = xbps_configure_pkg(xhp, pkgver, false, update, true);
|
||||
if (rv != 0) {
|
||||
xbps_dbg_printf(xhp, "%s: configure failed for "
|
||||
"%s-%s: %s\n", pkgname, version, strerror(rv));
|
||||
"%s: %s\n", pkgver, strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
@@ -333,10 +330,10 @@ xbps_transaction_commit(struct xbps_handle *xhp)
|
||||
*/
|
||||
if (update) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_UPDATE_DONE, 0,
|
||||
pkgname, version, NULL);
|
||||
pkgver, NULL);
|
||||
} else {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_INSTALL_DONE, 0,
|
||||
pkgname, version, NULL);
|
||||
pkgver, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -61,7 +61,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
uint64_t tsize, dlsize, instsize, rmsize;
|
||||
uint32_t inst_pkgcnt, up_pkgcnt, cf_pkgcnt, rm_pkgcnt;
|
||||
int rv = 0;
|
||||
const char *tract, *pkgname, *repo;
|
||||
const char *tract, *pkgver, *repo;
|
||||
|
||||
inst_pkgcnt = up_pkgcnt = cf_pkgcnt = rm_pkgcnt = 0;
|
||||
tsize = dlsize = instsize = rmsize = 0;
|
||||
@@ -75,7 +75,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
* Count number of pkgs to be removed, configured,
|
||||
* installed and updated.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract);
|
||||
prop_dictionary_get_cstring_nocopy(obj, "repository", &repo);
|
||||
|
||||
@@ -97,7 +97,7 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
*/
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
(strcmp(tract, "update") == 0)) {
|
||||
pkg_metad = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
|
||||
pkg_metad = xbps_pkgdb_get_pkg_metadata(xhp, pkgver);
|
||||
if (pkg_metad == NULL)
|
||||
continue;
|
||||
prop_dictionary_get_uint64(pkg_metad,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -60,9 +60,10 @@ enum {
|
||||
static int
|
||||
trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action)
|
||||
{
|
||||
prop_dictionary_t pkg_pkgdb, pkg_repod;
|
||||
prop_dictionary_t pkg_pkgdb = NULL, pkg_repod;
|
||||
prop_array_t unsorted;
|
||||
const char *pkgname, *repoloc, *repover, *repopkgver, *instver, *reason;
|
||||
const char *repoloc, *repover, *repopkgver, *instpkgver, *reason;
|
||||
char *pkgname;
|
||||
int rv = 0;
|
||||
pkg_state_t state = 0;
|
||||
|
||||
@@ -88,29 +89,35 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action)
|
||||
return ENOENT;
|
||||
}
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &repover);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver);
|
||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
||||
|
||||
pkgname = xbps_pkg_name(repopkgver);
|
||||
assert(pkgname);
|
||||
repover = xbps_pkg_version(repopkgver);
|
||||
assert(repover);
|
||||
|
||||
if (action == TRANS_UPDATE) {
|
||||
/*
|
||||
* Compare installed version vs best pkg available in repos.
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(pkg_pkgdb,
|
||||
"version", &instver);
|
||||
if (xbps_cmpver(repover, instver) <= 0) {
|
||||
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
|
||||
"(installed: %s-%s) from repository `%s'\n",
|
||||
pkgname, repover, pkgname, instver, repoloc);
|
||||
"pkgver", &instpkgver);
|
||||
if (xbps_cmpver(repopkgver, instpkgver) <= 0) {
|
||||
xbps_dbg_printf(xhp, "[rpool] Skipping `%s' "
|
||||
"(installed: %s) from repository `%s'\n",
|
||||
repopkgver, instpkgver, repoloc);
|
||||
free(pkgname);
|
||||
return EEXIST;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Prepare transaction dictionary.
|
||||
*/
|
||||
if ((rv = xbps_transaction_init(xhp)) != 0)
|
||||
if ((rv = xbps_transaction_init(xhp)) != 0) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
|
||||
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
||||
/*
|
||||
@@ -126,24 +133,33 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action)
|
||||
if (xbps_find_pkg_in_array(unsorted, repopkgver)) {
|
||||
xbps_dbg_printf(xhp, "[update] `%s' already queued in "
|
||||
"transaction.\n", repopkgver);
|
||||
free(pkgname);
|
||||
return EEXIST;
|
||||
}
|
||||
}
|
||||
|
||||
if ((rv = xbps_repository_find_deps(xhp, unsorted, pkg_repod)) != 0)
|
||||
if ((rv = xbps_repository_find_deps(xhp, unsorted, pkg_repod)) != 0) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
/*
|
||||
* Set package state in dictionary with same state than the
|
||||
* package currently uses, otherwise not-installed.
|
||||
*/
|
||||
if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) {
|
||||
if (rv != ENOENT)
|
||||
if (rv != ENOENT) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
/* Package not installed, don't error out */
|
||||
state = XBPS_PKG_STATE_NOT_INSTALLED;
|
||||
}
|
||||
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0)
|
||||
free(pkgname);
|
||||
|
||||
if ((rv = xbps_set_pkg_state_dictionary(pkg_repod, state)) != 0) {
|
||||
free(pkgname);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if ((action == TRANS_INSTALL) && (state == XBPS_PKG_STATE_UNPACKED))
|
||||
reason = "configure";
|
||||
@@ -165,8 +181,8 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action)
|
||||
if (!prop_array_add(unsorted, pkg_repod))
|
||||
return EINVAL;
|
||||
|
||||
xbps_dbg_printf(xhp, "%s-%s: added into the transaction (%s).\n",
|
||||
pkgname, repover, repoloc);
|
||||
xbps_dbg_printf(xhp, "%s: added into the transaction (%s).\n",
|
||||
repopkgver, repoloc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -174,9 +190,11 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, int action)
|
||||
int
|
||||
xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pkgname, *holdpkg;
|
||||
const char *pkgver, *holdpkg;
|
||||
char *pkgname;
|
||||
bool foundhold = false, newpkg_found = false;
|
||||
int rv = 0;
|
||||
size_t x;
|
||||
@@ -184,11 +202,31 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
if ((rv = xbps_pkgdb_init(xhp)) != 0)
|
||||
return rv;
|
||||
|
||||
iter = prop_array_iterator(xhp->pkgdb);
|
||||
iter = prop_dictionary_iterator(xhp->pkgdb);
|
||||
assert(iter);
|
||||
|
||||
/*
|
||||
* Check if there's a new update for XBPS before starting
|
||||
* a full system upgrade.
|
||||
*/
|
||||
if (xbps_pkgdb_get_pkg(xhp, "xbps")) {
|
||||
if (trans_find_pkg(xhp, "xbps", TRANS_UPDATE) == 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_XBPS_UPDATE, 0, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (xbps_pkgdb_get_pkg(xhp, "xbps-git")) {
|
||||
if (trans_find_pkg(xhp, "xbps-git", TRANS_UPDATE) == 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_XBPS_UPDATE, 0, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
|
||||
pkgd = prop_dictionary_get_keysym(xhp->pkgdb, obj);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
|
||||
for (x = 0; x < cfg_size(xhp->cfg, "PackagesOnHold"); x++) {
|
||||
holdpkg = cfg_getnstr(xhp->cfg, "PackagesOnHold", x);
|
||||
@@ -214,6 +252,7 @@ xbps_transaction_update_packages(struct xbps_handle *xhp)
|
||||
*/
|
||||
rv = 0;
|
||||
}
|
||||
free(pkgname);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2011-2012 Juan Romero Pardines.
|
||||
* Copyright (c) 2011-2013 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -40,8 +40,8 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
prop_dictionary_t instd, reppkgd, filesd;
|
||||
prop_object_t obj, obj2;
|
||||
prop_object_iterator_t iter;
|
||||
const char *pattern, *pkgname, *curpkgname, *pkgver, *curpkgver;
|
||||
char *buf;
|
||||
const char *pattern, *pkgver, *curpkgver;
|
||||
char *buf, *pkgname, *curpkgname;
|
||||
bool instd_auto, sr;
|
||||
size_t i;
|
||||
|
||||
@@ -66,20 +66,23 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL))
|
||||
continue;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgname", &pkgname);
|
||||
prop_dictionary_get_cstring_nocopy(obj,
|
||||
"pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(instd,
|
||||
"pkgname", &curpkgname);
|
||||
prop_dictionary_get_cstring_nocopy(instd,
|
||||
"pkgver", &curpkgver);
|
||||
pkgname = xbps_pkg_name(pkgver);
|
||||
assert(pkgname);
|
||||
curpkgname = xbps_pkg_name(curpkgver);
|
||||
assert(curpkgver);
|
||||
/*
|
||||
* Check that we are not replacing the same package,
|
||||
* due to virtual packages.
|
||||
*/
|
||||
if (strcmp(pkgname, curpkgname) == 0)
|
||||
if (strcmp(pkgname, curpkgname) == 0) {
|
||||
free(pkgname);
|
||||
free(curpkgname);
|
||||
continue;
|
||||
}
|
||||
|
||||
xbps_dbg_printf(xhp,
|
||||
"Package `%s' will be replaced by `%s', "
|
||||
@@ -126,15 +129,17 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
"softreplace", true);
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, curpkgname);
|
||||
filesd = prop_dictionary_internalize_from_zfile(buf);
|
||||
filesd = prop_dictionary_internalize_from_file(buf);
|
||||
free(buf);
|
||||
assert(filesd != NULL);
|
||||
buf = xbps_xasprintf("%s/.%s.plist",
|
||||
xhp->metadir, pkgname);
|
||||
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
|
||||
if (!prop_dictionary_externalize_to_file(filesd, buf)) {
|
||||
free(buf);
|
||||
prop_object_release(filesd);
|
||||
prop_object_iterator_release(iter);
|
||||
free(pkgname);
|
||||
free(curpkgname);
|
||||
return errno;
|
||||
}
|
||||
prop_object_release(filesd);
|
||||
@@ -147,6 +152,8 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
prop_dictionary_set_cstring_nocopy(instd,
|
||||
"transaction", "remove");
|
||||
prop_array_add(unsorted, instd);
|
||||
free(pkgname);
|
||||
free(curpkgname);
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
}
|
||||
|
||||
12
lib/util.c
12
lib/util.c
@@ -217,14 +217,17 @@ xbps_pkg_index_files_plist(struct xbps_handle *xhp, const char *uri)
|
||||
char HIDDEN *
|
||||
xbps_repository_pkg_path(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
{
|
||||
const char *filen, *repoloc;
|
||||
const char *pkgver, *arch, *repoloc;
|
||||
char *lbinpkg = NULL;
|
||||
|
||||
assert(xhp);
|
||||
assert(prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
|
||||
"filename", &filen))
|
||||
"pkgver", &pkgver))
|
||||
return NULL;
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
|
||||
"architecture", &arch))
|
||||
return NULL;
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg_repod,
|
||||
"repository", &repoloc))
|
||||
@@ -234,7 +237,8 @@ xbps_repository_pkg_path(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
/*
|
||||
* First check if binpkg is available in cachedir.
|
||||
*/
|
||||
lbinpkg = xbps_xasprintf("%s/%s", xhp->cachedir, filen);
|
||||
lbinpkg = xbps_xasprintf("%s/%s.%s.xbps", xhp->cachedir,
|
||||
pkgver, arch);
|
||||
if (access(lbinpkg, R_OK) == 0)
|
||||
return lbinpkg;
|
||||
|
||||
@@ -243,7 +247,7 @@ xbps_repository_pkg_path(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
/*
|
||||
* Local and remote repositories use the same path.
|
||||
*/
|
||||
return xbps_xasprintf("%s/%s", repoloc, filen);
|
||||
return xbps_xasprintf("%s/%s.%s.xbps", repoloc, pkgver, arch);
|
||||
}
|
||||
|
||||
bool
|
||||
|
||||
Reference in New Issue
Block a user