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:
parent
e71e3e9958
commit
2857214afa
@ -192,9 +192,13 @@ autoupdate_pkgs(bool yes, bool show_download_pkglist_url)
|
|||||||
if (rv == ENOENT) {
|
if (rv == ENOENT) {
|
||||||
printf("No packages currently registered.\n");
|
printf("No packages currently registered.\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else if (rv == ENXIO) {
|
} else if (rv == EEXIST) {
|
||||||
printf("All packages are up-to-date.\n");
|
printf("All packages are up-to-date.\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
} else if (rv == ENOTSUP) {
|
||||||
|
xbps_error_printf("xbps-bin: no repositories currently "
|
||||||
|
"registered!\n");
|
||||||
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
||||||
strerror(rv));
|
strerror(rv));
|
||||||
@ -246,8 +250,11 @@ install_new_pkg(const char *pkg)
|
|||||||
}
|
}
|
||||||
if ((rv = xbps_repository_install_pkg(pkgpatt)) != 0) {
|
if ((rv = xbps_repository_install_pkg(pkgpatt)) != 0) {
|
||||||
if (rv == ENOENT) {
|
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);
|
"repository pool.\n", pkg);
|
||||||
|
} else if (rv == ENOTSUP) {
|
||||||
|
xbps_error_printf("xbps-bin: no repositories "
|
||||||
|
"currently registered!\n");
|
||||||
} else {
|
} else {
|
||||||
xbps_error_printf("xbps-bin: unexpected error: %s\n",
|
xbps_error_printf("xbps-bin: unexpected error: %s\n",
|
||||||
strerror(rv));
|
strerror(rv));
|
||||||
@ -275,6 +282,9 @@ update_pkg(const char *pkgname)
|
|||||||
"repository pool.\n", pkgname);
|
"repository pool.\n", pkgname);
|
||||||
else if (rv == ENODEV)
|
else if (rv == ENODEV)
|
||||||
printf("Package '%s' not installed.\n", pkgname);
|
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) {
|
else if (rv != 0) {
|
||||||
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
xbps_error_printf("xbps-bin: unexpected error %s\n",
|
||||||
strerror(rv));
|
strerror(rv));
|
||||||
|
@ -154,7 +154,13 @@ main(int argc, char **argv)
|
|||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
usage();
|
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) {
|
} else if (strcasecmp(argv[0], "search") == 0) {
|
||||||
/*
|
/*
|
||||||
@ -164,7 +170,13 @@ main(int argc, char **argv)
|
|||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
usage();
|
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) {
|
} else if (strcasecmp(argv[0], "show") == 0) {
|
||||||
/* Shows info about a binary package. */
|
/* Shows info about a binary package. */
|
||||||
@ -175,11 +187,12 @@ main(int argc, char **argv)
|
|||||||
if (rv == ENOENT) {
|
if (rv == ENOENT) {
|
||||||
xbps_printf("Unable to locate package "
|
xbps_printf("Unable to locate package "
|
||||||
"`%s' in repository pool.\n", argv[1]);
|
"`%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) {
|
} else if (rv != 0 && rv != ENOENT) {
|
||||||
xbps_error_printf("xbps-repo: unexpected error '%s' ",
|
xbps_error_printf("xbps-repo: unexpected error '%s' ",
|
||||||
"searching for '%s'\n", strerror(rv), argv[1]);
|
"searching for '%s'\n", strerror(rv), argv[1]);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "show-deps") == 0) {
|
} else if (strcasecmp(argv[0], "show-deps") == 0) {
|
||||||
@ -191,11 +204,12 @@ main(int argc, char **argv)
|
|||||||
if (rv == ENOENT) {
|
if (rv == ENOENT) {
|
||||||
xbps_printf("Unable to locate package "
|
xbps_printf("Unable to locate package "
|
||||||
"`%s' in repository pool.\n", argv[1]);
|
"`%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) {
|
} else if (rv != 0 && rv != ENOENT) {
|
||||||
xbps_error_printf("xbps-repo: unexpected error '%s' "
|
xbps_error_printf("xbps-repo: unexpected error '%s' "
|
||||||
"searching for '%s'\n", strerror(errno), argv[1]);
|
"searching for '%s'\n", strerror(errno), argv[1]);
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcasecmp(argv[0], "show-files") == 0) {
|
} 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],
|
pkgd = xbps_repository_pool_dictionary_metadata_plist(argv[1],
|
||||||
XBPS_PKGFILES);
|
XBPS_PKGFILES);
|
||||||
if (pkgd == NULL) {
|
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 "
|
xbps_error_printf("xbps-repo: unexpected "
|
||||||
"error '%s' searching for '%s'\n",
|
"error '%s' searching for '%s'\n",
|
||||||
strerror(errno), argv[1]);
|
strerror(errno), argv[1]);
|
||||||
} else {
|
|
||||||
xbps_printf("Unable to locate package `%s' "
|
|
||||||
"in repository pool.\n", argv[1]);
|
|
||||||
}
|
}
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
goto out;
|
||||||
@ -226,6 +243,10 @@ main(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
rv = repo_find_files_in_packages(argv[1]);
|
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) {
|
} else if (strcasecmp(argv[0], "genindex") == 0) {
|
||||||
/* Generates a package repository index plist file. */
|
/* Generates a package repository index plist file. */
|
||||||
@ -240,6 +261,10 @@ main(int argc, char **argv)
|
|||||||
usage();
|
usage();
|
||||||
|
|
||||||
rv = repository_sync();
|
rv = repository_sync();
|
||||||
|
if (rv == ENOTSUP) {
|
||||||
|
xbps_error_printf("xbps-repo: no repositories "
|
||||||
|
"currently registered!\n");
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
usage();
|
usage();
|
||||||
|
@ -55,7 +55,7 @@
|
|||||||
*/
|
*/
|
||||||
#define XBPS_PKGINDEX_VERSION "1.2"
|
#define XBPS_PKGINDEX_VERSION "1.2"
|
||||||
|
|
||||||
#define XBPS_API_VERSION "20110728"
|
#define XBPS_API_VERSION "20110729"
|
||||||
#define XBPS_VERSION "0.10.0"
|
#define XBPS_VERSION "0.10.0"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,6 +185,9 @@ xbps_repository_update_packages(void)
|
|||||||
bool newpkg_found = false;
|
bool newpkg_found = false;
|
||||||
|
|
||||||
xhp = xbps_handle_get();
|
xhp = xbps_handle_get();
|
||||||
|
if (xhp->regpkgdb_dictionary == NULL)
|
||||||
|
return ENOENT;
|
||||||
|
|
||||||
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
|
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
@ -214,7 +217,7 @@ xbps_repository_update_packages(void)
|
|||||||
prop_object_iterator_release(iter);
|
prop_object_iterator_release(iter);
|
||||||
|
|
||||||
if (!newpkg_found)
|
if (!newpkg_found)
|
||||||
rv = ENXIO;
|
rv = EEXIST;
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -123,12 +123,12 @@ xbps_repository_pool_init(void)
|
|||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
ntotal++;
|
||||||
if (sync_remote_repo(plist, repouri) == -1) {
|
if (sync_remote_repo(plist, repouri) == -1) {
|
||||||
nmissing++;
|
nmissing++;
|
||||||
free(plist);
|
free(plist);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
ntotal++;
|
|
||||||
/*
|
/*
|
||||||
* Iterate over the repository pool and add the dictionary
|
* Iterate over the repository pool and add the dictionary
|
||||||
* for current repository into the queue.
|
* for current repository into the queue.
|
||||||
@ -166,14 +166,14 @@ xbps_repository_pool_init(void)
|
|||||||
free(plist);
|
free(plist);
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
xbps_dbg_printf("%s: missing pkg-index.plist "
|
xbps_dbg_printf("[rpool] missing pkg-index.plist "
|
||||||
"for '%s' repository.\n", __func__, repouri);
|
"for '%s' repository.\n", repouri);
|
||||||
nmissing++;
|
nmissing++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
rv = errno;
|
rv = errno;
|
||||||
xbps_dbg_printf("%s: cannot internalize plist %s: %s\n",
|
xbps_dbg_printf("[rpool] cannot internalize plist %s: %s\n",
|
||||||
__func__, plist, strerror(rv));
|
plist, strerror(rv));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
free(plist);
|
free(plist);
|
||||||
@ -182,11 +182,14 @@ xbps_repository_pool_init(void)
|
|||||||
SIMPLEQ_INSERT_TAIL(&rpool_queue, rpool, rp_entries);
|
SIMPLEQ_INSERT_TAIL(&rpool_queue, rpool, rp_entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ntotal - nmissing == 0)
|
if (ntotal - nmissing == 0) {
|
||||||
|
/* no repositories available, error out */
|
||||||
|
rv = ENOTSUP;
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
repolist_initialized = true;
|
repolist_initialized = true;
|
||||||
xbps_dbg_printf("%s: initialized ok.\n", __func__);
|
xbps_dbg_printf("[rpool] initialized ok.\n");
|
||||||
out:
|
out:
|
||||||
if (iter)
|
if (iter)
|
||||||
prop_object_iterator_release(iter);
|
prop_object_iterator_release(iter);
|
||||||
@ -218,7 +221,7 @@ xbps_repository_pool_release(void)
|
|||||||
|
|
||||||
}
|
}
|
||||||
repolist_initialized = false;
|
repolist_initialized = false;
|
||||||
xbps_dbg_printf("%s: released ok.\n", __func__);
|
xbps_dbg_printf("[rpool] released ok.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -236,13 +239,11 @@ xbps_repository_pool_foreach(
|
|||||||
*/
|
*/
|
||||||
if ((rv = xbps_repository_pool_init()) != 0) {
|
if ((rv = xbps_repository_pool_init()) != 0) {
|
||||||
if (rv == ENOTSUP) {
|
if (rv == ENOTSUP) {
|
||||||
xbps_dbg_printf("%s: empty repository list.\n",
|
xbps_dbg_printf("[rpool] empty repository list.\n");
|
||||||
__func__);
|
|
||||||
} else if (rv != ENOENT && rv != ENOTSUP) {
|
} else if (rv != ENOENT && rv != ENOTSUP) {
|
||||||
xbps_dbg_printf("%s: couldn't initialize "
|
xbps_dbg_printf("[rpool] couldn't initialize: %s\n",
|
||||||
"repository pool: %s\n", __func__, strerror(rv));
|
strerror(rv));
|
||||||
}
|
}
|
||||||
xbps_end(xbps_handle_get());
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,7 +340,7 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
|
|||||||
if (errno && errno != ENOENT)
|
if (errno && errno != ENOENT)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
xbps_dbg_printf("Package '%s' not found in repository "
|
xbps_dbg_printf("[rpool] Package '%s' not found in repository "
|
||||||
"'%s'.\n", rpf->pattern, rpi->rpi_uri);
|
"'%s'.\n", rpf->pattern, rpi->rpi_uri);
|
||||||
} else {
|
} else {
|
||||||
/*
|
/*
|
||||||
@ -356,8 +357,9 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
|
|||||||
prop_object_release(instpkgd);
|
prop_object_release(instpkgd);
|
||||||
|
|
||||||
if (xbps_cmpver(repover, instver) <= 0) {
|
if (xbps_cmpver(repover, instver) <= 0) {
|
||||||
xbps_dbg_printf("Skipping '%s-%s' (installed: %s) "
|
xbps_dbg_printf("[rpool] Skipping '%s-%s' "
|
||||||
"from repository '%s'\n", rpf->pattern, repover, instver,
|
"(installed: %s) from repository `%s'\n",
|
||||||
|
rpf->pattern, repover, instver,
|
||||||
rpi->rpi_uri);
|
rpi->rpi_uri);
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
return 0;
|
return 0;
|
||||||
@ -365,7 +367,7 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
|
|||||||
/*
|
/*
|
||||||
* New package version found, exit from the loop.
|
* New package version found, exit from the loop.
|
||||||
*/
|
*/
|
||||||
xbps_dbg_printf("Found '%s-%s' (installed: %s) "
|
xbps_dbg_printf("[rpool] Found '%s-%s' (installed: %s) "
|
||||||
"in repository '%s'.\n", rpf->pattern, repover,
|
"in repository '%s'.\n", rpf->pattern, repover,
|
||||||
instver, rpi->rpi_uri);
|
instver, rpi->rpi_uri);
|
||||||
prop_dictionary_set_cstring(rpf->pkgd, "repository",
|
prop_dictionary_set_cstring(rpf->pkgd, "repository",
|
||||||
|
@ -122,8 +122,8 @@ xbps_repository_sync_pkg_index(const char *uri)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if ((rv = xbps_mkpath(metadir, 0755)) == -1) {
|
if ((rv = xbps_mkpath(metadir, 0755)) == -1) {
|
||||||
xbps_dbg_printf("%s: failed to create metadir `%s': %s\n",
|
xbps_dbg_printf("[rsyncidx] failed to create metadir `%s': "
|
||||||
__func__, metadir, strerror(errno));
|
"%s\n", metadir, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -144,8 +144,8 @@ xbps_repository_sync_pkg_index(const char *uri)
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Full path to local repository directory to store the
|
* Full path to repository directory to store the pkg-index.plist
|
||||||
* package index file.
|
* file.
|
||||||
*/
|
*/
|
||||||
lrepodir = xbps_xasprintf("%s/%s/%s",
|
lrepodir = xbps_xasprintf("%s/%s/%s",
|
||||||
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
|
xhp->rootdir, XBPS_META_PATH, uri_fixedp);
|
||||||
@ -200,14 +200,20 @@ xbps_repository_sync_pkg_index(const char *uri)
|
|||||||
/*
|
/*
|
||||||
* Create local repodir to store pkg-index.plist file.
|
* Create local repodir to store pkg-index.plist file.
|
||||||
*/
|
*/
|
||||||
if ((rv = xbps_mkpath(lrepodir, 0755)) == -1)
|
if ((rv = xbps_mkpath(lrepodir, 0755)) == -1) {
|
||||||
|
xbps_dbg_printf("[rsyncidx] failed to create repodir "
|
||||||
|
"`%s': %s\n", lrepodir, strerror(errno));
|
||||||
goto out;
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Rename to destination file now it has been fetched successfully.
|
* Rename to destination file now it has been fetched successfully.
|
||||||
*/
|
*/
|
||||||
if ((rv = rename(tmp_metafile, lrepofile)) == 0)
|
if ((rv = rename(tmp_metafile, lrepofile)) == -1)
|
||||||
rv = 1;
|
xbps_dbg_printf("[rsyncidx] failed to rename `%s' to "
|
||||||
|
"`%s': %s\n", tmp_metafile, lrepofile, strerror(errno));
|
||||||
|
else
|
||||||
|
rv = 1; /* success */
|
||||||
|
|
||||||
out:
|
out:
|
||||||
if (rpidx)
|
if (rpidx)
|
||||||
|
Loading…
Reference in New Issue
Block a user