diff --git a/bin/xbps-bin/state_cb.c b/bin/xbps-bin/state_cb.c index 225cea86..e4738575 100644 --- a/bin/xbps-bin/state_cb.c +++ b/bin/xbps-bin/state_cb.c @@ -34,35 +34,60 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) { const struct xbps_handle *xhp = xbps_handle_get(); prop_dictionary_t pkgd; - const char *pkgver; + const char *version; (void)cbdata; switch (xscd->state) { + /* notifications */ case XBPS_STATE_TRANS_DOWNLOAD: + printf("[*] Downloading binary packages\n"); + break; case XBPS_STATE_TRANS_VERIFY: + printf("[*] Verifying binary package integrity\n"); + break; case XBPS_STATE_TRANS_RUN: + printf("[*] Running transaction tasks\n"); + break; case XBPS_STATE_TRANS_CONFIGURE: + printf("[*] Configuring unpacked packages\n"); + break; + case XBPS_STATE_REPOSYNC: case XBPS_STATE_DOWNLOAD: case XBPS_STATE_VERIFY: + case XBPS_STATE_CONFIG_FILE: + if (xscd->desc != NULL) + printf("%s\n", xscd->desc); + break; case XBPS_STATE_REMOVE: + printf("Removing `%s-%s' ...\n", xscd->pkgname, xscd->version); + break; case XBPS_STATE_PURGE: + printf("Purging `%s-%s' ...\n", xscd->pkgname, xscd->version); + break; case XBPS_STATE_CONFIGURE: + printf("Configuring `%s-%s' ...\n", xscd->pkgname, + xscd->version); + break; case XBPS_STATE_REGISTER: case XBPS_STATE_UNREGISTER: - case XBPS_STATE_INSTALL: + /* empty */ + break; case XBPS_STATE_UNPACK: - case XBPS_STATE_REPOSYNC: - case XBPS_STATE_CONFIG_FILE: - printf("%s\n", xscd->desc); + printf("Unpacking `%s-%s' ...\n", xscd->pkgname, xscd->version); + break; + case XBPS_STATE_INSTALL: + printf("Installing `%s-%s' ...\n", + xscd->pkgname, xscd->version); break; case XBPS_STATE_UPDATE: pkgd = xbps_find_pkg_dict_installed(xscd->pkgname, false); - prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); + prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); prop_object_release(pkgd); - printf("Updating `%s' to `%s-%s'...\n", pkgver, - xscd->pkgname, xscd->version); + printf("Updating `%s' (`%s' to `%s') ...\n", xscd->pkgname, + version, xscd->version); break; + /* success */ case XBPS_STATE_REMOVE_FILE: case XBPS_STATE_REMOVE_FILE_OBSOLETE: if (xhp->flags & XBPS_FLAG_VERBOSE) @@ -72,6 +97,23 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata) printf("\033[1A\033[K"); } break; + case XBPS_STATE_INSTALL_DONE: + printf("Installed `%s-%s' successfully.\n", + xscd->pkgname, xscd->version); + break; + case XBPS_STATE_UPDATE_DONE: + printf("Updated `%s' to `%s' successfully.\n", + xscd->pkgname, xscd->version); + break; + case XBPS_STATE_REMOVE_DONE: + printf("Removed `%s-%s' successfully.\n", + xscd->pkgname, xscd->version); + break; + case XBPS_STATE_PURGE_DONE: + printf("Purged `%s-%s' successfully.\n", + xscd->pkgname, xscd->version); + break; + /* errors */ case XBPS_STATE_UNPACK_FAIL: case XBPS_STATE_UPDATE_FAIL: case XBPS_STATE_CONFIGURE_FAIL: diff --git a/include/xbps_api.h b/include/xbps_api.h index 524c26fd..504c70c8 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -55,7 +55,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.3" -#define XBPS_API_VERSION "20111124-1" +#define XBPS_API_VERSION "20111125" #define XBPS_VERSION "0.11.0" /** @@ -168,7 +168,7 @@ void xbps_warn_printf(const char *, ...); * * Integer representing the xbps callback returned state. Possible values: * - * XBPS_STATE_UKKNOWN: unknown, state hasn't been prepared or unknown error. + * XBPS_STATE_UKKNOWN: state hasn't been prepared or unknown error. * XBPS_STATE_TRANS_DOWNLOAD: transaction is downloading binary packages. * XBPS_STATE_TRANS_VERIFY: transaction is verifying binary package integrity. * XBPS_STATE_TRANS_RUN: transaction is performing operations: @@ -178,12 +178,16 @@ void xbps_warn_printf(const char *, ...); * XBPS_STATE_DOWNLOAD: a binary package is being downloaded. * XBPS_STATE_VERIFY: a binary package is being verified. * XBPS_STATE_REMOVE: a package is being removed. + * XBPS_STATE_REMOVE_DONE: a package has been removed successfully. * XBPS_STATE_REMOVE_FILE: a package file is being removed. * XBPS_STATE_REMOVE_OBSOLETE: an obsolete package file is being removed. * XBPS_STATE_PURGE: a package is being purged. + * XBPS_STATE_PURGE_DONE: a package has been purged successfully. * XBPS_STATE_REPLACE: a package is being replaced. * XBPS_STATE_INSTALL: a package is being installed. + * XBPS_STATE_INSTALL_DONE: a package has been installed successfully. * XBPS_STATE_UPDATE: a package is being updated. + * XBPS_STATE_UPDATE_DONE: a package has been updated successfully. * XBPS_STATE_UNPACK: a package is being unpacked. * XBPS_STATE_CONFIGURE: a package is being configured. * XBPS_STATE_CONFIG_FILE: a package configuration file is being processed. @@ -218,12 +222,16 @@ typedef enum xbps_state { XBPS_STATE_DOWNLOAD, XBPS_STATE_VERIFY, XBPS_STATE_REMOVE, + XBPS_STATE_REMOVE_DONE, XBPS_STATE_REMOVE_FILE, XBPS_STATE_REMOVE_FILE_OBSOLETE, XBPS_STATE_PURGE, + XBPS_STATE_PURGE_DONE, XBPS_STATE_REPLACE, XBPS_STATE_INSTALL, + XBPS_STATE_INSTALL_DONE, XBPS_STATE_UPDATE, + XBPS_STATE_UPDATE_DONE, XBPS_STATE_UNPACK, XBPS_STATE_CONFIGURE, XBPS_STATE_CONFIG_FILE, diff --git a/lib/package_configure.c b/lib/package_configure.c index e915fa3d..14b10d61 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -119,8 +119,7 @@ xbps_configure_pkg(const char *pkgname, if (pkgver == NULL) return ENOMEM; - xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, lver, - "Configuring package `%s' ...", pkgver); + xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, lver, NULL); buf = xbps_xasprintf(".%s/metadata/%s/INSTALL", XBPS_META_PATH, pkgname); diff --git a/lib/package_purge.c b/lib/package_purge.c index 7c67b170..a0f04af9 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -146,8 +146,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state) } prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); - xbps_set_cb_state(XBPS_STATE_PURGE, 0, pkgname, version, - "Purging package `%s'...", pkgver); + xbps_set_cb_state(XBPS_STATE_PURGE, 0, pkgname, version, NULL); if (check_state) { /* @@ -233,5 +232,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state) if ((rv = xbps_unregister_pkg(pkgname, version)) != 0) return rv; + xbps_set_cb_state(XBPS_STATE_PURGE_DONE, 0, pkgname, version, NULL); + return rv; } diff --git a/lib/package_register.c b/lib/package_register.c index b81aa2c7..84764c9e 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -67,8 +67,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd) provides = prop_dictionary_get(pkgrd, "provides"); reqby = prop_dictionary_get(pkgrd, "requiredby"); - xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, - "Registering package `%s'...", pkgver); + xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, NULL); assert(pkgname != NULL); assert(version != NULL); @@ -170,8 +169,7 @@ xbps_unregister_pkg(const char *pkgname, const char *version) assert(pkgname != NULL); - xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, - "Unregistering package `%s'...", pkgname); + xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL); xhp = xbps_handle_get(); plist = xbps_xasprintf("%s/%s/%s", diff --git a/lib/package_remove.c b/lib/package_remove.c index 57818fa3..86013b99 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -213,8 +213,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) if (pkgver == NULL) return ENOMEM; - xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, - "Removing package `%s'...", pkgver); + xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, NULL); buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname); @@ -342,6 +341,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) rv, pkgname, version, "%s: [remove] failed to set state to config-files: %s", pkgver, strerror(rv)); + } else { + xbps_set_cb_state(XBPS_STATE_REMOVE_DONE, + 0, pkgname, version, NULL); } free(pkgver); diff --git a/lib/package_unpack.c b/lib/package_unpack.c index d0785698..cbb675a0 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -553,9 +553,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc); prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname); - xbps_set_cb_state(XBPS_STATE_UNPACK, - 0, pkgname, version, - "Unpacking package `%s'...", pkgver); + xbps_set_cb_state(XBPS_STATE_UNPACK, 0, pkgname, version, NULL); bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc); if (bpkg == NULL) { diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 19b5d222..fce79807 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -167,7 +167,7 @@ xbps_transaction_commit(prop_dictionary_t transd) struct xbps_handle *xhp; prop_object_t obj; prop_object_iterator_t iter; - const char *pkgname, *version, *pkgver, *filen, *tract; + const char *pkgname, *version, *pkgver, *tract; int rv = 0; bool update; @@ -180,23 +180,20 @@ xbps_transaction_commit(prop_dictionary_t transd) /* * Download binary packages (if they come from a remote repository). */ - xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, - "[*] Downloading binary packages"); + xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL); if ((rv = download_binpkgs(xhp, iter)) != 0) goto out; /* * Check SHA256 hashes for binary packages in transaction. */ - xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, - "[*] Verifying binary package integrity"); + xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL); if ((rv = check_binpkgs_hash(iter)) != 0) goto out; /* * Install, update, configure or remove packages as specified * in the transaction dictionary. */ - xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, - "[*] Running transaction tasks"); + xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL); while ((obj = prop_object_iterator_next(iter)) != NULL) { update = false; @@ -204,7 +201,6 @@ xbps_transaction_commit(prop_dictionary_t transd) prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "version", &version); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); - prop_dictionary_get_cstring_nocopy(obj, "filename", &filen); if (strcmp(tract, "remove") == 0) { /* @@ -239,8 +235,8 @@ xbps_transaction_commit(prop_dictionary_t transd) * Update a package: execute pre-remove * action if found before unpacking. */ - xbps_set_cb_state(XBPS_STATE_UPDATE, - 0, pkgname, version, NULL); + xbps_set_cb_state(XBPS_STATE_UPDATE, 0, + pkgname, version, NULL); rv = xbps_remove_pkg(pkgname, version, true); if (rv != 0) { xbps_set_cb_state( @@ -253,8 +249,8 @@ xbps_transaction_commit(prop_dictionary_t transd) } } else { /* Install a package */ - xbps_set_cb_state(XBPS_STATE_INSTALL, - 0, pkgname, version, NULL); + xbps_set_cb_state(XBPS_STATE_INSTALL, 0, + pkgname, version, NULL); } /* * Unpack binary package. @@ -272,8 +268,7 @@ xbps_transaction_commit(prop_dictionary_t transd) /* * Configure all unpacked packages. */ - xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, - "[*] Configuring unpacked packages"); + xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL); while ((obj = prop_object_iterator_next(iter)) != NULL) { prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); @@ -289,6 +284,17 @@ xbps_transaction_commit(prop_dictionary_t transd) rv = xbps_configure_pkg(pkgname, version, false, update); if (rv != 0) goto out; + /* + * Notify client callback when a package has been + * installed or updated. + */ + if (update) { + xbps_set_cb_state(XBPS_STATE_UPDATE_DONE, 0, + pkgname, version, NULL); + } else { + xbps_set_cb_state(XBPS_STATE_INSTALL_DONE, 0, + pkgname, version, NULL); + } } out: