Repository index 1.4 -- see NEWS file for info.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -102,7 +102,7 @@ void show_pkg_info(prop_dictionary_t);
|
||||
void show_pkg_info_one(prop_dictionary_t, const char *);
|
||||
int list_strings_in_array(prop_object_t, void *, bool *);
|
||||
int list_strings_sep_in_array(prop_object_t, void *, bool *);
|
||||
size_t find_longest_pkgver(prop_dictionary_t);
|
||||
size_t find_longest_pkgver(prop_object_t);
|
||||
void print_package_line(const char *, bool);
|
||||
|
||||
/* from list.c */
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2008-2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2008-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -186,12 +186,12 @@ _find_longest_pkgver_cb(prop_object_t obj, void *arg, bool *loop_done)
|
||||
}
|
||||
|
||||
size_t
|
||||
find_longest_pkgver(prop_dictionary_t d)
|
||||
find_longest_pkgver(prop_object_t o)
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
if (prop_object_type(d) == PROP_TYPE_DICTIONARY)
|
||||
(void)xbps_callback_array_iter_in_dict(d, "packages",
|
||||
if (prop_object_type(o) == PROP_TYPE_ARRAY)
|
||||
(void)xbps_callback_array_iter(o,
|
||||
_find_longest_pkgver_cb, &len);
|
||||
else
|
||||
(void)xbps_regpkgdb_foreach_pkg_cb(
|
||||
|
@@ -33,7 +33,7 @@
|
||||
#include "defs.h"
|
||||
|
||||
struct index_files_data {
|
||||
prop_dictionary_t idxdict;
|
||||
prop_array_t idx;
|
||||
prop_array_t idxfiles;
|
||||
prop_array_t obsoletes;
|
||||
const char *pkgdir;
|
||||
@@ -44,7 +44,6 @@ struct index_files_data {
|
||||
static int
|
||||
rmobsoletes_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
{
|
||||
prop_array_t array;
|
||||
prop_string_t ps;
|
||||
struct index_files_data *ifd = arg;
|
||||
const char *pkgver;
|
||||
@@ -52,8 +51,7 @@ rmobsoletes_files_cb(prop_object_t obj, void *arg, bool *done)
|
||||
(void)done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
|
||||
array = prop_dictionary_get(ifd->idxdict, "packages");
|
||||
if (xbps_find_pkg_in_array_by_pkgver(array, pkgver)) {
|
||||
if (xbps_find_pkg_in_array_by_pkgver(ifd->idx, pkgver)) {
|
||||
/* pkg found, do nothing */
|
||||
return 0;
|
||||
}
|
||||
@@ -195,9 +193,9 @@ start:
|
||||
int
|
||||
repo_genindex_files(const char *pkgdir)
|
||||
{
|
||||
prop_dictionary_t idxdict;
|
||||
prop_array_t idx;
|
||||
struct index_files_data *ifd = NULL;
|
||||
size_t idx;
|
||||
size_t i;
|
||||
const char *pkgver;
|
||||
char *plist;
|
||||
int rv;
|
||||
@@ -207,8 +205,8 @@ repo_genindex_files(const char *pkgdir)
|
||||
return ENOMEM;
|
||||
|
||||
/* internalize repository index plist */
|
||||
idxdict = prop_dictionary_internalize_from_zfile(plist);
|
||||
if (idxdict == NULL) {
|
||||
idx = prop_array_internalize_from_zfile(plist);
|
||||
if (idx == NULL) {
|
||||
free(plist);
|
||||
return errno;
|
||||
}
|
||||
@@ -227,7 +225,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
}
|
||||
ifd->pkgdir = pkgdir;
|
||||
ifd->idxfiles = prop_array_internalize_from_zfile(plist);
|
||||
ifd->idxdict = prop_dictionary_copy(idxdict);
|
||||
ifd->idx = prop_array_copy(idx);
|
||||
ifd->obsoletes = prop_array_create();
|
||||
if (ifd->idxfiles == NULL) {
|
||||
/* missing file, create new one */
|
||||
@@ -236,8 +234,7 @@ repo_genindex_files(const char *pkgdir)
|
||||
}
|
||||
|
||||
/* iterate over index.plist packages array */
|
||||
rv = xbps_callback_array_iter_in_dict(idxdict,
|
||||
"packages", genindex_files_cb, ifd);
|
||||
rv = xbps_callback_array_iter(idx, genindex_files_cb, ifd);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
|
||||
@@ -247,9 +244,9 @@ repo_genindex_files(const char *pkgdir)
|
||||
rmobsoletes_files_cb, ifd);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
for (idx = 0; idx < prop_array_count(ifd->obsoletes); idx++) {
|
||||
for (i = 0; i < prop_array_count(ifd->obsoletes); i++) {
|
||||
prop_array_get_cstring_nocopy(ifd->obsoletes,
|
||||
idx, &pkgver);
|
||||
i, &pkgver);
|
||||
if (!xbps_remove_pkg_from_array_by_pkgver(
|
||||
ifd->idxfiles, pkgver)) {
|
||||
rv = EINVAL;
|
||||
@@ -274,14 +271,14 @@ out:
|
||||
prop_object_release(ifd->obsoletes);
|
||||
if (ifd->idxfiles != NULL)
|
||||
prop_object_release(ifd->idxfiles);
|
||||
if (ifd->idxdict != NULL)
|
||||
prop_object_release(ifd->idxdict);
|
||||
if (ifd->idx != NULL)
|
||||
prop_object_release(ifd->idx);
|
||||
if (plist != NULL)
|
||||
free(plist);
|
||||
if (ifd != NULL)
|
||||
free(ifd);
|
||||
if (idxdict != NULL)
|
||||
prop_object_release(idxdict);
|
||||
if (idx != NULL)
|
||||
prop_object_release(idx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2009-2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2009-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -43,8 +43,8 @@
|
||||
static int
|
||||
remove_missing_binpkg_entries(const char *repodir)
|
||||
{
|
||||
prop_array_t pkgarray;
|
||||
prop_dictionary_t idxd, pkgd;
|
||||
prop_array_t array;
|
||||
prop_dictionary_t pkgd;
|
||||
const char *filen;
|
||||
char *binpkg, *plist;
|
||||
size_t i;
|
||||
@@ -55,8 +55,8 @@ remove_missing_binpkg_entries(const char *repodir)
|
||||
if (plist == NULL)
|
||||
return -1;
|
||||
|
||||
idxd = prop_dictionary_internalize_from_zfile(plist);
|
||||
if (idxd == NULL) {
|
||||
array = prop_array_internalize_from_zfile(plist);
|
||||
if (array == NULL) {
|
||||
if (errno != ENOENT) {
|
||||
xbps_error_printf("xbps-repo: cannot read `%s': %s\n",
|
||||
plist, strerror(errno));
|
||||
@@ -68,12 +68,8 @@ remove_missing_binpkg_entries(const char *repodir)
|
||||
}
|
||||
|
||||
again:
|
||||
pkgarray = prop_dictionary_get(idxd, "packages");
|
||||
if (prop_object_type(pkgarray) != PROP_TYPE_ARRAY)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < prop_array_count(pkgarray); i++) {
|
||||
pkgd = prop_array_get(pkgarray, i);
|
||||
for (i = 0; i < prop_array_count(array); i++) {
|
||||
pkgd = prop_array_get(array, i);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "filename", &filen);
|
||||
binpkg = xbps_xasprintf("%s/%s", repodir, filen);
|
||||
if (binpkg == NULL) {
|
||||
@@ -85,7 +81,7 @@ again:
|
||||
xbps_warn_printf("xbps-repo: `%s' unavailable, "
|
||||
"removing entry from index... (%s)\n",
|
||||
filen, strerror(errno));
|
||||
prop_array_remove(pkgarray, i);
|
||||
prop_array_remove(array, i);
|
||||
free(binpkg);
|
||||
found = true;
|
||||
goto again;
|
||||
@@ -93,10 +89,7 @@ again:
|
||||
free(binpkg);
|
||||
}
|
||||
if (found) {
|
||||
prop_dictionary_set_uint64(idxd, "total-pkgs",
|
||||
prop_array_count(pkgarray));
|
||||
prop_dictionary_set(idxd, "packages", pkgarray);
|
||||
if (!prop_dictionary_externalize_to_zfile(idxd, plist))
|
||||
if (!prop_array_externalize_to_zfile(array, plist))
|
||||
rv = errno;
|
||||
}
|
||||
free(plist);
|
||||
@@ -104,14 +97,12 @@ again:
|
||||
return rv;
|
||||
}
|
||||
|
||||
static prop_dictionary_t
|
||||
repoidx_getdict(const char *pkgdir)
|
||||
static prop_array_t
|
||||
repoidx_get(const char *pkgdir)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_array_t array;
|
||||
char *plist;
|
||||
int rv;
|
||||
|
||||
/*
|
||||
* Remove entries in repositories index for unexistent
|
||||
* packages, i.e dangling entries.
|
||||
@@ -123,50 +114,25 @@ repoidx_getdict(const char *pkgdir)
|
||||
if (plist == NULL)
|
||||
return NULL;
|
||||
|
||||
dict = prop_dictionary_internalize_from_zfile(plist);
|
||||
if (dict == NULL) {
|
||||
dict = prop_dictionary_create();
|
||||
if (dict == NULL)
|
||||
goto out;
|
||||
|
||||
array = prop_array_create();
|
||||
if (array == NULL) {
|
||||
prop_object_release(dict);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!prop_dictionary_set(dict, "packages", array)) {
|
||||
prop_object_release(dict);
|
||||
prop_object_release(array);
|
||||
goto out;
|
||||
}
|
||||
prop_object_release(array);
|
||||
if (!prop_dictionary_set_cstring_nocopy(dict,
|
||||
"pkgindex-version", XBPS_PKGINDEX_VERSION)) {
|
||||
prop_object_release(dict);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
array = prop_array_internalize_from_zfile(plist);
|
||||
free(plist);
|
||||
return dict;
|
||||
if (array == NULL)
|
||||
array = prop_array_create();
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static int
|
||||
add_binpkg_to_index(prop_dictionary_t idxdict,
|
||||
add_binpkg_to_index(prop_array_t idx,
|
||||
const char *filedir,
|
||||
const char *file)
|
||||
{
|
||||
prop_dictionary_t newpkgd, curpkgd;
|
||||
prop_array_t pkgar;
|
||||
struct stat st;
|
||||
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
|
||||
char *sha256, *filen, *tmpfilen, *oldfilepath, *buf;
|
||||
int rv = 0;
|
||||
|
||||
if (idxdict == NULL || file == NULL)
|
||||
return EINVAL;
|
||||
|
||||
tmpfilen = strdup(file);
|
||||
if (tmpfilen == NULL)
|
||||
return errno;
|
||||
@@ -191,7 +157,7 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
|
||||
* than current registered package, update the index; otherwise
|
||||
* pass to the next one.
|
||||
*/
|
||||
curpkgd = xbps_find_pkg_in_dict_by_name(idxdict, "packages", pkgname);
|
||||
curpkgd = xbps_find_pkg_in_array_by_name(idx, pkgname);
|
||||
if (curpkgd == NULL) {
|
||||
if (errno && errno != ENOENT) {
|
||||
prop_object_release(newpkgd);
|
||||
@@ -240,8 +206,7 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
|
||||
goto out;
|
||||
}
|
||||
free(oldfilepath);
|
||||
if (!xbps_remove_pkg_from_dict_by_name(idxdict,
|
||||
"packages", pkgname)) {
|
||||
if (!xbps_remove_pkg_from_array_by_name(idx, pkgname)) {
|
||||
xbps_error_printf("failed to remove `%s' "
|
||||
"from plist index: %s\n", pkgname, strerror(errno));
|
||||
prop_object_release(newpkgd);
|
||||
@@ -286,28 +251,16 @@ add_binpkg_to_index(prop_dictionary_t idxdict,
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/* Get package array in repo index file */
|
||||
pkgar = prop_dictionary_get(idxdict, "packages");
|
||||
if (pkgar == NULL) {
|
||||
prop_object_release(newpkgd);
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Add dictionary into the index and update package count.
|
||||
*/
|
||||
if (!xbps_add_obj_to_array(pkgar, newpkgd)) {
|
||||
prop_object_release(newpkgd);
|
||||
if (!xbps_add_obj_to_array(idx, newpkgd)) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
printf("Registered `%s-%s' (%s) in repository index.\n",
|
||||
pkgname, version, filen);
|
||||
|
||||
if (!prop_dictionary_set_uint64(idxdict, "total-pkgs",
|
||||
prop_array_count(pkgar)))
|
||||
rv = errno;
|
||||
|
||||
out:
|
||||
if (tmpfilen)
|
||||
free(tmpfilen);
|
||||
@@ -318,10 +271,9 @@ out:
|
||||
int
|
||||
repo_genindex(const char *pkgdir)
|
||||
{
|
||||
prop_dictionary_t idxdict = NULL;
|
||||
prop_array_t idx = NULL;
|
||||
struct dirent *dp;
|
||||
DIR *dirp;
|
||||
uint64_t npkgcnt = 0;
|
||||
char *binfile, *plist;
|
||||
int rv = 0;
|
||||
bool registered_newpkgs = false, foundpkg = false;
|
||||
@@ -329,13 +281,13 @@ repo_genindex(const char *pkgdir)
|
||||
/*
|
||||
* Create or read existing package index plist file.
|
||||
*/
|
||||
idxdict = repoidx_getdict(pkgdir);
|
||||
if (idxdict == NULL)
|
||||
idx = repoidx_get(pkgdir);
|
||||
if (idx == NULL)
|
||||
return errno;
|
||||
|
||||
plist = xbps_pkg_index_plist(pkgdir);
|
||||
if (plist == NULL) {
|
||||
prop_object_release(idxdict);
|
||||
prop_object_release(idx);
|
||||
return errno;
|
||||
}
|
||||
|
||||
@@ -362,7 +314,7 @@ repo_genindex(const char *pkgdir)
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
rv = add_binpkg_to_index(idxdict, pkgdir, binfile);
|
||||
rv = add_binpkg_to_index(idx, pkgdir, binfile);
|
||||
free(binfile);
|
||||
if (rv == EEXIST) {
|
||||
rv = 0;
|
||||
@@ -383,8 +335,8 @@ repo_genindex(const char *pkgdir)
|
||||
/*
|
||||
* Show total count registered packages.
|
||||
*/
|
||||
prop_dictionary_get_uint64(idxdict, "total-pkgs", &npkgcnt);
|
||||
printf("%ju packages registered in repository index.\n", npkgcnt);
|
||||
printf("%zu packages registered in repository index.\n",
|
||||
(size_t)prop_array_count(idx));
|
||||
/*
|
||||
* Don't write plist file if no packages were registered.
|
||||
*/
|
||||
@@ -394,12 +346,12 @@ repo_genindex(const char *pkgdir)
|
||||
* If any package was registered in package index, write
|
||||
* plist file to storage.
|
||||
*/
|
||||
if (!prop_dictionary_externalize_to_zfile(idxdict, plist))
|
||||
if (!prop_array_externalize_to_zfile(idx, plist))
|
||||
rv = errno;
|
||||
}
|
||||
out:
|
||||
free(plist);
|
||||
prop_object_release(idxdict);
|
||||
prop_object_release(idx);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2011 Juan Romero Pardines.
|
||||
* Copyright (c) 2011-2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -49,29 +49,22 @@ repo_pkg_list_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
}
|
||||
lpc.check_state = false;
|
||||
lpc.state = 0;
|
||||
lpc.pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||
lpc.pkgver_len = find_longest_pkgver(rpi->rpi_repo);
|
||||
|
||||
printf("From %s repository ...\n", rpi->rpi_uri);
|
||||
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
||||
"packages", list_pkgs_in_dict, &lpc);
|
||||
|
||||
(void)xbps_callback_array_iter(rpi->rpi_repo, list_pkgs_in_dict, &lpc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
repo_list_uri_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
{
|
||||
const char *pkgidx;
|
||||
uint64_t npkgs;
|
||||
|
||||
(void)arg;
|
||||
(void)done;
|
||||
|
||||
prop_dictionary_get_cstring_nocopy(rpi->rpi_repod,
|
||||
"pkgindex-version", &pkgidx);
|
||||
prop_dictionary_get_uint64(rpi->rpi_repod, "total-pkgs", &npkgs);
|
||||
printf("[%u] %s (index %s, " "%" PRIu64 " packages)\n",
|
||||
rpi->rpi_index, rpi->rpi_uri, pkgidx, npkgs);
|
||||
printf("[%u] %s (%zu packages)\n",
|
||||
rpi->rpi_index, rpi->rpi_uri,
|
||||
(size_t)prop_array_count(rpi->rpi_repo));
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -82,11 +75,9 @@ repo_search_pkgs_cb(struct repository_pool_index *rpi, void *arg, bool *done)
|
||||
struct repo_search_data *rsd = arg;
|
||||
(void)done;
|
||||
|
||||
rsd->pkgver_len = find_longest_pkgver(rpi->rpi_repod);
|
||||
rsd->pkgver_len = find_longest_pkgver(rpi->rpi_repo);
|
||||
|
||||
printf("From %s repository ...\n", rpi->rpi_uri);
|
||||
(void)xbps_callback_array_iter_in_dict(rpi->rpi_repod,
|
||||
"packages", show_pkg_namedesc, rsd);
|
||||
|
||||
(void)xbps_callback_array_iter(rpi->rpi_repo, show_pkg_namedesc, rsd);
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user