Mega-commit to document the API with doxygen.

Some changes were made to the API when making the documentation:

- A few exported functions are now hidden, because they were only used
  internally in the library.
- A few exported symbols were renamed to document them better than
  previously.
- Cosmetic changes all along the way, as well as some fixes here and there.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20100121021019-onbsivlrhdb7t3ou
This commit is contained in:
Juan RP
2010-01-21 03:10:19 +01:00
parent 61d2ea8896
commit c0b280c118
40 changed files with 1977 additions and 761 deletions

View File

@@ -110,7 +110,7 @@ xbps_check_pkg_integrity(const char *pkgname)
assert(pkgname != NULL);
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (pkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
return 0;

View File

@@ -37,22 +37,11 @@ struct transaction {
prop_dictionary_t dict;
prop_object_iterator_t iter;
bool yes;
size_t inst_pkgcnt;
size_t up_pkgcnt;
size_t cf_pkgcnt;
};
static int exec_transaction(struct transaction *);
static void show_missing_deps(prop_dictionary_t);
static int show_missing_dep_cb(prop_object_t, void *, bool *);
static void show_package_list(prop_object_iterator_t, const char *);
static void
show_missing_deps(prop_dictionary_t d)
{
fprintf(stderr,
"xbps-bin: unable to locate some required packages:\n");
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
show_missing_dep_cb, NULL);
}
static int
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
{
@@ -69,6 +58,15 @@ show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
return 0;
}
static void
show_missing_deps(prop_dictionary_t d)
{
fprintf(stderr,
"xbps-bin: unable to locate some required packages:\n");
(void)xbps_callback_array_iter_in_dict(d, "missing_deps",
show_missing_dep_cb, NULL);
}
static bool
check_binpkg_hash(const char *path, const char *filename,
const char *sha256)
@@ -125,7 +123,7 @@ download_package_list(prop_object_iterator_t iter)
/*
* If package is in a local repository, check its hash
* and pass no next one.
* and pass to next one.
*/
if (!xbps_check_is_repo_string_remote(repoloc)) {
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
@@ -167,11 +165,12 @@ download_package_list(prop_object_iterator_t iter)
rv = xbps_fetch_file(binfile, cachedir, false, NULL);
free(binfile);
if (rv == -1) {
fprintf(stderr, "xbps-bin: couldn't download %s "
"from %s (%s)\n", filename, repoloc,
xbps_fetch_error_string());
fprintf(stderr, "xbps-bin: couldn't download `%s'\n",
filename);
fprintf(stderr, "xbps-bin: %s returned: `%s'\n",
repoloc, xbps_fetch_error_string());
free(lbinfile);
return errno;
return -1;
}
if (!check_binpkg_hash(lbinfile, filename, sha256)) {
fprintf(stderr, "W: removing wrong %s file ...\n",
@@ -221,66 +220,62 @@ show_package_list(prop_object_iterator_t iter, const char *match)
}
static int
show_transaction_sizes(prop_object_iterator_t iter)
show_transaction_sizes(struct transaction *trans)
{
prop_object_t obj;
uint64_t tsize = 0, dlsize = 0, instsize = 0;
uint64_t dlsize = 0, instsize = 0;
const char *tract;
char size[64];
bool trans_inst, trans_up, trans_conf;
trans_inst = trans_up = trans_conf = false;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (!prop_dictionary_get_uint64(obj, "filename-size", &tsize))
return errno;
dlsize += tsize;
tsize = 0;
if (!prop_dictionary_get_uint64(obj, "installed_size", &tsize))
return errno;
instsize += tsize;
tsize = 0;
}
prop_object_iterator_reset(iter);
while ((obj = prop_object_iterator_next(iter))) {
while ((obj = prop_object_iterator_next(trans->iter))) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"trans-action", &tract))
return errno;
if (strcmp(tract, "install") == 0)
if (strcmp(tract, "install") == 0) {
trans->inst_pkgcnt++;
trans_inst = true;
else if (strcmp(tract, "update") == 0)
} else if (strcmp(tract, "update") == 0) {
trans->up_pkgcnt++;
trans_up = true;
else if (strcmp(tract, "configure") == 0)
} else if (strcmp(tract, "configure") == 0) {
trans->cf_pkgcnt++;
trans_conf = true;
}
}
prop_object_iterator_reset(iter);
prop_object_iterator_reset(trans->iter);
/*
* Show the list of packages that will be installed.
*/
if (trans_inst) {
printf("The following packages will be installed:\n\n");
show_package_list(iter, "install");
show_package_list(trans->iter, "install");
printf("\n\n");
}
if (trans_up) {
printf("The following packages will be updated:\n\n");
show_package_list(iter, "update");
show_package_list(trans->iter, "update");
printf("\n\n");
}
if (trans_conf) {
printf("The following packages will be configured:\n\n");
show_package_list(iter, "configure");
show_package_list(trans->iter, "configure");
printf("\n\n");
}
/*
* Show total download/installed size for all required packages.
*/
if (!prop_dictionary_get_uint64(trans->dict,
"total-download-size", &dlsize))
return errno;
if (!prop_dictionary_get_uint64(trans->dict,
"total-installed-size", &instsize))
return errno;
if (xbps_humanize_number(size, 5, (int64_t)dlsize,
"", HN_AUTOSCALE, HN_B|HN_DECIMAL|HN_NOSPACE) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number returns "
@@ -334,14 +329,14 @@ pkgname_from_pkgmatch(const char *pkg)
*
* XXX REALLY FIX THIS CRAP! I haven't found much easier ways...
*/
if ((version = xbps_get_pkgdep_version(pkg))) {
if ((version = xbps_get_pkgpattern_version(pkg))) {
while (*version) {
if (!isdigit((unsigned char)*version)) {
version++;
continue;
}
if (xbps_cmpver("0", version) <= 0)
return xbps_get_pkgdep_name(pkg);
return xbps_get_pkgpattern_name(pkg);
}
}
if ((version = xbps_get_pkg_version(pkg))) {
@@ -394,7 +389,7 @@ xbps_install_new_pkg(const char *pkg)
/*
* Find a package in a repository and prepare for installation.
*/
if ((pkgd = xbps_find_pkg_installed_from_plist(pkgname))) {
if ((pkgd = xbps_find_pkg_dict_installed(pkgname, false))) {
printf("Package '%s' is already installed.\n", pkgname);
prop_object_release(pkgd);
if (pkgmatch)
@@ -424,7 +419,7 @@ xbps_update_pkg(const char *pkgname)
prop_dictionary_t pkgd;
int rv = 0;
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
printf("Finding new '%s' package...\n", pkgname);
if (pkgd) {
rv = xbps_repository_update_pkg(pkgname, pkgd);
@@ -445,70 +440,12 @@ xbps_update_pkg(const char *pkgname)
return rv;
}
int
xbps_exec_transaction(bool yes)
{
struct transaction *trans;
prop_array_t array;
int rv = 0;
trans = calloc(1, sizeof(struct transaction));
if (trans == NULL)
goto out;
trans->dict = xbps_repository_get_transaction_dict();
if (trans->dict == NULL)
goto out;
/*
* Bail out if there are unresolved deps.
*/
array = prop_dictionary_get(trans->dict, "missing_deps");
if (prop_array_count(array) > 0) {
show_missing_deps(trans->dict);
goto out;
}
DPRINTF(("%s", prop_dictionary_externalize(trans->dict)));
/*
* Sort the package transaction dictionary.
*/
if ((rv = xbps_sort_pkg_deps(trans->dict)) != 0) {
fprintf(stderr, "xbps-bin: error while sorting "
"packages: %s\n", strerror(rv));
goto out;
}
/*
* It's time to run the transaction!
*/
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
if (trans->iter == NULL) {
fprintf(stderr, "xbps-bin: error allocating array mem! (%s)\n",
strerror(errno));
goto out;
}
trans->yes = yes;
rv = exec_transaction(trans);
out:
if (trans->iter)
prop_object_iterator_release(trans->iter);
if (trans->dict)
prop_object_release(trans->dict);
if (trans)
free(trans);
return rv;
}
static int
replace_packages(prop_object_iterator_t iter, const char *pkgver)
{
prop_dictionary_t instd;
prop_object_t obj;
const char *reppkgn, *version;
const char *pattern, *reppkgn, *reppkgver, *version;
int rv = 0;
/*
@@ -516,16 +453,23 @@ replace_packages(prop_object_iterator_t iter, const char *pkgver)
* them before upgrading or installing new one.
*/
while ((obj = prop_object_iterator_next(iter))) {
reppkgn = prop_string_cstring_nocopy(obj);
if (reppkgn == NULL)
pattern = prop_string_cstring_nocopy(obj);
if (pattern == NULL)
return errno;
instd = xbps_find_pkg_installed_from_plist(reppkgn);
/*
* If pattern matches an installed package, replace it.
*/
instd = xbps_find_pkg_dict_installed(pattern, true);
if (instd == NULL)
continue;
printf("Replacing package '%s' with '%s' ...\n",
reppkgn, pkgver);
prop_dictionary_get_cstring_nocopy(instd, "pkgname", &reppkgn);
prop_dictionary_get_cstring_nocopy(instd, "pkgver", &reppkgver);
printf("Replacing package '%s' with '%s' "
"(matched by '%s')...\n", reppkgver, pkgver, pattern);
prop_object_release(instd);
version = xbps_get_pkg_version(pkgver);
if ((rv = xbps_remove_pkg(reppkgn, version, false)) != 0) {
fprintf(stderr, "xbps-bin: couldn't remove %s (%s)\n",
@@ -562,8 +506,7 @@ exec_transaction(struct transaction *trans)
/*
* Show download/installed size for the transaction.
*/
rv = show_transaction_sizes(trans->iter);
if (rv != 0)
if ((rv = show_transaction_sizes(trans)) != 0)
return rv;
/*
@@ -580,12 +523,14 @@ exec_transaction(struct transaction *trans)
* Download binary packages (if they come from a remote repository)
* and check its SHA256 hash.
*/
printf("[1/3] Downloading/integrity check\n\n");
if ((rv = download_package_list(trans->iter)) != 0)
return rv;
/*
* Iterate over the transaction dictionary.
*/
printf("\n[2/3] Unpacking\n\n");
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
@@ -631,7 +576,7 @@ exec_transaction(struct transaction *trans)
}
if (strcmp(tract, "update") == 0) {
instpkgd = xbps_find_pkg_installed_from_plist(pkgname);
instpkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (instpkgd == NULL) {
fprintf(stderr, "xbps-bin: error: unable to "
"find %s installed dict!\n", pkgname);
@@ -648,27 +593,24 @@ exec_transaction(struct transaction *trans)
/*
* If package is marked as 'essential' remove old
* requiredby entries and overwrite pkg files; otherwise
* remove old package and install new one.
* remove old package and install new one. This
* is all handled internally in xbps_remove_pkg()
* and xbps_unpack_binary_pkg().
*/
if (essential) {
rv = xbps_requiredby_pkg_remove(pkgname);
if (rv != 0) {
fprintf(stderr, "xbps-bin: error: "
"couldn't remove reqby"
" entries for %s-%s (%s)\n",
pkgname, instver, strerror(rv));
return rv;
}
} else {
printf("Removing %s-%s ...\n",
pkgname, instver);
rv = xbps_remove_pkg(pkgname, version, true);
if (rv != 0) {
fprintf(stderr, "xbps-bin: error "
"removing %s-%s (%s)\n",
pkgname, instver, strerror(rv));
return rv;
}
if (essential)
printf("Replacing %s-%s with %s-%s ...\n",
pkgname, instver, pkgname, version);
else
printf("Removing %s-%s before installing new "
"version ...\n", pkgname, instver);
rv = xbps_remove_pkg(pkgname, version, true);
if (rv != 0) {
fprintf(stderr, "xbps-bin: error "
"%s %s-%s (%s)\n", essential ?
"replacing" : "removing", pkgname,
instver, strerror(rv));
return rv;
}
}
/*
@@ -694,6 +636,7 @@ exec_transaction(struct transaction *trans)
/*
* Configure all unpacked packages.
*/
printf("\n[3/3] Configuring\n\n");
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
if (!prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &pkgname))
@@ -713,7 +656,60 @@ exec_transaction(struct transaction *trans)
"package %s (%s)\n", pkgname, strerror(rv));
return rv;
}
trans->cf_pkgcnt++;
}
printf("\nxbps-bin: %zu installed, %zu updated, "
"%zu configured.\n", trans->inst_pkgcnt, trans->up_pkgcnt,
trans->cf_pkgcnt);
return 0;
}
int
xbps_exec_transaction(bool yes)
{
struct transaction *trans;
prop_array_t array;
int rv = 0;
trans = calloc(1, sizeof(struct transaction));
if (trans == NULL)
goto out;
trans->dict = xbps_repository_get_transaction_dict();
if (trans->dict == NULL)
goto out;
/*
* Bail out if there are unresolved deps.
*/
array = prop_dictionary_get(trans->dict, "missing_deps");
if (prop_array_count(array) > 0) {
show_missing_deps(trans->dict);
goto out;
}
DPRINTF(("%s", prop_dictionary_externalize(trans->dict)));
/*
* It's time to run the transaction!
*/
trans->iter = xbps_get_array_iter_from_dict(trans->dict, "packages");
if (trans->iter == NULL) {
fprintf(stderr, "xbps-bin: error allocating array mem! (%s)\n",
strerror(errno));
goto out;
}
trans->yes = yes;
rv = exec_transaction(trans);
out:
if (trans->iter)
prop_object_iterator_release(trans->iter);
if (trans->dict)
prop_object_release(trans->dict);
if (trans)
free(trans);
return rv;
}

View File

@@ -34,10 +34,6 @@
#include "defs.h"
#include "../xbps-repo/defs.h"
static void cleanup(int);
static void usage(void);
static int list_pkgs_in_dict(prop_object_t, void *, bool *);
static void
usage(void)
{
@@ -109,6 +105,14 @@ list_manual_packages(prop_object_t obj, void *arg, bool *loop_done)
return 0;
}
static void
cleanup(int signum)
{
xbps_regpkgs_dictionary_release();
exit(signum);
}
int
main(int argc, char **argv)
{
@@ -332,10 +336,3 @@ main(int argc, char **argv)
out:
cleanup(rv);
}
static void
cleanup(int signum)
{
xbps_regpkgs_dictionary_release();
exit(signum);
}

View File

@@ -130,7 +130,7 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force)
* First check if package is required by other packages.
*/
for (i = 1; i < argc; i++) {
dict = xbps_find_pkg_installed_from_plist(argv[i]);
dict = xbps_find_pkg_dict_installed(argv[i], false);
if (dict == NULL) {
printf("Package %s is not installed.\n", argv[i]);
continue;
@@ -155,7 +155,7 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force)
*/
printf("The following packages will be removed:\n\n");
for (i = 1; i < argc; i++) {
dict = xbps_find_pkg_installed_from_plist(argv[i]);
dict = xbps_find_pkg_dict_installed(argv[i], false);
if (dict == NULL)
continue;
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
@@ -180,7 +180,7 @@ xbps_remove_installed_pkgs(int argc, char **argv, bool force)
printf("Forcing removal!\n");
for (i = 1; i < argc; i++) {
dict = xbps_find_pkg_installed_from_plist(argv[i]);
dict = xbps_find_pkg_dict_installed(argv[i], false);
if (dict == NULL)
continue;
prop_dictionary_get_cstring_nocopy(dict, "version", &version);

View File

@@ -42,7 +42,7 @@ xbps_show_pkg_deps(const char *pkgname)
assert(pkgname != NULL);
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (pkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
return 0;
@@ -79,7 +79,7 @@ xbps_show_pkg_reverse_deps(const char *pkgname)
prop_dictionary_t pkgd;
int rv = 0;
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
pkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (pkgd == NULL) {
printf("Package %s is not installed.\n", pkgname);
return 0;

View File

@@ -34,8 +34,6 @@
#include <xbps_api.h>
#include "defs.h"
static void usage(void);
static void
usage(void)
{
@@ -122,7 +120,7 @@ main(int argc, char **argv)
if (argc != 1)
usage();
SIMPLEQ_FOREACH(rpool, &repopool_queue, chain)
SIMPLEQ_FOREACH(rpool, &rp_queue, rp_entries)
printf("%s\n", rpool->rp_uri);
} else if ((strcasecmp(argv[0], "rm") == 0) ||
@@ -141,7 +139,7 @@ main(int argc, char **argv)
if (argc != 2)
usage();
SIMPLEQ_FOREACH(rpool, &repopool_queue, chain) {
SIMPLEQ_FOREACH(rpool, &rp_queue, rp_entries) {
printf("From %s repository ...\n", rpool->rp_uri);
(void)xbps_callback_array_iter_in_dict(rpool->rp_repod,
"packages", show_pkg_namedesc, argv[1]);

View File

@@ -222,7 +222,7 @@ show_pkg_info_from_repolist(const char *pkgname)
prop_dictionary_t repo_pkgd, pkg_propsd;
int rv = 0;
SIMPLEQ_FOREACH(rp, &repopool_queue, chain) {
SIMPLEQ_FOREACH(rp, &rp_queue, rp_entries) {
char *url = NULL;
repo_pkgd = xbps_find_pkg_in_dict_by_name(rp->rp_repod,
"packages", pkgname);
@@ -264,7 +264,7 @@ show_pkg_deps_from_repolist(const char *pkgname)
const char *ver;
int rv = 0;
SIMPLEQ_FOREACH(rd, &repopool_queue, chain) {
SIMPLEQ_FOREACH(rd, &rp_queue, rp_entries) {
pkgd = xbps_find_pkg_in_dict_by_name(rd->rp_repod,
"packages", pkgname);
if (pkgd == NULL) {
@@ -294,7 +294,7 @@ repository_sync(void)
char *plist;
int rv = 0;
SIMPLEQ_FOREACH(rp, &repopool_queue, chain) {
SIMPLEQ_FOREACH(rp, &rp_queue, rp_entries) {
if (!xbps_check_is_repo_string_remote(rp->rp_uri))
continue;

View File

@@ -191,7 +191,7 @@ show_pkg_namedesc(prop_object_t obj, void *arg, bool *loop_done)
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "short_desc", &desc);
if (xbps_pkgdep_match(pkgver, pattern) == 1)
if (xbps_pkgpattern_match(pkgver, pattern) == 1)
printf(" %s - %s\n", pkgver, desc);
else if (strcmp(pkgname, pattern) == 0)
printf(" %s - %s\n", pkgver, desc);

View File

@@ -273,7 +273,7 @@ main(int argc, char **argv)
if (argc != 2)
usage();
pkgname = xbps_get_pkgdep_name(argv[1]);
pkgname = xbps_get_pkgpattern_name(argv[1]);
if (pkgname == NULL)
exit(EXIT_FAILURE);
@@ -285,7 +285,7 @@ main(int argc, char **argv)
if (argc != 3)
usage();
exit(xbps_pkgdep_match(argv[1], argv[2]));
exit(xbps_pkgpattern_match(argv[1], argv[2]));
} else if (strcasecmp(argv[0], "cmpver") == 0) {
/* Compare two version strings, installed vs required */