Use xbps_{error,warn}_printf() everywhere.

This commit is contained in:
Juan RP 2011-01-30 18:23:33 +01:00
parent e04f167d09
commit fca3d6b9bf
8 changed files with 77 additions and 81 deletions

View File

@ -48,28 +48,25 @@ struct transaction {
size_t cf_pkgcnt;
};
static int
show_missing_dep_cb(prop_object_t obj, void *arg, bool *loop_done)
{
(void)arg;
(void)loop_done;
fprintf(stderr, " * Missing binary package for: %s\n",
prop_string_cstring_nocopy(obj));
return 0;
}
static void
show_missing_deps(prop_array_t a)
{
prop_object_t obj;
size_t i;
fprintf(stderr,
"xbps-bin: unable to locate some required packages:\n");
(void)xbps_callback_array_iter(a, show_missing_dep_cb, NULL);
for (i = 0; i < prop_array_count(a); i++) {
obj = prop_array_get(a, i);
fprintf(stderr, " * Missing binary package for: %s\n",
prop_string_cstring_nocopy(obj));
}
}
static int
check_binpkg_hash(const char *path, const char *filename,
check_binpkg_hash(const char *path,
const char *filename,
const char *sha256)
{
int rv;
@ -77,12 +74,12 @@ check_binpkg_hash(const char *path, const char *filename,
printf("Checking %s integrity... ", filename);
rv = xbps_check_file_hash(path, sha256);
if (rv != 0 && rv != ERANGE) {
fprintf(stderr, "\nxbps-bin: unexpected error: %s\n",
xbps_error_printf("\nxbps-bin: unexpected error: %s\n",
strerror(rv));
return rv;
} else if (rv == ERANGE) {
printf("hash mismatch!\n");
fprintf(stderr, "Package '%s' has wrong checksum, removing "
xbps_warn_printf("Package '%s' has wrong checksum, removing "
"and refetching it again...\n", filename);
(void)remove(path);
return rv;
@ -151,9 +148,9 @@ again:
rv = xbps_fetch_file(binfile, cachedir, false, NULL,
fetch_file_progress_cb, &xfpd);
if (rv == -1) {
fprintf(stderr, "xbps-bin: couldn't download `%s'\n",
xbps_error_printf("xbps-bin: couldn't download `%s'\n",
filename);
fprintf(stderr, "xbps-bin: %s returned: `%s'\n",
xbps_error_printf("xbps-bin: %s returned: `%s'\n",
repoloc, xbps_fetch_error_string());
free(binfile);
return -1;
@ -248,13 +245,13 @@ show_transaction_sizes(struct transaction *trans)
prop_dictionary_get_uint64(trans->dict, "total-installed-size",
&instsize);
if (xbps_humanize_number(size, (int64_t)dlsize) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number returns "
xbps_error_printf("xbps-bin: error: humanize_number returns "
"%s\n", strerror(errno));
return -1;
}
printf("Total download size:\t%6s\n", size);
if (xbps_humanize_number(size, (int64_t)instsize) == -1) {
fprintf(stderr, "xbps-bin: error: humanize_number2 returns "
xbps_error_printf("xbps-bin: error: humanize_number2 returns "
"%s\n", strerror(errno));
return -1;
}
@ -291,7 +288,7 @@ xbps_autoupdate_pkgs(bool yes, bool show_download_pkglist_url)
printf("All packages are up-to-date.\n");
return 0;
} else {
fprintf(stderr, "xbps-bin: unexpected error %s\n",
xbps_error_printf("xbps-bin: unexpected error %s\n",
strerror(rv));
return -1;
}
@ -340,7 +337,7 @@ xbps_install_new_pkg(const char *pkg)
"repository pool.\n", pkg);
rv = -1;
} else {
fprintf(stderr, "xbps-bin: unexpected error: %s\n",
xbps_error_printf("xbps-bin: unexpected error: %s\n",
strerror(rv));
rv = -1;
}
@ -367,7 +364,7 @@ xbps_update_pkg(const char *pkgname)
else if (rv == ENODEV)
printf("Package '%s' not installed.\n", pkgname);
else if (rv != 0) {
fprintf(stderr, "xbps-bin: unexpected error %s\n",
xbps_error_printf("xbps-bin: unexpected error %s\n",
strerror(rv));
return -1;
}
@ -428,7 +425,7 @@ replace_packages(prop_dictionary_t trans_dict, prop_dictionary_t pkgd,
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",
xbps_error_printf("xbps-bin: couldn't remove %s (%s)\n",
reppkgn, strerror(rv));
return -1;
}
@ -556,7 +553,7 @@ exec_transaction(struct transaction *trans)
if (replaces_iter != NULL) {
rv = replace_packages(trans->dict, obj, replaces_iter, pkgver);
if (rv != 0) {
fprintf(stderr,
xbps_error_printf(
"xbps-bin: couldn't replace some "
"packages! (%s)\n", strerror(rv));
return rv;
@ -567,7 +564,7 @@ exec_transaction(struct transaction *trans)
if (strcmp(tract, "update") == 0) {
instpkgd = xbps_find_pkg_dict_installed(pkgname, false);
if (instpkgd == NULL) {
fprintf(stderr, "xbps-bin: error: unable to "
xbps_error_printf("xbps-bin: error: unable to "
"find %s installed dict!\n", pkgname);
return EINVAL;
}
@ -584,7 +581,7 @@ exec_transaction(struct transaction *trans)
pkgname, instver, version);
if ((rv = xbps_remove_pkg(pkgname, version, true)) != 0) {
fprintf(stderr, "xbps-bin: error "
xbps_error_printf("xbps-bin: error "
"replacing %s-%s (%s)\n", pkgname,
instver, strerror(rv));
return rv;
@ -604,7 +601,7 @@ exec_transaction(struct transaction *trans)
unpack_progress_cb_percentage, &xpd);
}
if (rv != 0) {
fprintf(stderr, "xbps-bin: error unpacking %s "
xbps_error_printf("xbps-bin: error unpacking %s "
"(%s)\n", pkgver, strerror(rv));
return rv;
}
@ -615,7 +612,7 @@ exec_transaction(struct transaction *trans)
* Register binary package.
*/
if ((rv = xbps_register_pkg(obj, autoinst)) != 0) {
fprintf(stderr, "xbps-bin: error registering %s "
xbps_error_printf("xbps-bin: error registering %s "
"(%s)\n", pkgver, strerror(rv));
return rv;
}
@ -634,7 +631,7 @@ exec_transaction(struct transaction *trans)
update = true;
rv = xbps_configure_pkg(pkgname, version, false, update);
if (rv != 0) {
fprintf(stderr, "xbps-bin: error configuring "
xbps_error_printf("xbps-bin: error configuring "
"package %s (%s)\n", pkgname, strerror(rv));
return rv;
}
@ -678,7 +675,7 @@ xbps_exec_transaction(bool yes, bool show_download_pkglist_url)
*/
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",
xbps_error_printf("xbps-bin: error allocating array mem! (%s)\n",
strerror(errno));
goto out;
}

View File

@ -439,5 +439,6 @@ main(int argc, char **argv)
}
out:
cleanup(rv);
xbps_end();
exit(rv);
}

View File

@ -41,7 +41,7 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
printf("Removing package %s-%s ...\n", pkgname, version);
if ((rv = xbps_remove_pkg(pkgname, version, false)) != 0) {
xbps_error_printf("unable to remove %s-%s (%s).\n",
xbps_error_printf("xbps-bin: unable to remove %s-%s (%s).\n",
pkgname, version, strerror(errno));
return rv;
}
@ -49,7 +49,7 @@ pkg_remove_and_purge(const char *pkgname, const char *version, bool purge)
printf(" Purging ... ");
(void)fflush(stdout);
if ((rv = xbps_purge_pkg(pkgname, false)) != 0) {
xbps_error_printf("unable to purge %s-%s "
xbps_error_printf("xbps-bin: unable to purge %s-%s "
"(%s).\n", pkgname, version,
strerror(errno));
return rv;

View File

@ -98,9 +98,9 @@ find_files_in_package(struct repository_pool_index *rpi, void *arg, bool *done)
XBPS_PKGFILES);
free(url);
if (pkg_filesd == NULL) {
fprintf(stderr, "E: couldn't get '%s' from '%s' "
"in repo '%s: %s'\n", XBPS_PKGFILES, pkgname, rpi->rpi_uri,
strerror(errno));
xbps_error_printf("xbps-repo: couldn't read '%s' "
"from '%s (%s)': %s\n", XBPS_PKGFILES, pkgname,
rpi->rpi_uri, strerror(errno));
rv = -1;
break;
}

View File

@ -107,7 +107,7 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
newpkgd = xbps_repository_plist_find_pkg_dict_from_url(file,
XBPS_PKGPROPS);
if (newpkgd == NULL) {
fprintf(stderr, "xbps-repo: can't read %s %s metadata "
xbps_error_printf("xbps-repo: can't read %s %s metadata "
"file, skipping!\n", file, XBPS_PKGPROPS);
goto out;
}
@ -129,7 +129,7 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
} else if (curpkgd) {
prop_dictionary_get_cstring_nocopy(curpkgd, "version", &regver);
if (xbps_cmpver(version, regver) <= 0) {
fprintf(stderr, "W: skipping %s. %s-%s already "
xbps_warn_printf("skipping %s. %s-%s already "
"registered.\n", filen, pkgname, regver);
prop_object_release(newpkgd);
rv = EEXIST;
@ -149,8 +149,9 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
goto out;
}
if (remove(oldfilepath) == -1) {
fprintf(stderr, "E: Couldn't remove old package file "
"'%s'! (%s)\n", oldfilepath, strerror(errno));
xbps_error_printf("xbps-repo: couldn't remove old "
"package file `%s': %s\n", oldfilepath,
strerror(errno));
free(oldfilepath);
prop_object_release(newpkgd);
rv = errno;
@ -165,13 +166,13 @@ xbps_repo_addpkg_index(prop_dictionary_t idxdict, const char *filedir,
}
if (!xbps_remove_pkg_from_dict_by_name(idxdict,
"packages", pkgname)) {
fprintf(stderr, "E: couldn't remove %s dict from "
"index (%s)\n", pkgname, strerror(errno));
xbps_error_printf("xbps-repo: couldn't remove `%s' "
"from plist index: %s\n", pkgname, strerror(errno));
prop_object_release(newpkgd);
free(tmpstr);
goto out;
}
fprintf(stderr, "W: removed outdated binpkg file for "
xbps_warn_printf("xbps-repo: removed outdated binpkg file for "
"'%s'.\n", tmpstr);
free(tmpstr);
}
@ -292,8 +293,8 @@ xbps_repo_genindex(const char *pkgdir)
dirp = opendir(path);
if (dirp == NULL) {
fprintf(stderr, "E: unexistent '%s' directory!\n",
path);
xbps_error_printf("xbps-repo: unexistent '%s' "
"directory!\n", path);
free(path);
continue;
}

View File

@ -113,8 +113,8 @@ main(int argc, char **argv)
if ((rv = xbps_repository_pool_init()) != 0) {
if (rv != ENOENT) {
fprintf(stderr, "E: cannot get repository list pool! %s\n",
strerror(rv));
xbps_error_printf("xbps-repo: failed to initialize "
"repository pool: %s\n", strerror(rv));
exit(EXIT_FAILURE);
}
}
@ -158,9 +158,9 @@ main(int argc, char **argv)
rv = show_pkg_info_from_repolist(argv[1]);
if (rv == 0 && errno == ENOENT) {
fprintf(stderr,
"Unable to locate package '%s' from "
"repository pool.\n", argv[1]);
xbps_error_printf("xbps-repo: unable to locate "
"`%s' from repository pool: %s\n", argv[1],
strerror(rv));
rv = EINVAL;
goto out;
}
@ -172,9 +172,9 @@ main(int argc, char **argv)
rv = show_pkg_deps_from_repolist(argv[1]);
if (rv == 0 && errno == ENOENT) {
fprintf(stderr,
"Unable to locate package '%s' from "
"repository pool.\n", argv[1]);
xbps_error_printf("xbps-repo: unable to locate "
"`%s' from repository pool: %s\n", argv[1],
strerror(rv));
rv = EINVAL;
goto out;
}
@ -188,13 +188,12 @@ main(int argc, char **argv)
XBPS_PKGFILES);
if (pkgd == NULL) {
if (errno != ENOENT) {
fprintf(stderr, "xbps-repo: unexpected "
xbps_error_printf("xbps-repo: unexpected "
"error '%s' searching for '%s'\n",
strerror(errno), argv[1]);
} else {
fprintf(stderr,
"Package '%s' not found in repository "
"pool.\n", argv[1]);
xbps_error_printf("xbps-repo: `%s' not found "
"in repository pool.\n", argv[1]);
}
rv = errno;
goto out;

View File

@ -91,8 +91,8 @@ pkgindex_verify(const char *plist, const char *uri)
d = prop_dictionary_internalize_from_zfile(plist);
if (d == NULL) {
fprintf(stderr, "E: failed to add '%s' repository: %s\n",
uri, strerror(errno));
xbps_error_printf("xbps-repo: failed to add `%s' "
"repository: %s\n", uri, strerror(errno));
return NULL;
}
@ -103,22 +103,22 @@ pkgindex_verify(const char *plist, const char *uri)
if (!prop_dictionary_get_cstring(d,
"pkgindex-version", &rpi->pkgidxver)) {
fprintf(stderr,
"E: missing 'pkgindex-version' object!\n");
xbps_error_printf("xbps-repo: missing 'pkgindex-version' "
"object!\n");
rv = errno;
goto out;
}
if (!prop_dictionary_get_uint64(d, "total-pkgs",
&rpi->totalpkgs)) {
fprintf(stderr, "E: missing 'total-pkgs' object!\n");
xbps_error_printf("xbps-repo: missing 'total-pkgs' object!\n");
rv = errno;
goto out;
}
/* Reject empty repositories, how could this happen? :-) */
if (rpi->totalpkgs == 0) {
fprintf(stderr, "E: empty package list!\n");
xbps_error_printf("xbps-repo: `%s' empty package list!\n", uri);
rv = EINVAL;
goto out;
}
@ -126,9 +126,8 @@ pkgindex_verify(const char *plist, const char *uri)
out:
prop_object_release(d);
if (rv != 0) {
fprintf(stderr,
"W: removing incorrect pkg index file: '%s' ...\n",
plist);
xbps_error_printf("xbps-repo: removing incorrect "
"pkg-index file for `%s'.\n", uri);
(void)remove(plist);
if (rpi) {
free(rpi);
@ -151,11 +150,11 @@ unregister_repository(const char *uri)
return 0;
if (rv == ENOENT) {
fprintf(stderr, "Repository '%s' not actually "
xbps_error_printf("Repository '%s' not "
"registered.\n", idxstr);
} else {
fprintf(stderr, "E: couldn't unregister "
"repository (%s)\n", strerror(rv));
xbps_error_printf("xbps-repo: couldn't unregister "
"repository: %s\n", strerror(rv));
}
return rv;
@ -178,9 +177,8 @@ register_repository(const char *uri)
rv = xbps_repository_sync_pkg_index(idxstr,
fetch_file_progress_cb, &xfpd);
if (rv == -1) {
fprintf(stderr,
"E: could not fetch pkg index file: %s.\n",
xbps_fetch_error_string());
xbps_error_printf("xbps-repo: couldn't fetch pkg-index"
"file: %s.\n", xbps_fetch_error_string());
return rv;
} else if (rv == 0) {
printf("Package index file is already "
@ -199,9 +197,8 @@ register_repository(const char *uri)
return errno;
if (xbps_mkpath(metadir, 0755) == -1) {
fprintf(stderr,
"E: couldn't create metadata dir! (%s)\n",
strerror(errno));
xbps_error_printf("xbps-repo: couldn't create metadata "
"directory: %s.\n", strerror(errno));
free(metadir);
return EXIT_FAILURE;
}
@ -217,10 +214,10 @@ register_repository(const char *uri)
if ((rv = xbps_repository_register(idxstr)) != 0) {
if (rv == EEXIST) {
fprintf(stderr, "W: repository already registered.\n");
xbps_warn_printf("repository already registered.\n");
} else {
fprintf(stderr, "E: couldn't register repository "
"(%s)\n", strerror(errno));
xbps_error_printf("xbps-repo: couldn't register "
"repository: %s.\n", strerror(errno));
}
goto out;
}
@ -313,7 +310,8 @@ repo_sync_pkg_index_cb(struct repository_pool_index *rpi, void *arg, bool *done)
rv = xbps_repository_sync_pkg_index(rpi->rpi_uri,
fetch_file_progress_cb, &xfpd);
if (rv == -1) {
fprintf(stderr, "E: returned: %s\n", xbps_fetch_error_string());
xbps_error_printf("xbps-repo: failed to sync `%s': %s\n",
rpi->rpi_uri, xbps_fetch_error_string());
return rv;
} else if (rv == 0) {
printf("Package index file is already up to date.\n");

View File

@ -51,7 +51,7 @@ write_plist_file(prop_dictionary_t dict, const char *file)
if (!prop_dictionary_externalize_to_zfile(dict, file)) {
prop_object_release(dict);
printf("=> ERROR: couldn't write to %s (%s)",
xbps_error_printf("xbps-uhelper: couldn't write to %s: %s",
file, strerror(errno));
exit(EXIT_FAILURE);
}