libxbps: improve returned errnos for repository API functions.
- xbps_repository_update_packages: return ENOENT if regpkgdb is NULL (no packages currently registered). - xbps_repository_update_packages: return EEXIST if no updates are available. - xbps_repository_pool: return ENOTSUP if no repositories were registered. - make xbps-{bin,repo} handle ENOTSUP errors.
This commit is contained in:
@@ -192,9 +192,13 @@ autoupdate_pkgs(bool yes, bool show_download_pkglist_url)
|
||||
if (rv == ENOENT) {
|
||||
printf("No packages currently registered.\n");
|
||||
return 0;
|
||||
} else if (rv == ENXIO) {
|
||||
} else if (rv == EEXIST) {
|
||||
printf("All packages are up-to-date.\n");
|
||||
return 0;
|
||||
} else if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-bin: no repositories currently "
|
||||
"registered!\n");
|
||||
return -1;
|
||||
} else {
|
||||
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
||||
strerror(rv));
|
||||
@@ -246,8 +250,11 @@ install_new_pkg(const char *pkg)
|
||||
}
|
||||
if ((rv = xbps_repository_install_pkg(pkgpatt)) != 0) {
|
||||
if (rv == ENOENT) {
|
||||
fprintf(stderr, "xbps-bin: unable to locate '%s' in "
|
||||
xbps_error_printf("xbps-bin: unable to locate '%s' in "
|
||||
"repository pool.\n", pkg);
|
||||
} else if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-bin: no repositories "
|
||||
"currently registered!\n");
|
||||
} else {
|
||||
xbps_error_printf("xbps-bin: unexpected error: %s\n",
|
||||
strerror(rv));
|
||||
@@ -275,6 +282,9 @@ update_pkg(const char *pkgname)
|
||||
"repository pool.\n", pkgname);
|
||||
else if (rv == ENODEV)
|
||||
printf("Package '%s' not installed.\n", pkgname);
|
||||
else if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-bin: no repositories currently "
|
||||
"registered!\n");
|
||||
else if (rv != 0) {
|
||||
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
||||
strerror(rv));
|
||||
|
@@ -154,7 +154,13 @@ main(int argc, char **argv)
|
||||
if (argc != 1)
|
||||
usage();
|
||||
|
||||
xbps_repository_pool_foreach(repo_list_uri_cb, NULL);
|
||||
rv = xbps_repository_pool_foreach(repo_list_uri_cb, NULL);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
else if (rv != 0 && rv != ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: failed to initialize "
|
||||
"rpool: %s\n", strerror(rv));
|
||||
|
||||
} else if (strcasecmp(argv[0], "search") == 0) {
|
||||
/*
|
||||
@@ -164,7 +170,13 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
xbps_repository_pool_foreach(repo_search_pkgs_cb, argv[1]);
|
||||
rv = xbps_repository_pool_foreach(repo_search_pkgs_cb, argv[1]);
|
||||
if (rv == ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
else if (rv != 0 && rv != ENOTSUP)
|
||||
xbps_error_printf("xbps-repo: failed to initialize "
|
||||
"rpool: %s\n", strerror(rv));
|
||||
|
||||
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||
/* Shows info about a binary package. */
|
||||
@@ -175,11 +187,12 @@ main(int argc, char **argv)
|
||||
if (rv == ENOENT) {
|
||||
xbps_printf("Unable to locate package "
|
||||
"`%s' in repository pool.\n", argv[1]);
|
||||
goto out;
|
||||
} else if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
} else if (rv != 0 && rv != ENOENT) {
|
||||
xbps_error_printf("xbps-repo: unexpected error '%s' ",
|
||||
"searching for '%s'\n", strerror(rv), argv[1]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "show-deps") == 0) {
|
||||
@@ -191,11 +204,12 @@ main(int argc, char **argv)
|
||||
if (rv == ENOENT) {
|
||||
xbps_printf("Unable to locate package "
|
||||
"`%s' in repository pool.\n", argv[1]);
|
||||
goto out;
|
||||
} else if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
} else if (rv != 0 && rv != ENOENT) {
|
||||
xbps_error_printf("xbps-repo: unexpected error '%s' "
|
||||
"searching for '%s'\n", strerror(errno), argv[1]);
|
||||
goto out;
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "show-files") == 0) {
|
||||
@@ -206,13 +220,16 @@ main(int argc, char **argv)
|
||||
pkgd = xbps_repository_pool_dictionary_metadata_plist(argv[1],
|
||||
XBPS_PKGFILES);
|
||||
if (pkgd == NULL) {
|
||||
if (errno != ENOENT) {
|
||||
if (errno == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
} else if (errno == ENOENT) {
|
||||
xbps_printf("Unable to locate package `%s' "
|
||||
"in repository pool.\n", argv[1]);
|
||||
} else {
|
||||
xbps_error_printf("xbps-repo: unexpected "
|
||||
"error '%s' searching for '%s'\n",
|
||||
strerror(errno), argv[1]);
|
||||
} else {
|
||||
xbps_printf("Unable to locate package `%s' "
|
||||
"in repository pool.\n", argv[1]);
|
||||
}
|
||||
rv = errno;
|
||||
goto out;
|
||||
@@ -226,6 +243,10 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
|
||||
rv = repo_find_files_in_packages(argv[1]);
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
}
|
||||
|
||||
} else if (strcasecmp(argv[0], "genindex") == 0) {
|
||||
/* Generates a package repository index plist file. */
|
||||
@@ -240,6 +261,10 @@ main(int argc, char **argv)
|
||||
usage();
|
||||
|
||||
rv = repository_sync();
|
||||
if (rv == ENOTSUP) {
|
||||
xbps_error_printf("xbps-repo: no repositories "
|
||||
"currently registered!\n");
|
||||
}
|
||||
|
||||
} else {
|
||||
usage();
|
||||
|
Reference in New Issue
Block a user