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:
Juan RP 2011-07-29 11:17:34 +02:00
parent e71e3e9958
commit 2857214afa
6 changed files with 84 additions and 38 deletions

View File

@ -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));

View File

@ -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();

View File

@ -55,7 +55,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.2"
#define XBPS_API_VERSION "20110728"
#define XBPS_API_VERSION "20110729"
#define XBPS_VERSION "0.10.0"
/**

View File

@ -185,6 +185,9 @@ xbps_repository_update_packages(void)
bool newpkg_found = false;
xhp = xbps_handle_get();
if (xhp->regpkgdb_dictionary == NULL)
return ENOENT;
iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages");
if (iter == NULL)
return ENOENT;
@ -214,7 +217,7 @@ xbps_repository_update_packages(void)
prop_object_iterator_release(iter);
if (!newpkg_found)
rv = ENXIO;
rv = EEXIST;
return rv;
}

View File

@ -123,12 +123,12 @@ xbps_repository_pool_init(void)
rv = errno;
goto out;
}
ntotal++;
if (sync_remote_repo(plist, repouri) == -1) {
nmissing++;
free(plist);
continue;
}
ntotal++;
/*
* Iterate over the repository pool and add the dictionary
* for current repository into the queue.
@ -166,14 +166,14 @@ xbps_repository_pool_init(void)
free(plist);
if (errno == ENOENT) {
errno = 0;
xbps_dbg_printf("%s: missing pkg-index.plist "
"for '%s' repository.\n", __func__, repouri);
xbps_dbg_printf("[rpool] missing pkg-index.plist "
"for '%s' repository.\n", repouri);
nmissing++;
continue;
}
rv = errno;
xbps_dbg_printf("%s: cannot internalize plist %s: %s\n",
__func__, plist, strerror(rv));
xbps_dbg_printf("[rpool] cannot internalize plist %s: %s\n",
plist, strerror(rv));
goto out;
}
free(plist);
@ -182,11 +182,14 @@ xbps_repository_pool_init(void)
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;
}
repolist_initialized = true;
xbps_dbg_printf("%s: initialized ok.\n", __func__);
xbps_dbg_printf("[rpool] initialized ok.\n");
out:
if (iter)
prop_object_iterator_release(iter);
@ -218,7 +221,7 @@ xbps_repository_pool_release(void)
}
repolist_initialized = false;
xbps_dbg_printf("%s: released ok.\n", __func__);
xbps_dbg_printf("[rpool] released ok.\n");
}
int
@ -236,13 +239,11 @@ xbps_repository_pool_foreach(
*/
if ((rv = xbps_repository_pool_init()) != 0) {
if (rv == ENOTSUP) {
xbps_dbg_printf("%s: empty repository list.\n",
__func__);
xbps_dbg_printf("[rpool] empty repository list.\n");
} else if (rv != ENOENT && rv != ENOTSUP) {
xbps_dbg_printf("%s: couldn't initialize "
"repository pool: %s\n", __func__, strerror(rv));
xbps_dbg_printf("[rpool] couldn't initialize: %s\n",
strerror(rv));
}
xbps_end(xbps_handle_get());
return rv;
}
@ -339,7 +340,7 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
if (errno && errno != ENOENT)
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);
} else {
/*
@ -356,8 +357,9 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
prop_object_release(instpkgd);
if (xbps_cmpver(repover, instver) <= 0) {
xbps_dbg_printf("Skipping '%s-%s' (installed: %s) "
"from repository '%s'\n", rpf->pattern, repover, instver,
xbps_dbg_printf("[rpool] Skipping '%s-%s' "
"(installed: %s) from repository `%s'\n",
rpf->pattern, repover, instver,
rpi->rpi_uri);
errno = EEXIST;
return 0;
@ -365,7 +367,7 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
/*
* 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,
instver, rpi->rpi_uri);
prop_dictionary_set_cstring(rpf->pkgd, "repository",

View File

@ -122,8 +122,8 @@ xbps_repository_sync_pkg_index(const char *uri)
goto out;
}
if ((rv = xbps_mkpath(metadir, 0755)) == -1) {
xbps_dbg_printf("%s: failed to create metadir `%s': %s\n",
__func__, metadir, strerror(errno));
xbps_dbg_printf("[rsyncidx] failed to create metadir `%s': "
"%s\n", metadir, strerror(errno));
goto out;
}
/*
@ -144,8 +144,8 @@ xbps_repository_sync_pkg_index(const char *uri)
goto out;
}
/*
* Full path to local repository directory to store the
* package index file.
* Full path to repository directory to store the pkg-index.plist
* file.
*/
lrepodir = xbps_xasprintf("%s/%s/%s",
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.
*/
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;
}
/*
* Rename to destination file now it has been fetched successfully.
*/
if ((rv = rename(tmp_metafile, lrepofile)) == 0)
rv = 1;
if ((rv = rename(tmp_metafile, lrepofile)) == -1)
xbps_dbg_printf("[rsyncidx] failed to rename `%s' to "
"`%s': %s\n", tmp_metafile, lrepofile, strerror(errno));
else
rv = 1; /* success */
out:
if (rpidx)