Added success states for state_cb, move some descriptions to the client cb.

This commit is contained in:
Juan RP 2011-11-25 09:44:49 +01:00
parent 196b26035a
commit f3099fa2c6
8 changed files with 91 additions and 37 deletions

View File

@ -34,35 +34,60 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
{ {
const struct xbps_handle *xhp = xbps_handle_get(); const struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
const char *pkgver; const char *version;
(void)cbdata; (void)cbdata;
switch (xscd->state) { switch (xscd->state) {
/* notifications */
case XBPS_STATE_TRANS_DOWNLOAD: case XBPS_STATE_TRANS_DOWNLOAD:
printf("[*] Downloading binary packages\n");
break;
case XBPS_STATE_TRANS_VERIFY: case XBPS_STATE_TRANS_VERIFY:
printf("[*] Verifying binary package integrity\n");
break;
case XBPS_STATE_TRANS_RUN: case XBPS_STATE_TRANS_RUN:
printf("[*] Running transaction tasks\n");
break;
case XBPS_STATE_TRANS_CONFIGURE: case XBPS_STATE_TRANS_CONFIGURE:
printf("[*] Configuring unpacked packages\n");
break;
case XBPS_STATE_REPOSYNC:
case XBPS_STATE_DOWNLOAD: case XBPS_STATE_DOWNLOAD:
case XBPS_STATE_VERIFY: case XBPS_STATE_VERIFY:
case XBPS_STATE_CONFIG_FILE:
if (xscd->desc != NULL)
printf("%s\n", xscd->desc);
break;
case XBPS_STATE_REMOVE: case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->pkgname, xscd->version);
break;
case XBPS_STATE_PURGE: case XBPS_STATE_PURGE:
printf("Purging `%s-%s' ...\n", xscd->pkgname, xscd->version);
break;
case XBPS_STATE_CONFIGURE: case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->pkgname,
xscd->version);
break;
case XBPS_STATE_REGISTER: case XBPS_STATE_REGISTER:
case XBPS_STATE_UNREGISTER: case XBPS_STATE_UNREGISTER:
case XBPS_STATE_INSTALL: /* empty */
break;
case XBPS_STATE_UNPACK: case XBPS_STATE_UNPACK:
case XBPS_STATE_REPOSYNC: printf("Unpacking `%s-%s' ...\n", xscd->pkgname, xscd->version);
case XBPS_STATE_CONFIG_FILE: break;
printf("%s\n", xscd->desc); case XBPS_STATE_INSTALL:
printf("Installing `%s-%s' ...\n",
xscd->pkgname, xscd->version);
break; break;
case XBPS_STATE_UPDATE: case XBPS_STATE_UPDATE:
pkgd = xbps_find_pkg_dict_installed(xscd->pkgname, false); 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); prop_object_release(pkgd);
printf("Updating `%s' to `%s-%s'...\n", pkgver, printf("Updating `%s' (`%s' to `%s') ...\n", xscd->pkgname,
xscd->pkgname, xscd->version); version, xscd->version);
break; break;
/* success */
case XBPS_STATE_REMOVE_FILE: case XBPS_STATE_REMOVE_FILE:
case XBPS_STATE_REMOVE_FILE_OBSOLETE: case XBPS_STATE_REMOVE_FILE_OBSOLETE:
if (xhp->flags & XBPS_FLAG_VERBOSE) 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"); printf("\033[1A\033[K");
} }
break; 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_UNPACK_FAIL:
case XBPS_STATE_UPDATE_FAIL: case XBPS_STATE_UPDATE_FAIL:
case XBPS_STATE_CONFIGURE_FAIL: case XBPS_STATE_CONFIGURE_FAIL:

View File

@ -55,7 +55,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.3" #define XBPS_PKGINDEX_VERSION "1.3"
#define XBPS_API_VERSION "20111124-1" #define XBPS_API_VERSION "20111125"
#define XBPS_VERSION "0.11.0" #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: * 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_DOWNLOAD: transaction is downloading binary packages.
* XBPS_STATE_TRANS_VERIFY: transaction is verifying binary package integrity. * XBPS_STATE_TRANS_VERIFY: transaction is verifying binary package integrity.
* XBPS_STATE_TRANS_RUN: transaction is performing operations: * 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_DOWNLOAD: a binary package is being downloaded.
* XBPS_STATE_VERIFY: a binary package is being verified. * XBPS_STATE_VERIFY: a binary package is being verified.
* XBPS_STATE_REMOVE: a package is being removed. * 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_FILE: a package file is being removed.
* XBPS_STATE_REMOVE_OBSOLETE: an obsolete 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: 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_REPLACE: a package is being replaced.
* XBPS_STATE_INSTALL: a package is being installed. * 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: 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_UNPACK: a package is being unpacked.
* XBPS_STATE_CONFIGURE: a package is being configured. * XBPS_STATE_CONFIGURE: a package is being configured.
* XBPS_STATE_CONFIG_FILE: a package configuration file is being processed. * XBPS_STATE_CONFIG_FILE: a package configuration file is being processed.
@ -218,12 +222,16 @@ typedef enum xbps_state {
XBPS_STATE_DOWNLOAD, XBPS_STATE_DOWNLOAD,
XBPS_STATE_VERIFY, XBPS_STATE_VERIFY,
XBPS_STATE_REMOVE, XBPS_STATE_REMOVE,
XBPS_STATE_REMOVE_DONE,
XBPS_STATE_REMOVE_FILE, XBPS_STATE_REMOVE_FILE,
XBPS_STATE_REMOVE_FILE_OBSOLETE, XBPS_STATE_REMOVE_FILE_OBSOLETE,
XBPS_STATE_PURGE, XBPS_STATE_PURGE,
XBPS_STATE_PURGE_DONE,
XBPS_STATE_REPLACE, XBPS_STATE_REPLACE,
XBPS_STATE_INSTALL, XBPS_STATE_INSTALL,
XBPS_STATE_INSTALL_DONE,
XBPS_STATE_UPDATE, XBPS_STATE_UPDATE,
XBPS_STATE_UPDATE_DONE,
XBPS_STATE_UNPACK, XBPS_STATE_UNPACK,
XBPS_STATE_CONFIGURE, XBPS_STATE_CONFIGURE,
XBPS_STATE_CONFIG_FILE, XBPS_STATE_CONFIG_FILE,

View File

@ -119,8 +119,7 @@ xbps_configure_pkg(const char *pkgname,
if (pkgver == NULL) if (pkgver == NULL)
return ENOMEM; return ENOMEM;
xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, lver, xbps_set_cb_state(XBPS_STATE_CONFIGURE, 0, pkgname, lver, NULL);
"Configuring package `%s' ...", pkgver);
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL", buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);

View File

@ -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, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
xbps_set_cb_state(XBPS_STATE_PURGE, 0, pkgname, version, xbps_set_cb_state(XBPS_STATE_PURGE, 0, pkgname, version, NULL);
"Purging package `%s'...", pkgver);
if (check_state) { if (check_state) {
/* /*
@ -233,5 +232,7 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
if ((rv = xbps_unregister_pkg(pkgname, version)) != 0) if ((rv = xbps_unregister_pkg(pkgname, version)) != 0)
return rv; return rv;
xbps_set_cb_state(XBPS_STATE_PURGE_DONE, 0, pkgname, version, NULL);
return rv; return rv;
} }

View File

@ -67,8 +67,7 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
provides = prop_dictionary_get(pkgrd, "provides"); provides = prop_dictionary_get(pkgrd, "provides");
reqby = prop_dictionary_get(pkgrd, "requiredby"); reqby = prop_dictionary_get(pkgrd, "requiredby");
xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, xbps_set_cb_state(XBPS_STATE_REGISTER, 0, pkgname, version, NULL);
"Registering package `%s'...", pkgver);
assert(pkgname != NULL); assert(pkgname != NULL);
assert(version != NULL); assert(version != NULL);
@ -170,8 +169,7 @@ xbps_unregister_pkg(const char *pkgname, const char *version)
assert(pkgname != NULL); assert(pkgname != NULL);
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
"Unregistering package `%s'...", pkgname);
xhp = xbps_handle_get(); xhp = xbps_handle_get();
plist = xbps_xasprintf("%s/%s/%s", plist = xbps_xasprintf("%s/%s/%s",

View File

@ -213,8 +213,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
if (pkgver == NULL) if (pkgver == NULL)
return ENOMEM; return ENOMEM;
xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, xbps_set_cb_state(XBPS_STATE_REMOVE, 0, pkgname, version, NULL);
"Removing package `%s'...", pkgver);
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", buf = xbps_xasprintf(".%s/metadata/%s/REMOVE",
XBPS_META_PATH, pkgname); XBPS_META_PATH, pkgname);
@ -342,6 +341,9 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
rv, pkgname, version, rv, pkgname, version,
"%s: [remove] failed to set state to config-files: %s", "%s: [remove] failed to set state to config-files: %s",
pkgver, strerror(rv)); pkgver, strerror(rv));
} else {
xbps_set_cb_state(XBPS_STATE_REMOVE_DONE,
0, pkgname, version, NULL);
} }
free(pkgver); free(pkgver);

View File

@ -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, "repository", &repoloc);
prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname); prop_dictionary_get_cstring_nocopy(pkg_repod, "filename", &fname);
xbps_set_cb_state(XBPS_STATE_UNPACK, xbps_set_cb_state(XBPS_STATE_UNPACK, 0, pkgname, version, NULL);
0, pkgname, version,
"Unpacking package `%s'...", pkgver);
bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc); bpkg = xbps_path_from_repository_uri(pkg_repod, repoloc);
if (bpkg == NULL) { if (bpkg == NULL) {

View File

@ -167,7 +167,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
struct xbps_handle *xhp; struct xbps_handle *xhp;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
const char *pkgname, *version, *pkgver, *filen, *tract; const char *pkgname, *version, *pkgver, *tract;
int rv = 0; int rv = 0;
bool update; bool update;
@ -180,23 +180,20 @@ xbps_transaction_commit(prop_dictionary_t transd)
/* /*
* Download binary packages (if they come from a remote repository). * Download binary packages (if they come from a remote repository).
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, xbps_set_cb_state(XBPS_STATE_TRANS_DOWNLOAD, 0, NULL, NULL, NULL);
"[*] Downloading binary packages");
if ((rv = download_binpkgs(xhp, iter)) != 0) if ((rv = download_binpkgs(xhp, iter)) != 0)
goto out; goto out;
/* /*
* Check SHA256 hashes for binary packages in transaction. * Check SHA256 hashes for binary packages in transaction.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, xbps_set_cb_state(XBPS_STATE_TRANS_VERIFY, 0, NULL, NULL, NULL);
"[*] Verifying binary package integrity");
if ((rv = check_binpkgs_hash(iter)) != 0) if ((rv = check_binpkgs_hash(iter)) != 0)
goto out; goto out;
/* /*
* Install, update, configure or remove packages as specified * Install, update, configure or remove packages as specified
* in the transaction dictionary. * in the transaction dictionary.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, xbps_set_cb_state(XBPS_STATE_TRANS_RUN, 0, NULL, NULL, NULL);
"[*] Running transaction tasks");
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
update = false; 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, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version); prop_dictionary_get_cstring_nocopy(obj, "version", &version);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
prop_dictionary_get_cstring_nocopy(obj, "filename", &filen);
if (strcmp(tract, "remove") == 0) { if (strcmp(tract, "remove") == 0) {
/* /*
@ -239,8 +235,8 @@ xbps_transaction_commit(prop_dictionary_t transd)
* Update a package: execute pre-remove * Update a package: execute pre-remove
* action if found before unpacking. * action if found before unpacking.
*/ */
xbps_set_cb_state(XBPS_STATE_UPDATE, xbps_set_cb_state(XBPS_STATE_UPDATE, 0,
0, pkgname, version, NULL); pkgname, version, NULL);
rv = xbps_remove_pkg(pkgname, version, true); rv = xbps_remove_pkg(pkgname, version, true);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state( xbps_set_cb_state(
@ -253,8 +249,8 @@ xbps_transaction_commit(prop_dictionary_t transd)
} }
} else { } else {
/* Install a package */ /* Install a package */
xbps_set_cb_state(XBPS_STATE_INSTALL, xbps_set_cb_state(XBPS_STATE_INSTALL, 0,
0, pkgname, version, NULL); pkgname, version, NULL);
} }
/* /*
* Unpack binary package. * Unpack binary package.
@ -272,8 +268,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
/* /*
* Configure all unpacked packages. * Configure all unpacked packages.
*/ */
xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, xbps_set_cb_state(XBPS_STATE_TRANS_CONFIGURE, 0, NULL, NULL, NULL);
"[*] Configuring unpacked packages");
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "transaction", &tract); 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); rv = xbps_configure_pkg(pkgname, version, false, update);
if (rv != 0) if (rv != 0)
goto out; 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: out: