Major API/ABI cleanup bringing performance improvements and fixes.

These are the core interfaces in the new API:

rpool - Interface to interact with the repository pool.
rindex - Interface to interact with repository indexes.
pkgdb - Interface to interact with local packages.
transaction - Interface to interact with a transaction.

This also brings new repository index format, making the index file
per architecture and being incompatible with previous versions.

The transaction frequency flush option has been removed, and due to
the nature of package states it was causing more harm than good.

More changes coming soon, but the API shall remain stable from now on.
This commit is contained in:
Juan RP
2012-11-30 07:11:51 +01:00
parent 16e18313da
commit 63c1883201
57 changed files with 1437 additions and 2640 deletions

View File

@@ -419,7 +419,7 @@ create_dot_graph(struct xbps_handle *xhp,
* list file, aka XBPS_META_PATH/XBPS_PKGDB.
*/
if (revdeps) {
regpkgd = xbps_find_pkg_dict_installed(xhp, pkgn, false);
regpkgd = xbps_pkgdb_get_pkg(xhp, pkgn);
if (regpkgd == NULL)
die("cannot find '%s' dictionary on %s!",
pkgn, XBPS_PKGDB);
@@ -510,7 +510,7 @@ main(int argc, char **argv)
/*
* Internalize the plist file of the target installed package.
*/
plistd = xbps_metadir_get_pkgd(&xh, argv[0]);
plistd = xbps_pkgdb_get_pkg_metadata(&xh, argv[0]);
if (plistd == NULL)
die("cannot internalize %s metadata file", argv[0]);

View File

@@ -45,22 +45,14 @@ bool yesno(const char *, ...);
bool noyes(const char *, ...);
/* from fetch_cb.c */
void fetch_file_progress_cb(struct xbps_handle *,
struct xbps_fetch_cb_data *,
void *);
void fetch_file_progress_cb(struct xbps_fetch_cb_data *, void *);
/* from state_cb.c */
void state_cb(struct xbps_handle *,
struct xbps_state_cb_data *,
void *);
void state_cb(struct xbps_state_cb_data *, void *);
/* from unpack_cb.c */
void unpack_progress_cb_verbose(struct xbps_handle *,
struct xbps_unpack_cb_data *,
void *);
void unpack_progress_cb(struct xbps_handle *,
struct xbps_unpack_cb_data *,
void *);
void unpack_progress_cb_verbose(struct xbps_unpack_cb_data *, void *);
void unpack_progress_cb(struct xbps_unpack_cb_data *, void *);
/* From util.c */
void print_package_line(const char *, size_t, bool);

View File

@@ -150,15 +150,11 @@ stat_display(struct xbps_fetch_cb_data *xfpd, void *cbdata)
}
void
fetch_file_progress_cb(struct xbps_handle *xhp,
struct xbps_fetch_cb_data *xfpd,
void *cbdata)
fetch_file_progress_cb(struct xbps_fetch_cb_data *xfpd, void *cbdata)
{
struct xferstat *xfer = cbdata;
char size[8];
(void)xhp;
if (xfpd->cb_start) {
/* start transfer stats */
get_time(&xfer->start);

View File

@@ -31,9 +31,7 @@
#include "defs.h"
void
state_cb(struct xbps_handle *xhp,
struct xbps_state_cb_data *xscd,
void *cbdata)
state_cb(struct xbps_state_cb_data *xscd, void *cbdata)
{
prop_dictionary_t pkgd;
const char *version;
@@ -41,7 +39,7 @@ state_cb(struct xbps_handle *xhp,
(void)cbdata;
if (xhp->flags & XBPS_FLAG_SYSLOG) {
if (xscd->xhp->flags & XBPS_FLAG_SYSLOG) {
syslog_enabled = true;
openlog("xbps-install", LOG_CONS, LOG_USER);
}
@@ -88,7 +86,7 @@ state_cb(struct xbps_handle *xhp,
/* empty */
break;
case XBPS_STATE_UPDATE:
pkgd = xbps_find_pkg_dict_installed(xhp, xscd->arg0, false);
pkgd = xbps_pkgdb_get_pkg(xscd->xhp, xscd->arg0);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
printf("%s-%s: updating to %s ...\n", xscd->arg0,
version, xscd->arg1);
@@ -96,7 +94,7 @@ state_cb(struct xbps_handle *xhp,
/* success */
case XBPS_STATE_REMOVE_FILE:
case XBPS_STATE_REMOVE_FILE_OBSOLETE:
if (xhp->flags & XBPS_FLAG_VERBOSE)
if (xscd->xhp->flags & XBPS_FLAG_VERBOSE)
printf("%s\n", xscd->desc);
else {
printf("%s\n", xscd->desc);
@@ -109,7 +107,7 @@ state_cb(struct xbps_handle *xhp,
if (syslog_enabled)
syslog(LOG_NOTICE, "Installed `%s-%s' successfully "
"(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir);
xscd->xhp->rootdir);
break;
case XBPS_STATE_UPDATE_DONE:
printf("%s-%s: updated successfully.\n",
@@ -117,7 +115,7 @@ state_cb(struct xbps_handle *xhp,
if (syslog_enabled)
syslog(LOG_NOTICE, "Updated `%s' to `%s' successfully "
"(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir);
xscd->xhp->rootdir);
break;
case XBPS_STATE_REMOVE_DONE:
printf("%s-%s: removed successfully.\n",
@@ -125,7 +123,7 @@ state_cb(struct xbps_handle *xhp,
if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully "
"(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir);
xscd->xhp->rootdir);
break;
/* errors */
case XBPS_STATE_UNPACK_FAIL:
@@ -154,7 +152,7 @@ state_cb(struct xbps_handle *xhp,
syslog(LOG_ERR, "%s", xscd->desc);
break;
default:
xbps_dbg_printf(xhp,
xbps_dbg_printf(xscd->xhp,
"unknown state %d\n", xscd->state);
break;
}

View File

@@ -30,11 +30,8 @@
#include "defs.h"
void
unpack_progress_cb_verbose(struct xbps_handle *xhp,
struct xbps_unpack_cb_data *xpd,
void *cbdata)
unpack_progress_cb_verbose(struct xbps_unpack_cb_data *xpd, void *cbdata)
{
(void)xhp;
(void)cbdata;
if (xpd->entry == NULL || xpd->entry_total_count <= 0)
@@ -47,11 +44,8 @@ unpack_progress_cb_verbose(struct xbps_handle *xhp,
}
void
unpack_progress_cb(struct xbps_handle *xhp,
struct xbps_unpack_cb_data *xpd,
void *cbdata)
unpack_progress_cb(struct xbps_unpack_cb_data *xpd, void *cbdata)
{
(void)xhp;
(void)cbdata;
if (xpd->entry_total_count <= 0)

View File

@@ -101,11 +101,10 @@ check_pkg_integrity(struct xbps_handle *xhp,
/* find real pkg by name */
opkgd = pkgd;
if (pkgd == NULL) {
opkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
opkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
if (opkgd == NULL) {
/* find virtual pkg by name */
opkgd = xbps_find_virtualpkg_dict_installed(xhp,
pkgname, false);
opkgd = xbps_pkgdb_get_virtualpkg(xhp, pkgname);
}
if (opkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
@@ -115,7 +114,7 @@ check_pkg_integrity(struct xbps_handle *xhp,
/*
* Check for props.plist metadata file.
*/
propsd = xbps_metadir_get_pkgd(xhp, pkgname);
propsd = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
if (propsd == NULL) {
printf("%s: unexistent metafile, converting to 0.18 "
"format...\n", pkgname);

View File

@@ -59,7 +59,7 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
* Internalize current pkg props dictionary from its
* installed metadata directory.
*/
curpkg_propsd = xbps_metadir_get_pkgd(xhp, curpkgn);
curpkg_propsd = xbps_pkgdb_get_pkg_metadata(xhp, curpkgn);
if (curpkg_propsd == NULL) {
xbps_error_printf("%s: missing %s metadata file!\n",
curpkgn, XBPS_PKGPROPS);
@@ -138,26 +138,24 @@ remove_stale_entries_in_reqby(struct xbps_handle *xhp, prop_dictionary_t pkgd)
char *str;
size_t i;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
again:
reqby = prop_dictionary_get(pkgd, "requiredby");
if (reqby == NULL || prop_array_count(reqby) == 0)
return;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
for (i = 0; i < prop_array_count(reqby); i++) {
prop_array_get_cstring(reqby, i, &str);
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL)
if ((pkgd = xbps_pkgdb_get_pkg(xhp, str)) != NULL)
continue;
if (!xbps_remove_string_from_array(xhp, reqby, str))
fprintf(stderr, "%s: failed to remove %s from "
"requiredby!\n", pkgver, str);
else
printf("%s: removed stale entry in requiredby `%s'\n",
pkgver, str);
prop_array_remove(reqby, i);
printf("%s: removed stale entry in requiredby `%s'\n",
pkgver, str);
prop_dictionary_set(pkgd, "requiredby", reqby);
free(str);
goto again;
}
}

View File

@@ -48,30 +48,22 @@ int
check_pkg_rundeps(struct xbps_handle *xhp, const char *pkgname, void *arg)
{
prop_dictionary_t pkg_propsd = arg;
prop_object_t obj;
prop_object_iterator_t iter;
prop_array_t array;
size_t i;
const char *reqpkg;
bool test_broken = false;
if (!xbps_pkg_has_rundeps(pkg_propsd))
return 0;
iter = xbps_array_iter_from_dict(pkg_propsd, "run_depends");
if (iter == NULL)
return -1;
while ((obj = prop_object_iterator_next(iter))) {
reqpkg = prop_string_cstring_nocopy(obj);
if (reqpkg == NULL) {
prop_object_iterator_release(iter);
return -1;
}
if (xbps_check_is_installed_pkg_by_pattern(xhp, reqpkg) <= 0) {
array = prop_dictionary_get(pkg_propsd, "run_depends");
for (i = 0; i < prop_array_count(array); i++) {
prop_array_get_cstring_nocopy(array, i, &reqpkg);
if (xbps_pkg_is_installed(xhp, reqpkg) <= 0) {
xbps_error_printf("%s: dependency not satisfied: %s\n",
pkgname, reqpkg);
test_broken = true;
}
}
prop_object_iterator_release(iter);
return test_broken;
}

View File

@@ -158,17 +158,13 @@ list_pkgs_pkgdb(struct xbps_handle *xhp)
}
static int
repo_list_uri_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
repo_list_uri_cb(struct xbps_rindex *rpi, void *arg, bool *done)
{
(void)xhp;
(void)arg;
(void)done;
printf("%s (%zu packages)\n", rpi->uri,
(size_t)prop_array_count(rpi->repo));
(size_t)prop_dictionary_count(rpi->repod));
return 0;
}
@@ -187,21 +183,32 @@ repo_list(struct xbps_handle *xhp)
return 0;
}
struct fflongest {
prop_dictionary_t d;
size_t len;
};
static int
_find_longest_pkgver_cb(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
{
size_t *len = arg;
struct fflongest *ffl = arg;
prop_dictionary_t pkgd;
const char *pkgver;
(void)xhp;
(void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
if (*len == 0 || strlen(pkgver) > *len)
*len = strlen(pkgver);
if (prop_object_type(obj) == PROP_TYPE_DICT_KEYSYM)
pkgd = prop_dictionary_get_keysym(ffl->d, obj);
else
pkgd = obj;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
if (ffl->len == 0 || strlen(pkgver) > ffl->len)
ffl->len = strlen(pkgver);
return 0;
}
@@ -209,16 +216,24 @@ _find_longest_pkgver_cb(struct xbps_handle *xhp,
size_t
find_longest_pkgver(struct xbps_handle *xhp, prop_object_t o)
{
size_t len = 0;
struct fflongest ffl;
if (prop_object_type(o) == PROP_TYPE_ARRAY)
(void)xbps_callback_array_iter(xhp, o,
_find_longest_pkgver_cb, &len);
else
ffl.d = o;
ffl.len = 0;
if (prop_object_type(o) == PROP_TYPE_DICTIONARY) {
prop_array_t array;
array = prop_dictionary_all_keys(o);
(void)xbps_callback_array_iter(xhp, array,
_find_longest_pkgver_cb, &ffl);
prop_object_release(array);
} else {
(void)xbps_pkgdb_foreach_cb(xhp,
_find_longest_pkgver_cb, &len);
_find_longest_pkgver_cb, &ffl);
}
return len;
return ffl.len;
}
int

View File

@@ -95,7 +95,7 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp, prop_object_t obj, void *arg, bool *do
(void)done;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
pkgmetad = xbps_metadir_get_pkgd(xhp, pkgname);
pkgmetad = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
files_keys = prop_dictionary_all_keys(pkgmetad);
for (i = 0; i < prop_array_count(files_keys); i++) {
@@ -122,26 +122,21 @@ ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
}
static void
repo_match_files_by_pattern(struct xbps_handle *xhp,
prop_dictionary_t pkg_filesd,
repo_match_files_by_pattern(prop_dictionary_t pkgd,
struct ffdata *ffd)
{
prop_array_t array;
const char *filestr, *pkgver, *arch;
const char *filestr, *pkgver;
size_t i;
int x;
prop_dictionary_get_cstring_nocopy(pkg_filesd, "architecture", &arch);
if (!xbps_pkg_arch_match(xhp, arch, NULL))
return;
array = prop_dictionary_get(pkg_filesd, "files");
array = prop_dictionary_get(pkgd, "files");
for (i = 0; i < prop_array_count(array); i++) {
prop_array_get_cstring_nocopy(array, i, &filestr);
for (x = 0; x < ffd->npatterns; x++) {
if ((xbps_pkgpattern_match(filestr, ffd->patterns[x])) ||
(strcmp(filestr, ffd->patterns[x]) == 0)) {
prop_dictionary_get_cstring_nocopy(pkg_filesd,
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
printf("%s: %s (%s)\n",
pkgver, filestr, ffd->repouri);
@@ -151,22 +146,21 @@ repo_match_files_by_pattern(struct xbps_handle *xhp,
}
static int
repo_ownedby_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
repo_ownedby_cb(struct xbps_rindex *rpi, void *arg, bool *done)
{
prop_array_t idxfiles;
prop_array_t allkeys;
prop_dictionary_t pkgd, idxfiles;
prop_dictionary_keysym_t ksym;
struct ffdata *ffd = arg;
char *plist;
unsigned int i;
(void)done;
if ((plist = xbps_pkg_index_files_plist(xhp, rpi->uri)) == NULL)
if ((plist = xbps_pkg_index_files_plist(rpi->xhp, rpi->uri)) == NULL)
return ENOMEM;
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) {
if ((idxfiles = prop_dictionary_internalize_from_zfile(plist)) == NULL) {
free(plist);
if (errno == ENOENT) {
fprintf(stderr, "%s: index-files missing! "
@@ -178,11 +172,13 @@ repo_ownedby_cb(struct xbps_handle *xhp,
free(plist);
ffd->repouri = rpi->uri;
for (i = 0; i < prop_array_count(idxfiles); i++)
repo_match_files_by_pattern(xhp,
prop_array_get(idxfiles, i), ffd);
allkeys = prop_dictionary_all_keys(idxfiles);
for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(idxfiles, ksym);
repo_match_files_by_pattern(pkgd, ffd);
}
prop_object_release(idxfiles);
return 0;
}
@@ -195,8 +191,10 @@ repo_ownedby(struct xbps_handle *xhp, int npatterns, char **patterns)
ffd.npatterns = npatterns;
ffd.patterns = patterns;
if ((rv = xbps_rpool_sync(xhp, XBPS_PKGINDEX_FILES, NULL)) != 0)
if ((rv = xbps_rpool_sync(xhp, XBPS_PKGINDEX_FILES, NULL)) != 0) {
fprintf(stderr, "xbps-query: failed to sync rindex "
"files: %s\n", strerror(rv));
return rv;
}
return xbps_rpool_foreach(xhp, repo_ownedby_cb, &ffd);
}

View File

@@ -52,20 +52,17 @@ struct repo_search_data {
};
static int
repo_longest_pkgver(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
repo_longest_pkgver(struct xbps_rindex *rpi, void *arg, bool *done)
{
size_t *len = arg, olen = 0;
(void)done;
if (*len == 0) {
*len = find_longest_pkgver(xhp, rpi->repo);
*len = find_longest_pkgver(rpi->xhp, rpi->repod);
return 0;
}
olen = find_longest_pkgver(xhp, rpi->repo);
olen = find_longest_pkgver(rpi->xhp, rpi->repod);
if (olen > *len)
*len = olen;
@@ -83,75 +80,66 @@ repo_find_longest_pkgver(struct xbps_handle *xhp)
}
static int
show_pkg_namedesc(struct xbps_handle *xhp,
prop_object_t obj,
void *arg,
bool *loop_done)
repo_search_pkgs_cb(struct xbps_rindex *rpi, void *arg, bool *done)
{
prop_array_t allkeys;
prop_dictionary_t pkgd;
prop_dictionary_keysym_t ksym;
struct repo_search_data *rsd = arg;
const char *pkgver, *pkgname, *desc, *arch, *inststr;
const char *pkgver, *pkgname, *desc, *inststr;
char *tmp = NULL, *out = NULL;
size_t x, len;
int i;
size_t i, j, len;
int x;
(void)xhp;
(void)loop_done;
prop_dictionary_get_cstring_nocopy(obj, "architecture", &arch);
if (!xbps_pkg_arch_match(xhp, arch, NULL))
return 0;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
for (i = 0; i < rsd->npatterns; i++) {
if ((xbps_pkgpattern_match(pkgver, rsd->patterns[i]) == 1) ||
(xbps_pkgpattern_match(desc, rsd->patterns[i]) == 1) ||
(strcasecmp(pkgname, rsd->patterns[i]) == 0) ||
(strcasestr(pkgver, rsd->patterns[i])) ||
(strcasestr(desc, rsd->patterns[i]))) {
tmp = calloc(1, rsd->pkgver_len + 1);
assert(tmp);
memcpy(tmp, pkgver, rsd->pkgver_len);
for (x = strlen(tmp); x < rsd->pkgver_len; x++)
tmp[x] = ' ';
tmp[x] = '\0';
if (xbps_pkgdb_get_pkgd_by_pkgver(xhp, pkgver))
inststr = "[*]";
else
inststr = "[-]";
len = strlen(inststr) + strlen(tmp) + strlen(desc) + 1;
if (len > rsd->maxcols) {
out = malloc(rsd->maxcols+1);
assert(out);
snprintf(out, rsd->maxcols-3, "%s %s %s",
inststr, tmp, desc);
strncat(out, "...", rsd->maxcols);
out[rsd->maxcols+1] = '\0';
printf("%s\n", out);
free(out);
} else {
printf("%s %s %s\n", inststr, tmp, desc);
}
free(tmp);
}
}
return 0;
}
static int
repo_search_pkgs_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
{
struct repo_search_data *rsd = arg;
(void)done;
(void)xbps_callback_array_iter(xhp, rpi->repo, show_pkg_namedesc, rsd);
allkeys = prop_dictionary_all_keys(rpi->repod);
for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(rpi->repod, ksym);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "short_desc", &desc);
for (x = 0; x < rsd->npatterns; x++) {
if ((xbps_pkgpattern_match(pkgver, rsd->patterns[x])) ||
(xbps_pkgpattern_match(desc, rsd->patterns[x])) ||
(strcasecmp(pkgname, rsd->patterns[x]) == 0) ||
(strcasestr(pkgver, rsd->patterns[x])) ||
(strcasestr(desc, rsd->patterns[x]))) {
tmp = calloc(1, rsd->pkgver_len + 1);
assert(tmp);
memcpy(tmp, pkgver, rsd->pkgver_len);
for (j = strlen(tmp); j < rsd->pkgver_len; j++)
tmp[j] = ' ';
tmp[j] = '\0';
if (xbps_pkgdb_get_pkg(rpi->xhp, pkgver))
inststr = "[*]";
else
inststr = "[-]";
len = strlen(inststr) + strlen(tmp) +
strlen(desc) + 1;
if (len > rsd->maxcols) {
out = malloc(rsd->maxcols+1);
assert(out);
snprintf(out, rsd->maxcols-3, "%s %s %s",
inststr, tmp, desc);
strncat(out, "...", rsd->maxcols);
out[rsd->maxcols+1] = '\0';
printf("%s\n", out);
free(out);
} else {
printf("%s %s %s\n", inststr,
tmp, desc);
}
free(tmp);
}
}
}
prop_object_release(allkeys);
return 0;
}

View File

@@ -41,10 +41,7 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
assert(pkgname != NULL);
/*
* Check for props.plist metadata file.
*/
propsd = xbps_metadir_get_pkgd(xhp, pkgname);
propsd = xbps_pkgdb_get_pkg_metadata(xhp, pkgname);
if (propsd == NULL)
return ENOENT;
@@ -55,14 +52,14 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
}
int
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkgname)
show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
{
prop_dictionary_t pkgd;
int rv = 0;
pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false);
pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkg);
if (pkgd == NULL) {
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
pkgd = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgd == NULL)
return ENOENT;
}
@@ -77,11 +74,7 @@ repo_show_pkg_deps(struct xbps_handle *xhp, const char *pattern)
{
prop_dictionary_t pkgd;
if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
pkgd = xbps_rpool_get_pkg(xhp, pattern);
if (pkgd == NULL)
return errno;
@@ -92,20 +85,20 @@ repo_show_pkg_deps(struct xbps_handle *xhp, const char *pattern)
}
static int
repo_revdeps_cb(struct xbps_handle *xhp,
struct xbps_rpool_index *rpi,
void *arg,
bool *done)
repo_revdeps_cb(struct xbps_rindex *rpi, void *arg, bool *done)
{
prop_dictionary_t pkgd;
prop_array_t pkgdeps;
prop_array_t allkeys, pkgdeps;
prop_dictionary_keysym_t ksym;
const char *pkgver, *arch, *pattern = arg;
size_t i;
(void)done;
for (i = 0; i < prop_array_count(rpi->repo); i++) {
pkgd = prop_array_get(rpi->repo, i);
allkeys = prop_dictionary_all_keys(rpi->repod);
for (i = 0; i < prop_array_count(allkeys); i++) {
ksym = prop_array_get(allkeys, i);
pkgd = prop_dictionary_get_keysym(rpi->repod, ksym);
pkgdeps = prop_dictionary_get(pkgd, "run_depends");
if (pkgdeps == NULL || prop_array_count(pkgdeps) == 0)
continue;
@@ -113,13 +106,14 @@ repo_revdeps_cb(struct xbps_handle *xhp,
if (xbps_match_pkgdep_in_array(pkgdeps, pattern)) {
prop_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
if (xbps_pkg_arch_match(xhp, arch, NULL)) {
if (xbps_pkg_arch_match(rpi->xhp, arch, NULL)) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
printf("%s\n", pkgver);
}
}
}
prop_object_release(allkeys);
return 0;
}
@@ -133,7 +127,7 @@ repo_show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg)
if (xbps_pkg_version(pkg))
pkgver = pkg;
else {
pkgd = xbps_rpool_find_pkg(xhp, pkg, false, false);
pkgd = xbps_rpool_get_pkg(xhp, pkg);
if (pkgd == NULL)
return ENOENT;
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);

View File

@@ -216,21 +216,20 @@ show_pkg_files(prop_dictionary_t filesd)
int
show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *pkgname,
const char *pkg,
const char *option)
{
prop_dictionary_t d, pkgdb_d;
const char *instdate, *pname;
const char *instdate;
bool autoinst;
d = xbps_metadir_get_pkgd(xhp, pkgname);
if (d == NULL)
pkgdb_d = xbps_pkgdb_get_pkg(xhp, pkg);
if (pkgdb_d == NULL)
return ENOENT;
prop_dictionary_get_cstring_nocopy(d, "pkgname", &pname);
pkgdb_d = xbps_pkgdb_get_pkgd(xhp, pname, false);
if (pkgdb_d == NULL)
return EINVAL;
d = xbps_pkgdb_get_pkg_metadata(xhp, pkg);
if (d == NULL)
return ENOENT;
if (prop_dictionary_get_cstring_nocopy(pkgdb_d,
"install-date", &instdate))
@@ -249,12 +248,12 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
}
int
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkgname)
show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg)
{
prop_dictionary_t d;
int rv = 0;
d = xbps_metadir_get_pkgd(xhp, pkgname);
d = xbps_pkgdb_get_pkg_metadata(xhp, pkg);
if (d == NULL)
return ENOENT;
@@ -270,11 +269,7 @@ repo_show_pkg_info(struct xbps_handle *xhp,
{
prop_dictionary_t pkgd;
if (xbps_pkgpattern_version(pattern))
pkgd = xbps_rpool_find_pkg(xhp, pattern, true, false);
else
pkgd = xbps_rpool_find_pkg(xhp, pattern, false, true);
pkgd = xbps_rpool_get_pkg(xhp, pattern);
if (pkgd == NULL)
return errno;
@@ -291,8 +286,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg)
{
prop_dictionary_t pkgd;
pkgd = xbps_rpool_dictionary_metadata_plist(xhp, pkg,
"./files.plist");
pkgd = xbps_rpool_get_pkg_plist(xhp, pkg, "./files.plist");
if (pkgd == NULL) {
if (errno != ENOTSUP && errno != ENOENT) {
fprintf(stderr, "Unexpected error: %s\n",

View File

@@ -51,13 +51,13 @@ usage(bool fail)
}
static void
state_cb(struct xbps_handle *xhp, struct xbps_state_cb_data *xscd, void *cbd)
state_cb(struct xbps_state_cb_data *xscd, void *cbd)
{
bool syslog_enabled = false;
(void)cbd;
if (xhp->flags & XBPS_FLAG_SYSLOG) {
if (xscd->xhp->flags & XBPS_FLAG_SYSLOG) {
syslog_enabled = true;
openlog("xbps-reconfigure", LOG_CONS, LOG_USER);
}
@@ -74,7 +74,7 @@ state_cb(struct xbps_handle *xhp, struct xbps_state_cb_data *xscd, void *cbd)
syslog(LOG_ERR, "%s", xscd->desc);
break;
default:
xbps_dbg_printf(xhp,
xbps_dbg_printf(xscd->xhp,
"unknown state %d\n", xscd->state);
break;
}

View File

@@ -72,28 +72,28 @@ cleanup_sighandler(int signum)
}
static void
state_cb_rm(struct xbps_handle *xhp,
struct xbps_state_cb_data *xscd,
void *cbdata)
state_cb_rm(struct xbps_state_cb_data *xscd, void *cbdata)
{
bool syslog_enabled = false;
(void)cbdata;
if (xhp->flags & XBPS_FLAG_SYSLOG) {
if (xscd->xhp->flags & XBPS_FLAG_SYSLOG) {
syslog_enabled = true;
openlog("xbps-remove", LOG_CONS, LOG_USER);
}
switch (xscd->state) {
/* notifications */
case XBPS_STATE_UNREGISTER:
break;
case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->arg0, xscd->arg1);
break;
/* success */
case XBPS_STATE_REMOVE_FILE:
case XBPS_STATE_REMOVE_FILE_OBSOLETE:
if (xhp->flags & XBPS_FLAG_VERBOSE)
if (xscd->xhp->flags & XBPS_FLAG_VERBOSE)
printf("%s\n", xscd->desc);
else {
printf("%s\n", xscd->desc);
@@ -106,7 +106,7 @@ state_cb_rm(struct xbps_handle *xhp,
if (syslog_enabled)
syslog(LOG_NOTICE, "Removed `%s-%s' successfully "
"(rootdir: %s).", xscd->arg0, xscd->arg1,
xhp->rootdir);
xscd->xhp->rootdir);
break;
/* errors */
case XBPS_STATE_UNREGISTER_FAIL:
@@ -127,7 +127,7 @@ state_cb_rm(struct xbps_handle *xhp,
syslog(LOG_ERR, "%s", xscd->desc);
break;
default:
xbps_dbg_printf(xhp,
xbps_dbg_printf(xscd->xhp,
"%s-%s: unknown state %d\n",
xscd->arg0, xscd->arg1, xscd->state);
break;
@@ -161,7 +161,7 @@ cachedir_clean(struct xbps_handle *xhp)
}
/* Internalize props.plist dictionary from binary pkg */
binpkg = xbps_xasprintf("%s/%s", xhp->cachedir, dp->d_name);
pkg_propsd = xbps_dictionary_metadata_plist_by_url(binpkg,
pkg_propsd = xbps_get_pkg_plist_from_binpkg(binpkg,
"./props.plist");
if (pkg_propsd == NULL) {
xbps_error_printf("Failed to read from %s: %s\n",
@@ -175,7 +175,7 @@ cachedir_clean(struct xbps_handle *xhp)
* Remove binary pkg if it's not registered in any repository
* or if hash doesn't match.
*/
repo_pkgd = xbps_rpool_find_pkg_exact(xhp, pkgver);
repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver);
if (repo_pkgd) {
prop_dictionary_get_cstring_nocopy(repo_pkgd,
"filename-sha256", &rsha256);
@@ -213,7 +213,7 @@ remove_pkg(struct xbps_handle *xhp, const char *pkgname, size_t cols,
rv = xbps_transaction_remove_pkg(xhp, pkgname, recursive);
if (rv == EEXIST) {
/* pkg has revdeps */
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
pkgd = xbps_pkgdb_get_pkg(xhp, pkgname);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
reqby = prop_dictionary_get(pkgd, "requiredby");
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",

View File

@@ -2,7 +2,7 @@ TOPDIR = ../..
-include $(TOPDIR)/config.mk
BIN = xbps-rindex
OBJS = main.o index.o index-files.o remove-obsoletes.o common.o
OBJS = main.o index.o remove-obsoletes.o common.o
MAN = $(BIN).8
include $(TOPDIR)/mk/prog.mk

View File

@@ -56,11 +56,13 @@ remove_pkg(const char *repodir, const char *arch, const char *file)
filepath = xbps_xasprintf("%s/%s", repodir, file);
if (remove(filepath) == -1) {
rv = errno;
xbps_error_printf("failed to remove old binpkg `%s': %s\n",
file, strerror(rv));
free(filepath);
return rv;
if (errno != ENOENT) {
rv = errno;
xbps_error_printf("failed to remove old binpkg "
"`%s': %s\n", file, strerror(rv));
free(filepath);
return rv;
}
}
free(filepath);

View File

@@ -1,377 +0,0 @@
/*-
* Copyright (c) 2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <errno.h>
#include <libgen.h>
#include <assert.h>
#include <xbps_api.h>
#include "defs.h"
int
index_files_clean(struct xbps_handle *xhp, const char *repodir)
{
prop_object_t obj;
prop_array_t idx, idxfiles, obsoletes;
char *plist, *plistf, *pkgver, *str;
const char *p, *arch, *ipkgver, *iarch;
size_t x, i;
int rv = 0;
bool flush = false;
plist = plistf = pkgver = str = NULL;
idx = idxfiles = obsoletes = NULL;
/* Internalize index-files.plist if found */
if ((plistf = xbps_pkg_index_files_plist(xhp, repodir)) == NULL)
return EINVAL;
if ((idxfiles = prop_array_internalize_from_zfile(plistf)) == NULL) {
free(plistf);
return 0;
}
/* Internalize index.plist */
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) {
rv = EINVAL;
goto out;
}
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
rv = EINVAL;
goto out;
}
printf("Cleaning `%s' index-files, please wait...\n", repodir);
/*
* Iterate over index-files array to find obsolete entries.
*/
obsoletes = prop_array_create();
assert(obsoletes);
for (x = 0; x < prop_array_count(idxfiles); x++) {
obj = prop_array_get(idxfiles, x);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &ipkgver);
prop_dictionary_get_cstring_nocopy(obj, "architecture", &iarch);
if (xbps_find_pkg_in_array_by_pkgver(xhp, idx, ipkgver, iarch)) {
/* pkg found, do nothing */
continue;
}
str = xbps_xasprintf("%s,%s", ipkgver, iarch);
if (!prop_array_add_cstring(obsoletes, str)) {
free(str);
rv = EINVAL;
goto out;
}
free(str);
}
/*
* Iterate over the obsoletes and array and remove entries
* from index-files array.
*/
for (i = 0; i < prop_array_count(obsoletes); i++) {
prop_array_get_cstring_nocopy(obsoletes, i, &p);
pkgver = strdup(p);
for (x = 0; x < strlen(p); x++) {
if ((pkgver[x] = p[x]) == ',') {
pkgver[x] = '\0';
break;
}
}
arch = strchr(p, ',') + 1;
if (!xbps_remove_pkg_from_array_by_pkgver(
xhp, idxfiles, pkgver, arch)) {
free(pkgver);
rv = EINVAL;
goto out;
}
printf("index-files: removed obsolete entry `%s' "
"(%s)\n", pkgver, arch);
free(pkgver);
flush = true;
}
/* Externalize index-files array to plist when necessary */
if (flush && !prop_array_externalize_to_zfile(idxfiles, plistf))
rv = errno;
printf("index-files: %u packages registered.\n",
prop_array_count(idxfiles));
out:
if (obsoletes)
prop_object_release(obsoletes);
if (idx)
prop_object_release(idx);
if (idxfiles)
prop_object_release(idxfiles);
if (plist)
free(plist);
if (plistf)
free(plistf);
return rv;
}
int
index_files_add(struct xbps_handle *xhp, int argc, char **argv)
{
prop_array_t idxfiles = NULL;
prop_object_t obj, fileobj;
prop_dictionary_t pkgprops, pkg_filesd, pkgd;
prop_array_t files, pkg_cffiles, pkg_files, pkg_links;
const char *binpkg, *pkgver, *arch, *version;
char *plist, *repodir, *p, *pkgname;
size_t x;
int i, rv = 0;
bool found, flush;
found = flush = false;
plist = repodir = p = NULL;
obj = fileobj = NULL;
pkgprops = pkg_filesd = pkgd = NULL;
files = NULL;
if ((p = strdup(argv[0])) == NULL) {
rv = ENOMEM;
goto out;
}
repodir = dirname(p);
if ((plist = xbps_pkg_index_files_plist(xhp, repodir)) == NULL) {
rv = ENOMEM;
goto out;
}
/*
* Internalize index-files.plist if found and process argv.
*/
if ((idxfiles = prop_array_internalize_from_zfile(plist)) == NULL) {
if (errno == ENOENT) {
idxfiles = prop_array_create();
assert(idxfiles);
} else {
rv = errno;
goto out;
}
}
for (i = 0; i < argc; i++) {
found = false;
pkgprops = xbps_dictionary_metadata_plist_by_url(argv[i],
"./props.plist");
if (pkgprops == NULL) {
fprintf(stderr, "index-files: cannot internalize "
"%s props.plist: %s\n", argv[i], strerror(errno));
continue;
}
prop_dictionary_get_cstring_nocopy(pkgprops,
"filename", &binpkg);
prop_dictionary_get_cstring_nocopy(pkgprops,
"pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgprops,
"architecture", &arch);
if (xbps_find_pkg_in_array_by_pkgver(xhp, idxfiles,
pkgver, arch)) {
fprintf(stderr, "index-files: skipping `%s' (%s), "
"already registered.\n", pkgver, arch);
prop_object_release(pkgprops);
pkgprops = NULL;
continue;
}
/* internalize files.plist from binary package archive */
pkg_filesd = xbps_dictionary_metadata_plist_by_url(argv[i],
"./files.plist");
if (pkg_filesd == NULL) {
prop_object_release(pkgprops);
rv = EINVAL;
goto out;
}
/* Find out if binary pkg stored in index contain any file */
pkg_cffiles = prop_dictionary_get(pkg_filesd, "conf_files");
if (pkg_cffiles != NULL && prop_array_count(pkg_cffiles))
found = true;
else
pkg_cffiles = NULL;
pkg_files = prop_dictionary_get(pkg_filesd, "files");
if (pkg_files != NULL && prop_array_count(pkg_files))
found = true;
else
pkg_files = NULL;
pkg_links = prop_dictionary_get(pkg_filesd, "links");
if (pkg_links != NULL && prop_array_count(pkg_links))
found = true;
else
pkg_links = NULL;
/* If pkg does not contain any file, ignore it */
if (!found) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
continue;
}
/* create pkg dictionary */
if ((pkgd = prop_dictionary_create()) == NULL) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
rv = EINVAL;
goto out;
}
/* add pkgver and architecture objects into pkg dictionary */
if (!prop_dictionary_set_cstring(pkgd, "architecture", arch)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set_cstring(pkgd, "pkgver", pkgver)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
/* add files array obj into pkg dictionary */
if ((files = prop_array_create()) == NULL) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set(pkgd, "files", files)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
/* add conf_files in pkgd */
if (pkg_cffiles != NULL) {
for (x = 0; x < prop_array_count(pkg_cffiles); x++) {
obj = prop_array_get(pkg_cffiles, x);
fileobj = prop_dictionary_get(obj, "file");
if (!prop_array_add(files, fileobj)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
}
}
/* add files array in pkgd */
if (pkg_files != NULL) {
for (x = 0; x < prop_array_count(pkg_files); x++) {
obj = prop_array_get(pkg_files, x);
fileobj = prop_dictionary_get(obj, "file");
if (!prop_array_add(files, fileobj)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
}
}
/* add links array in pkgd */
if (pkg_links != NULL) {
for (x = 0; x < prop_array_count(pkg_links); x++) {
obj = prop_array_get(pkg_links, x);
fileobj = prop_dictionary_get(obj, "file");
if (!prop_array_add(files, fileobj)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
}
}
/* add pkgd into the index-files array */
if (!prop_array_add(idxfiles, pkgd)) {
prop_object_release(pkgprops);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
rv = EINVAL;
goto out;
}
flush = true;
printf("index-files: added `%s' (%s)\n", pkgver, arch);
prop_object_release(pkg_filesd);
prop_object_release(files);
prop_object_release(pkgd);
pkg_filesd = pkgd = NULL;
files = NULL;
/*
* Remove old entry (if exists).
*/
pkgname = xbps_pkg_name(pkgver);
assert(pkgname);
version = xbps_pkg_version(pkgver);
assert(version);
p = xbps_xasprintf("%s<%s", pkgname, version);
pkgd = xbps_find_pkg_in_array_by_pattern(xhp, idxfiles, p, NULL);
if (pkgd) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
printf("index-files: remove obsolete entry `%s' (%s)\n",
pkgver, arch);
xbps_remove_pkg_from_array_by_pkgver(xhp,
idxfiles, pkgver, NULL);
}
prop_object_release(pkgprops);
free(pkgname);
}
if (flush && !prop_array_externalize_to_zfile(idxfiles, plist)) {
fprintf(stderr, "failed to externalize %s: %s\n",
plist, strerror(errno));
rv = errno;
}
printf("index-files: %u packages registered.\n",
prop_array_count(idxfiles));
out:
if (p)
free(p);
if (plist)
free(plist);
if (idxfiles)
prop_object_release(idxfiles);
return rv;
}

View File

@@ -43,21 +43,24 @@
int
index_clean(struct xbps_handle *xhp, const char *repodir)
{
prop_array_t array;
prop_dictionary_t pkgd;
const char *filen, *pkgver, *arch;
char *plist;
size_t i, idx = 0;
prop_array_t array, result = NULL;
prop_dictionary_t idx, idxfiles, pkgd;
prop_dictionary_keysym_t ksym;
const char *filen, *pkgver, *arch, *keyname;
char *plist, *plistf;
size_t i;
int rv = 0;
bool flush = false;
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
return -1;
plist = xbps_pkg_index_plist(xhp, repodir);
assert(plist);
plistf = xbps_pkg_index_files_plist(xhp, repodir);
assert(plistf);
array = prop_array_internalize_from_zfile(plist);
if (array == NULL) {
idx = prop_dictionary_internalize_from_zfile(plist);
if (idx == NULL) {
if (errno != ENOENT) {
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
fprintf(stderr, "index: cannot read `%s': %s\n",
plist, strerror(errno));
free(plist);
return -1;
@@ -66,38 +69,75 @@ index_clean(struct xbps_handle *xhp, const char *repodir)
return 0;
}
}
idxfiles = prop_dictionary_internalize_from_zfile(plistf);
if (idxfiles == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plistf, strerror(errno));
rv = -1;
goto out;
} else {
goto out;
}
}
if (chdir(repodir) == -1) {
fprintf(stderr, "cannot chdir to %s: %s\n",
fprintf(stderr, "index: cannot chdir to %s: %s\n",
repodir, strerror(errno));
rv = errno;
rv = -1;
goto out;
}
printf("Cleaning `%s' index, please wait...\n", repodir);
again:
for (i = idx; i < prop_array_count(array); i++) {
pkgd = prop_array_get(array, i);
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
array = prop_dictionary_all_keys(idx);
for (i = 0; i < prop_array_count(array); i++) {
ksym = prop_array_get(array, i);
pkgd = prop_dictionary_get_keysym(idx, ksym);
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
if (access(filen, R_OK) == -1) {
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd,
"architecture", &arch);
printf("index: removed obsolete entry `%s' (%s)\n",
pkgver, arch);
prop_array_remove(array, i);
if (result == NULL)
result = prop_array_create();
keyname = prop_dictionary_keysym_cstring_nocopy(ksym);
prop_array_add_cstring(result, keyname);
flush = true;
idx = i;
goto again;
}
}
if (flush && !prop_array_externalize_to_zfile(array, plist)) {
rv = errno;
goto out;
}
printf("index: %u packages registered.\n", prop_array_count(array));
out:
free(plist);
prop_object_release(array);
if (flush) {
for (i = 0; i < prop_array_count(result); i++) {
prop_array_get_cstring_nocopy(result, i, &keyname);
prop_dictionary_remove(idx, keyname);
prop_dictionary_remove(idxfiles, keyname);
}
prop_object_release(result);
if (!prop_dictionary_externalize_to_zfile(idx, plist) &&
!prop_dictionary_externalize_to_zfile(idxfiles, plistf)) {
fprintf(stderr, "index: failed to externalize %s: %s\n",
plist, strerror(errno));
goto out;
}
}
printf("index: %u packages registered.\n",
prop_dictionary_count(idx));
printf("index-files: %u packages registered.\n",
prop_dictionary_count(idxfiles));
out:
if (plist)
free(plist);
if (plistf)
free(plistf);
if (idx)
prop_object_release(idx);
if (idxfiles)
prop_object_release(idxfiles);
return rv;
}
@@ -108,15 +148,21 @@ out:
int
index_add(struct xbps_handle *xhp, int argc, char **argv)
{
prop_array_t idx = NULL;
prop_dictionary_t newpkgd = NULL, curpkgd;
prop_array_t filespkgar, pkg_files, pkg_links, pkg_cffiles;
prop_dictionary_t idx, idxfiles, newpkgd, newpkgfilesd, curpkgd;
prop_dictionary_t filespkgd;
prop_object_t obj, fileobj;
struct stat st;
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
const char *arch, *oldarch;
const char *pkgver, *arch, *oldarch;
char *sha256, *filen, *repodir, *buf, *buf2;
char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL;
char *tmpfilen, *tmprepodir, *plist, *plistf;
size_t x;
int i, ret = 0, rv = 0;
bool flush = false;
bool files_flush = false, found = false, flush = false;
idx = idxfiles = newpkgd = newpkgfilesd = curpkgd = NULL;
tmpfilen = tmprepodir = plist = plistf = NULL;
if ((tmprepodir = strdup(argv[0])) == NULL) {
rv = ENOMEM;
@@ -124,18 +170,33 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
}
repodir = dirname(tmprepodir);
/* Internalize plist file or create it if doesn't exist */
/* Internalize index or create it if doesn't exist */
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
return -1;
if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) {
if ((idx = prop_dictionary_internalize_from_zfile(plist)) == NULL) {
if (errno != ENOENT) {
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
fprintf(stderr, "index: cannot read `%s': %s\n",
plist, strerror(errno));
rv = -1;
goto out;
} else {
idx = prop_array_create();
idx = prop_dictionary_create();
assert(idx);
}
}
/* Internalize index-files or create it if doesn't exist */
if ((plistf = xbps_pkg_index_files_plist(xhp, repodir)) == NULL)
return -1;
if ((idxfiles = prop_dictionary_internalize_from_zfile(plistf)) == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "index: cannot read `%s': %s\n",
plistf, strerror(errno));
rv = -1;
goto out;
} else {
idxfiles = prop_dictionary_create();
assert(idx);
}
}
@@ -152,28 +213,34 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
/*
* Read metadata props plist dictionary from binary package.
*/
newpkgd = xbps_dictionary_metadata_plist_by_url(argv[i],
newpkgd = xbps_get_pkg_plist_from_binpkg(argv[i],
"./props.plist");
if (newpkgd == NULL) {
xbps_error_printf("failed to read %s metadata for `%s',"
fprintf(stderr, "failed to read %s metadata for `%s',"
" skipping!\n", XBPS_PKGPROPS, argv[i]);
free(tmpfilen);
continue;
}
prop_dictionary_get_cstring_nocopy(newpkgd, "architecture",
&arch);
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgver", &pkgver);
if (!xbps_pkg_arch_match(xhp, arch, NULL)) {
fprintf(stderr, "index: ignoring %s, unmatched "
"arch (%s)\n", pkgver, arch);
prop_object_release(newpkgd);
continue;
}
prop_dictionary_get_cstring_nocopy(newpkgd, "pkgname",
&pkgname);
prop_dictionary_get_cstring_nocopy(newpkgd, "version",
&version);
prop_dictionary_get_cstring_nocopy(newpkgd, "architecture",
&arch);
/*
* Check if this package exists already in the index, but first
* checking the version. If current package version is greater
* than current registered package, update the index; otherwise
* pass to the next one.
*/
curpkgd =
xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, NULL);
curpkgd = prop_dictionary_get(idx, pkgname);
if (curpkgd == NULL) {
if (errno && errno != ENOENT) {
prop_object_release(newpkgd);
@@ -235,18 +302,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
free(tmpfilen);
goto out;
}
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
buf2, oldarch)) {
xbps_error_printf("failed to remove %s "
"from plist index: %s\n", buf,
strerror(errno));
rv = errno;
free(buf);
free(buf2);
prop_object_release(newpkgd);
free(tmpfilen);
goto out;
}
prop_dictionary_remove(idx, pkgname);
free(buf2);
printf("index: removed obsolete entry/binpkg %s.\n", buf);
free(buf);
@@ -292,7 +348,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
/*
* Add new pkg dictionary into the index.
*/
if (!prop_array_add(idx, newpkgd)) {
if (!prop_dictionary_set(idx, pkgname, newpkgd)) {
prop_object_release(newpkgd);
free(tmpfilen);
rv = EINVAL;
@@ -301,23 +357,121 @@ index_add(struct xbps_handle *xhp, int argc, char **argv)
flush = true;
printf("index: added `%s-%s' (%s).\n", pkgname, version, arch);
free(tmpfilen);
/*
* Add new pkg dictionary into the index-files.
*/
found = false;
newpkgfilesd = xbps_get_pkg_plist_from_binpkg(argv[i],
"./files.plist");
if (newpkgfilesd == NULL) {
rv = EINVAL;
goto out;
}
/* Find out if binary pkg stored in index contain any file */
pkg_cffiles = prop_dictionary_get(newpkgfilesd, "conf_files");
if (pkg_cffiles != NULL && prop_array_count(pkg_cffiles))
found = true;
else
pkg_cffiles = NULL;
pkg_files = prop_dictionary_get(newpkgfilesd, "files");
if (pkg_files != NULL && prop_array_count(pkg_files))
found = true;
else
pkg_files = NULL;
pkg_links = prop_dictionary_get(newpkgfilesd, "links");
if (pkg_links != NULL && prop_array_count(pkg_links))
found = true;
else
pkg_links = NULL;
/* If pkg does not contain any file, ignore it */
if (!found) {
prop_object_release(newpkgfilesd);
prop_object_release(newpkgd);
continue;
}
/* create pkg files array */
filespkgar = prop_array_create();
assert(filespkgar);
/* add conf_files in pkg files array */
if (pkg_cffiles != NULL) {
for (x = 0; x < prop_array_count(pkg_cffiles); x++) {
obj = prop_array_get(pkg_cffiles, x);
fileobj = prop_dictionary_get(obj, "file");
prop_array_add(filespkgar, fileobj);
}
}
/* add files array in pkg array */
if (pkg_files != NULL) {
for (x = 0; x < prop_array_count(pkg_files); x++) {
obj = prop_array_get(pkg_files, x);
fileobj = prop_dictionary_get(obj, "file");
prop_array_add(filespkgar, fileobj);
}
}
/* add links array in pkgd */
if (pkg_links != NULL) {
for (x = 0; x < prop_array_count(pkg_links); x++) {
obj = prop_array_get(pkg_links, x);
fileobj = prop_dictionary_get(obj, "file");
prop_array_add(filespkgar, fileobj);
}
}
prop_object_release(newpkgfilesd);
/* create pkg dictionary */
filespkgd = prop_dictionary_create();
assert(filespkgd);
/* add pkg files array into pkg dictionary */
prop_dictionary_set(filespkgd, "files", filespkgar);
prop_object_release(filespkgar);
/* set pkgver obj into pkg dictionary */
prop_dictionary_set_cstring(filespkgd, "pkgver", pkgver);
/* add pkg dictionary into index-files */
prop_dictionary_set(idxfiles, pkgname, filespkgd);
prop_object_release(filespkgd);
printf("index-files: added `%s' (%s)\n", pkgver, arch);
files_flush = true;
prop_object_release(newpkgd);
}
if (flush && !prop_array_externalize_to_zfile(idx, plist)) {
xbps_error_printf("failed to externalize plist: %s\n",
if (flush && !prop_dictionary_externalize_to_zfile(idx, plist)) {
fprintf(stderr, "index: failed to externalize plist: %s\n",
strerror(errno));
rv = errno;
rv = -1;
goto out;
}
printf("index: %u packages registered.\n", prop_array_count(idx));
if (files_flush &&
!prop_dictionary_externalize_to_zfile(idxfiles, plistf)) {
fprintf(stderr, "index-files: failed to externalize "
"plist: %s\n", strerror(errno));
rv = -1;
goto out;
}
printf("index: %u packages registered.\n",
prop_dictionary_count(idx));
printf("index-files: %u packages registered.\n",
prop_dictionary_count(idxfiles));
out:
if (tmprepodir)
free(tmprepodir);
if (plist)
free(plist);
if (plistf)
free(plistf);
if (idx)
prop_object_release(idx);
if (idxfiles)
prop_object_release(idxfiles);
return rv;
}

View File

@@ -99,15 +99,12 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (add_mode) {
if (index_add(&xh, argc - optind, argv + optind) == 0)
rv = index_files_add(&xh, argc - optind, argv + optind);
} else if (clean_mode) {
if (index_clean(&xh, argv[optind]) == 0)
rv = index_files_clean(&xh, argv[optind]);
} else if (rm_mode) {
if (add_mode)
rv = index_add(&xh, argc - optind, argv + optind);
else if (clean_mode)
rv = index_clean(&xh, argv[optind]);
else if (rm_mode)
rv = remove_obsoletes(&xh, argv[optind]);
}
xbps_end(&xh);
exit(rv ? EXIT_FAILURE : EXIT_SUCCESS);

View File

@@ -39,8 +39,8 @@
int
remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
{
prop_dictionary_t pkgd;
prop_array_t idx;
prop_dictionary_t pkgd, idx;
struct xbps_rindex ri;
DIR *dirp;
struct dirent *dp;
const char *pkgver, *arch;
@@ -50,10 +50,10 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL)
return -1;
idx = prop_array_internalize_from_zfile(plist);
idx = prop_dictionary_internalize_from_zfile(plist);
if (idx == NULL) {
if (errno != ENOENT) {
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
fprintf(stderr, "xbps-rindex: cannot read `%s': %s\n",
plist, strerror(errno));
free(plist);
return -1;
@@ -62,14 +62,19 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
return 0;
}
}
/* initialize repository index */
ri.repod = idx;
ri.uri = repodir;
ri.xhp = xhp;
if (chdir(repodir) == -1) {
fprintf(stderr, "cannot chdir to %s: %s\n",
fprintf(stderr, "xbps-rindex: cannot chdir to %s: %s\n",
repodir, strerror(errno));
prop_object_release(idx);
return errno;
}
if ((dirp = opendir(repodir)) == NULL) {
fprintf(stderr, "failed to open %s: %s\n",
fprintf(stderr, "xbps-rindex: failed to open %s: %s\n",
repodir, strerror(errno));
prop_object_release(idx);
return errno;
@@ -82,12 +87,12 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
if (strcmp(ext, ".xbps"))
continue;
pkgd = xbps_dictionary_metadata_plist_by_url(dp->d_name,
pkgd = xbps_get_pkg_plist_from_binpkg(dp->d_name,
"./props.plist");
if (pkgd == NULL) {
rv = remove_pkg(repodir, arch, dp->d_name);
if (rv != 0) {
fprintf(stderr, "index: failed to remove "
fprintf(stderr, "xbps-rindex: failed to remove "
"package `%s': %s\n", dp->d_name,
strerror(rv));
prop_object_release(pkgd);
@@ -100,10 +105,10 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir)
/*
* If binpkg is not registered in index, remove binpkg.
*/
if (!xbps_find_pkg_in_array_by_pkgver(xhp, idx, pkgver, arch)) {
if (!xbps_rindex_get_pkg(&ri, pkgver)) {
rv = remove_pkg(repodir, arch, dp->d_name);
if (rv != 0) {
fprintf(stderr, "index: failed to remove "
fprintf(stderr, "xbps-rindex: failed to remove "
"package `%s': %s\n", dp->d_name,
strerror(rv));
prop_object_release(pkgd);

View File

@@ -155,7 +155,7 @@ main(int argc, char **argv)
if (argc != 2)
usage();
dict = xbps_find_pkg_dict_installed(&xh, argv[1], false);
dict = xbps_pkgdb_get_pkg(&xh, argv[1]);
if (dict == NULL) {
rv = errno;
goto out;