diff --git a/bin/xbps-bin/Makefile b/bin/xbps-bin/Makefile index 3a34d986..2fa3ffad 100644 --- a/bin/xbps-bin/Makefile +++ b/bin/xbps-bin/Makefile @@ -4,7 +4,7 @@ TOPDIR = ../.. BIN = xbps-bin OBJS = check.o install.o main.o remove.o show-deps.o OBJS += show-info-files.o util.o find-files.o -OBJS += question.o fetch.o +OBJS += question.o fetch_cb.o trans_cb.o MAN = $(BIN).8 include $(TOPDIR)/prog.mk diff --git a/bin/xbps-bin/defs.h b/bin/xbps-bin/defs.h index ff5696f2..a8829df4 100644 --- a/bin/xbps-bin/defs.h +++ b/bin/xbps-bin/defs.h @@ -44,8 +44,6 @@ int update_pkg(const char *); int autoupdate_pkgs(bool, bool); int autoremove_pkgs(bool, bool); int exec_transaction(bool, bool); -void transaction_cb(struct xbps_transaction_cb_data *); -void transaction_err_cb(struct xbps_transaction_cb_data *); int remove_installed_pkgs(int, char **, bool, bool, bool, bool); @@ -68,9 +66,13 @@ int find_files_in_packages(const char *); bool yesno(const char *, ...); bool noyes(const char *, ...); -/* from fetch.c */ +/* from fetch_cb.c */ void fetch_file_progress_cb(struct xbps_fetch_cb_data *); +/* from trans_cb.c */ +void transaction_cb(struct xbps_transaction_cb_data *); +void transaction_err_cb(struct xbps_transaction_cb_data *); + /* From util.c */ int show_pkg_files(prop_dictionary_t); void show_pkg_info(prop_dictionary_t); diff --git a/bin/xbps-bin/fetch.c b/bin/xbps-bin/fetch_cb.c similarity index 100% rename from bin/xbps-bin/fetch.c rename to bin/xbps-bin/fetch_cb.c diff --git a/bin/xbps-bin/install.c b/bin/xbps-bin/install.c index c85586ec..149630b0 100644 --- a/bin/xbps-bin/install.c +++ b/bin/xbps-bin/install.c @@ -283,87 +283,6 @@ update_pkg(const char *pkgname) return 0; } -void -transaction_cb(struct xbps_transaction_cb_data *xtcd) -{ - if (xtcd->desc != NULL && xtcd->pkgver == NULL) { - printf("\n%s ...\n", xtcd->desc); - return; - } - - switch (xtcd->state) { - case XBPS_TRANS_STATE_DOWNLOAD: - printf("Downloading `%s' (from %s) ...\n", - xtcd->pkgver, xtcd->binpkg_repourl); - break; - case XBPS_TRANS_STATE_VERIFY: - printf("Checking `%s' integrity ...\n", xtcd->binpkg_fname); - break; - case XBPS_TRANS_STATE_REMOVE: - printf("Removing `%s' ...\n", xtcd->pkgver); - break; - case XBPS_TRANS_STATE_PURGE: - printf("Purging `%s' ...\n", xtcd->pkgver); - break; - case XBPS_TRANS_STATE_CONFIGURE: - printf("Configuring `%s' ...\n", xtcd->pkgver); - break; - case XBPS_TRANS_STATE_REGISTER: - case XBPS_TRANS_STATE_INSTALL: - break; - case XBPS_TRANS_STATE_UPDATE: - printf("Updating `%s' ...\n", xtcd->pkgver); - break; - case XBPS_TRANS_STATE_UNPACK: - printf("Unpacking `%s' (from ../%s) ...\n", - xtcd->pkgver, xtcd->binpkg_fname); - break; - default: - xbps_dbg_printf("%s: unknown transaction state %d %s\n", - xtcd->pkgver, xtcd->state, xtcd->desc); - break; - } -} - -void -transaction_err_cb(struct xbps_transaction_cb_data *xtcd) -{ - const char *state_descr = NULL; - - switch (xtcd->state) { - case XBPS_TRANS_STATE_DOWNLOAD: - state_descr = "failed to download binary package"; - break; - case XBPS_TRANS_STATE_VERIFY: - state_descr = "failed to verify binary package SHA256"; - break; - case XBPS_TRANS_STATE_REMOVE: - state_descr = "failed to remove package"; - break; - case XBPS_TRANS_STATE_PURGE: - state_descr = "failed to purge package"; - break; - case XBPS_TRANS_STATE_CONFIGURE: - state_descr = "failed to configure package"; - break; - case XBPS_TRANS_STATE_UPDATE: - state_descr = "failed to update package"; - break; - case XBPS_TRANS_STATE_UNPACK: - state_descr = "failed to unpack binary package"; - break; - case XBPS_TRANS_STATE_REGISTER: - state_descr = "failed to register package"; - break; - default: - state_descr = "unknown transaction state"; - break; - } - - xbps_error_printf("%s: %s: %s\n", - xtcd->pkgver, state_descr, strerror(xtcd->err)); -} - int exec_transaction(bool yes, bool show_download_urls) { diff --git a/bin/xbps-bin/trans_cb.c b/bin/xbps-bin/trans_cb.c new file mode 100644 index 00000000..782c45a3 --- /dev/null +++ b/bin/xbps-bin/trans_cb.c @@ -0,0 +1,117 @@ +/*- + * Copyright (c) 2011 Juan Romero Pardines. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include "defs.h" + +void +transaction_cb(struct xbps_transaction_cb_data *xtcd) +{ + if (xtcd->desc != NULL && xtcd->pkgver == NULL) { + printf("\n%s ...\n", xtcd->desc); + return; + } + + switch (xtcd->state) { + case XBPS_TRANS_STATE_DOWNLOAD: + printf("Downloading `%s' (from %s) ...\n", + xtcd->pkgver, xtcd->repourl); + break; + case XBPS_TRANS_STATE_VERIFY: + printf("Checking `%s' integrity ...\n", xtcd->binpkg_fname); + break; + case XBPS_TRANS_STATE_REMOVE: + printf("Removing `%s' ...\n", xtcd->pkgver); + break; + case XBPS_TRANS_STATE_PURGE: + printf("Purging `%s' ...\n", xtcd->pkgver); + break; + case XBPS_TRANS_STATE_CONFIGURE: + printf("Configuring `%s' ...\n", xtcd->pkgver); + break; + case XBPS_TRANS_STATE_REGISTER: + case XBPS_TRANS_STATE_INSTALL: + break; + case XBPS_TRANS_STATE_UPDATE: + printf("Updating `%s' ...\n", xtcd->pkgver); + break; + case XBPS_TRANS_STATE_UNPACK: + printf("Unpacking `%s' (from ../%s) ...\n", + xtcd->pkgver, xtcd->binpkg_fname); + break; + case XBPS_TRANS_STATE_REPOSYNC: + printf("Syncing repository pkg-index for `%s' ...\n", + xtcd->repourl); + break; + default: + xbps_dbg_printf("%s: unknown transaction state %d %s\n", + xtcd->pkgver, xtcd->state, xtcd->desc); + break; + } +} + +void +transaction_err_cb(struct xbps_transaction_cb_data *xtcd) +{ + const char *state_descr = NULL; + + switch (xtcd->state) { + case XBPS_TRANS_STATE_DOWNLOAD: + state_descr = "failed to download binary package"; + break; + case XBPS_TRANS_STATE_VERIFY: + state_descr = "failed to verify binary package SHA256"; + break; + case XBPS_TRANS_STATE_REMOVE: + state_descr = "failed to remove package"; + break; + case XBPS_TRANS_STATE_PURGE: + state_descr = "failed to purge package"; + break; + case XBPS_TRANS_STATE_CONFIGURE: + state_descr = "failed to configure package"; + break; + case XBPS_TRANS_STATE_UPDATE: + state_descr = "failed to update package"; + break; + case XBPS_TRANS_STATE_UNPACK: + state_descr = "failed to unpack binary package"; + break; + case XBPS_TRANS_STATE_REGISTER: + state_descr = "failed to register package"; + break; + case XBPS_TRANS_STATE_REPOSYNC: + xbps_error_printf("Failed to sync pkg-index: %s\n", + xtcd->err); + return; + default: + state_descr = "unknown transaction state"; + break; + } + + xbps_error_printf("%s: %s: %s\n", + xtcd->pkgver, state_descr, strerror(xtcd->err)); +} diff --git a/bin/xbps-repo/Makefile b/bin/xbps-repo/Makefile index c0716a27..4ff88a38 100644 --- a/bin/xbps-repo/Makefile +++ b/bin/xbps-repo/Makefile @@ -3,7 +3,8 @@ TOPDIR = ../.. BIN = xbps-repo OBJS = main.o index.o repository.o find-files.o -OBJS += ../xbps-bin/fetch.o ../xbps-bin/util.o +OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o +OBJS += ../xbps-bin/trans_cb.o MAN = $(BIN).8 include $(TOPDIR)/prog.mk diff --git a/bin/xbps-repo/defs.h b/bin/xbps-repo/defs.h index 997da115..41ba9ef9 100644 --- a/bin/xbps-repo/defs.h +++ b/bin/xbps-repo/defs.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2010 Juan Romero Pardines. + * Copyright (c) 2009-2011 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,12 +30,16 @@ #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) #endif +#include + /* From index.c */ int repo_genindex(const char *); + /* From repository.c */ int show_pkg_info_from_repolist(const char *); int show_pkg_deps_from_repolist(const char *); int repository_sync(void); + /* From find-files.c */ int repo_find_files_in_packages(const char *); diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 855a8e31..3a9b0ce3 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -135,6 +135,8 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } xhp->debug = debug; + xhp->xbps_transaction_cb = transaction_cb; + xhp->xbps_transaction_err_cb = transaction_err_cb; xhp->xbps_fetch_cb = fetch_file_progress_cb; xhp->xfcd->cookie = &xfer; xhp->rootdir = rootdir; diff --git a/bin/xbps-repo/repository.c b/bin/xbps-repo/repository.c index 7823fdc0..d64fa4a3 100644 --- a/bin/xbps-repo/repository.c +++ b/bin/xbps-repo/repository.c @@ -148,12 +148,8 @@ repo_sync_pkg_index_cb(struct repository_pool_index *rpi, void *arg, bool *done) if (!xbps_check_is_repository_uri_remote(rpi->rpi_uri)) return 0; - printf("Synchronizing package index for `%s' ...\n", rpi->rpi_uri); rv = xbps_repository_sync_pkg_index(rpi->rpi_uri); if (rv == -1) { - xbps_error_printf("xbps-repo: failed to sync `%s': %s%s\n", - rpi->rpi_uri, strerror(errno), xbps_fetch_error_string() ? - xbps_fetch_error_string() : ""); return rv; } else if (rv == 0) { printf("Package index file is already up to date.\n"); diff --git a/bin/xbps-uhelper/Makefile b/bin/xbps-uhelper/Makefile index f338e9ba..b2e46118 100644 --- a/bin/xbps-uhelper/Makefile +++ b/bin/xbps-uhelper/Makefile @@ -2,6 +2,6 @@ TOPDIR = ../.. -include $(TOPDIR)/config.mk BIN = xbps-uhelper -OBJS = main.o ../xbps-bin/fetch.o +OBJS = main.o ../xbps-bin/fetch_cb.o include $(TOPDIR)/prog.mk diff --git a/include/xbps_api.h b/include/xbps_api.h index 0bc2a0c0..a615ea0f 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -55,7 +55,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.2" -#define XBPS_API_VERSION "20110727" +#define XBPS_API_VERSION "20110728" #define XBPS_VERSION "0.10.0" /** @@ -168,6 +168,9 @@ void xbps_warn_printf(const char *, ...); * XBPS_TRANS_STATE_CONFIGURE: a package is being configured. * * XBPS_TRANS_STATE_REGISTER: a package is being registered. + * + * XBPS_TRANS_STATE_REPOSYNC. a remote repository's + * pkg index is being synced. */ typedef enum trans_state { XBPS_TRANS_STATE_UNKNOWN = 0, @@ -180,7 +183,8 @@ typedef enum trans_state { XBPS_TRANS_STATE_UPDATE, XBPS_TRANS_STATE_UNPACK, XBPS_TRANS_STATE_CONFIGURE, - XBPS_TRANS_STATE_REGISTER + XBPS_TRANS_STATE_REGISTER, + XBPS_TRANS_STATE_REPOSYNC } trans_state_t; /** @@ -217,9 +221,9 @@ struct xbps_transaction_cb_data { /** * @var binpkg_repourl * - * Binary package's repository URL (set internally, read-only). + * Repository URL (set internally, read-only). */ - const char *binpkg_repourl; + const char *repourl; /** * @var err * diff --git a/lib/package_configure.c b/lib/package_configure.c index a66da546..bf3620b2 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -114,7 +114,7 @@ xbps_configure_pkg(const char *pkgname, if (xhp->xbps_transaction_cb) { xhp->xtcd->desc = NULL; xhp->xtcd->binpkg_fname = NULL; - xhp->xtcd->binpkg_repourl = NULL; + xhp->xtcd->repourl = NULL; xhp->xtcd->state = XBPS_TRANS_STATE_CONFIGURE; xhp->xtcd->pkgver = pkgver; xhp->xbps_transaction_cb(xhp->xtcd); diff --git a/lib/repository_pool.c b/lib/repository_pool.c index 22bd7727..7c67bd0a 100644 --- a/lib/repository_pool.c +++ b/lib/repository_pool.c @@ -47,11 +47,27 @@ static SIMPLEQ_HEAD(rpool_head, repository_pool) rpool_queue = static bool repolist_initialized; -#define FETCH_ERROR(x) ((x == FETCH_UNAVAIL) || \ - (x == FETCH_NETWORK) || \ - (x == FETCH_ABORT) || \ - (x == FETCH_TIMEOUT) || \ - (x == FETCH_DOWN)) +#define FETCH_ERROR(x) ((x == FETCH_UNAVAIL) || \ + (x == FETCH_NETWORK) || \ + (x == FETCH_ABORT) || \ + (x == FETCH_TIMEOUT) || \ + (x == FETCH_DOWN)) +static int +sync_remote_repo(const char *plist, const char *repourl) +{ + /* if file is there, continue */ + if (access(plist, R_OK) == 0) + return 0; + + /* file not found, fetch it */ + if (xbps_repository_sync_pkg_index(repourl) == -1) { + if (FETCH_ERROR(fetchLastErrCode)) + return -1; + } + + return 0; +} +#undef FETCH_ERROR int HIDDEN xbps_repository_pool_init(void) @@ -107,42 +123,10 @@ xbps_repository_pool_init(void) rv = errno; goto out; } - /* - * For remote repositories, check that its pkg-index.plist - * file is there, otherwise we have to fetch it. - */ - if (xbps_check_is_repository_uri_remote(repouri)) { - if ((access(plist, R_OK) == -1) && errno == ENOENT) { - /* file not found, fetch it */ - xbps_printf("Synchronizing package index for " - "`%s'...\n", repouri); - rv = xbps_repository_sync_pkg_index(repouri); - if (rv == -1) { - const char *fetcherr = - xbps_fetch_error_string(); - - xbps_error_printf("failed to sync " - "repository `%s': %s%s\n", - repouri, - errno ? strerror(errno) : "", - fetchLastErrCode ? fetcherr : ""); - - /* - * Ignore if the file cannot be - * fetched due to network, missing - * file, moved, etc. - */ - if (FETCH_ERROR(fetchLastErrCode)) { - rv = 0; - free(plist); - continue; - } - rv = errno; - free(plist); - goto out; - } - rv = 0; - } + if (sync_remote_repo(plist, repouri) == -1) { + nmissing++; + free(plist); + continue; } ntotal++; /* diff --git a/lib/repository_sync_index.c b/lib/repository_sync_index.c index e4064673..5ab36549 100644 --- a/lib/repository_sync_index.c +++ b/lib/repository_sync_index.c @@ -97,6 +97,10 @@ xbps_repository_sync_pkg_index(const char *uri) tmp_metafile = rpidx = lrepodir = lrepofile = NULL; xhp = xbps_handle_get(); + /* ignore non remote repositories */ + if (!xbps_check_is_repository_uri_remote(uri)) + return 0; + if (uname(&un) == -1) return -1; @@ -160,15 +164,28 @@ xbps_repository_sync_pkg_index(const char *uri) } else fetch_outputdir = metadir; + if (xhp->xbps_transaction_cb) { + xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC; + xhp->xtcd->repourl = uri; + xhp->xbps_transaction_cb(xhp->xtcd); + } /* * Download pkg-index.plist file from repository. */ - rv = xbps_fetch_file(rpidx, fetch_outputdir, true, NULL); - if (rv == -1) { + if (xbps_fetch_file(rpidx, fetch_outputdir, true, NULL) == -1) { sverrno = errno; - xbps_dbg_printf("%s: failed to sync: %s %s\n", - __func__, strerror(errno), xbps_fetch_error_string()); - (void)remove(tmp_metafile); + if (fetchLastErrCode) + rv = fetchLastErrCode; + else + rv = errno; + + if (xhp->xbps_transaction_err_cb) { + xhp->xtcd->state = XBPS_TRANS_STATE_REPOSYNC; + xhp->xtcd->repourl = uri; + xhp->xtcd->err = rv; + xhp->xbps_transaction_cb(xhp->xtcd); + } + rv = -1; errno = sverrno; goto out; } diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 40da331a..977fe16d 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -35,16 +35,16 @@ #include "xbps_api_impl.h" -#define RUN_TRANS_CB(s, d, p, bf, burl) \ -do { \ - if (xhp->xbps_transaction_cb != NULL) { \ - xhp->xtcd->state = s; \ - xhp->xtcd->desc = d; \ - xhp->xtcd->pkgver = p; \ - xhp->xtcd->binpkg_fname = bf; \ - xhp->xtcd->binpkg_repourl = burl; \ - (*xhp->xbps_transaction_cb)(xhp->xtcd); \ - } \ +#define RUN_TRANS_CB(s, d, p, bf, burl) \ +do { \ + if (xhp->xbps_transaction_cb != NULL) { \ + xhp->xtcd->state = s; \ + xhp->xtcd->desc = d; \ + xhp->xtcd->pkgver = p; \ + xhp->xtcd->binpkg_fname = bf; \ + xhp->xtcd->repourl = burl; \ + (*xhp->xbps_transaction_cb)(xhp->xtcd); \ + } \ } while (0) #define RUN_TRANS_ERR_CB(s, p, r) \