Simplify xbps_transaction_prepare()/commit() and related API changes.

- xbps_handle::transd -> new member with transaction dictionary.
- xbps_transaction_prepare: returns an int.
- xbps_transaction_commit: doesn't need any arg now.
- xbps_repository_pool_sync: doesn't need any arg now.
- xbps_pkgdb_update: removed xbps_handle * arg.
- xbps_transaction_missingdeps_get: removed, missing_deps array is in
  xbps_handle::transd("missing_deps") array object.
This commit is contained in:
Juan RP 2012-01-22 10:00:46 +01:00
parent 38db570c19
commit a166d6a2a3
14 changed files with 183 additions and 235 deletions

View File

@ -63,14 +63,13 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done)
int int
check_pkg_integrity_all(void) check_pkg_integrity_all(void)
{ {
struct xbps_handle *xhp = xbps_handle_get();
struct checkpkg cpkg; struct checkpkg cpkg;
int rv; int rv;
memset(&cpkg, 0, sizeof(cpkg)); memset(&cpkg, 0, sizeof(cpkg));
(void)xbps_pkgdb_foreach_cb(cb_pkg_integrity, &cpkg); (void)xbps_pkgdb_foreach_cb(cb_pkg_integrity, &cpkg);
if (cpkg.flush) { if (cpkg.flush) {
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) { if ((rv = xbps_pkgdb_update(true)) != 0) {
xbps_error_printf("failed to write pkgdb: %s\n", xbps_error_printf("failed to write pkgdb: %s\n",
strerror(rv)); strerror(rv));
return rv; return rv;

View File

@ -368,30 +368,32 @@ remove_pkg(const char *pkgname, bool recursive)
int int
exec_transaction(bool yes, bool show_download_urls) exec_transaction(bool yes, bool show_download_urls)
{ {
prop_array_t mdeps;
struct transaction *trans; struct transaction *trans;
prop_array_t array; struct xbps_handle *xhp = xbps_handle_get();
int rv = 0; int rv = 0;
trans = calloc(1, sizeof(*trans)); trans = calloc(1, sizeof(*trans));
if (trans == NULL) if (trans == NULL)
return ENOMEM; return ENOMEM;
if ((trans->d = xbps_transaction_prepare()) == NULL) { if ((rv = xbps_transaction_prepare()) != 0) {
if (errno == ENODEV) { if (rv == ENODEV) {
mdeps =
prop_dictionary_get(xhp->transd, "missing_deps");
/* missing packages */ /* missing packages */
array = xbps_transaction_missingdeps_get(); show_missing_deps(mdeps);
show_missing_deps(array);
rv = errno;
goto out; goto out;
} }
xbps_dbg_printf("Empty transaction dictionary: %s\n", xbps_dbg_printf("Empty transaction dictionary: %s\n",
strerror(errno)); strerror(errno));
return errno; return rv;
} }
xbps_dbg_printf("Dictionary before transaction happens:\n"); xbps_dbg_printf("Dictionary before transaction happens:\n");
xbps_dbg_printf_append("%s", prop_dictionary_externalize(trans->d)); xbps_dbg_printf_append("%s", prop_dictionary_externalize(xhp->transd));
trans->iter = xbps_array_iter_from_dict(trans->d, "packages"); trans->d = xhp->transd;
trans->iter = xbps_array_iter_from_dict(xhp->transd, "packages");
if (trans->iter == NULL) { if (trans->iter == NULL) {
rv = errno; rv = errno;
xbps_error_printf("xbps-bin: error allocating array mem! (%s)\n", xbps_error_printf("xbps-bin: error allocating array mem! (%s)\n",
@ -420,8 +422,7 @@ exec_transaction(bool yes, bool show_download_urls)
/* /*
* It's time to run the transaction! * It's time to run the transaction!
*/ */
rv = xbps_transaction_commit(trans->d); if ((rv = xbps_transaction_commit()) == 0) {
if (rv == 0) {
printf("\nxbps-bin: %u installed, %u updated, " printf("\nxbps-bin: %u installed, %u updated, "
"%u configured, %u removed.\n", trans->inst_pkgcnt, "%u configured, %u removed.\n", trans->inst_pkgcnt,
trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt, trans->up_pkgcnt, trans->cf_pkgcnt + trans->inst_pkgcnt,
@ -430,8 +431,6 @@ exec_transaction(bool yes, bool show_download_urls)
out: out:
if (trans->iter) if (trans->iter)
prop_object_iterator_release(trans->iter); prop_object_iterator_release(trans->iter);
if (trans->d)
prop_object_release(trans->d);
if (trans) if (trans)
free(trans); free(trans);

View File

@ -241,7 +241,7 @@ main(int argc, char **argv)
if (argc != 1) if (argc != 1)
usage(); usage();
rv = xbps_repository_pool_sync(&xh); rv = xbps_repository_pool_sync();
if (rv == ENOTSUP) { if (rv == ENOTSUP) {
xbps_error_printf("xbps-repo: no repositories " xbps_error_printf("xbps-repo: no repositories "
"currently registered!\n"); "currently registered!\n");

View File

@ -389,7 +389,7 @@ main(int argc, char **argv)
} }
xh.pkgdb = prop_array_copy(array); xh.pkgdb = prop_array_copy(array);
prop_object_release(dict); prop_object_release(dict);
rv = xbps_pkgdb_update(&xh, true); rv = xbps_pkgdb_update(true);
if (rv == 0) { if (rv == 0) {
printf("Migrated regpkgdb to pkgdb " printf("Migrated regpkgdb to pkgdb "
"successfully.\n"); "successfully.\n");

View File

@ -56,7 +56,7 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.4" #define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120120-1" #define XBPS_API_VERSION "20120122"
#define XBPS_VERSION "0.12" #define XBPS_VERSION "0.12"
/** /**
@ -440,6 +440,13 @@ struct xbps_handle {
* stored in XBPS_META_PATH/XBPS_PKGDB. * stored in XBPS_META_PATH/XBPS_PKGDB.
*/ */
prop_array_t pkgdb; prop_array_t pkgdb;
/**
* @var transd;
*
* Proplib dictionary with transaction details, required by
* xbps_transaction_commit().
*/
prop_dictionary_t transd;
/** /**
* Pointer to the supplifed function callback to be used * Pointer to the supplifed function callback to be used
* in the XBPS possible states. * in the XBPS possible states.
@ -735,14 +742,12 @@ bool xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
* Updates the master package database (pkgdb) plist with new contents from * Updates the master package database (pkgdb) plist with new contents from
* disk to the cached copy in memory. * disk to the cached copy in memory.
* *
* @param[in] xhp Pointer to our xbps_handle struct, as returned by
* \a xbps_handle_get().
* @param[in] flush If true the pkgdb plist contents in memory will * @param[in] flush If true the pkgdb plist contents in memory will
* be flushed atomically to storage. * be flushed atomically to storage.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_pkgdb_update(struct xbps_handle *xhp, bool flush); int xbps_pkgdb_update(bool flush);
/*@}*/ /*@}*/
@ -1203,8 +1208,9 @@ bool xbps_remove_pkgname_from_array(prop_array_t array, const char *name);
* @param[in] dict Proplib dictionary to be added in \a array. * @param[in] dict Proplib dictionary to be added in \a array.
* @param[in] pkgname Package name to be matched. * @param[in] pkgname Package name to be matched.
* *
* @return 0 on success, EINVAL if dictionary couldn't be set in * @retval 0 success.
* array or ENOENT if no match. * @retval EINVAL Dictionary couldn't be set in array.
* @retval ENOENT No match.
*/ */
int xbps_array_replace_dict_by_name(prop_array_t array, int xbps_array_replace_dict_by_name(prop_array_t array,
prop_dictionary_t dict, prop_dictionary_t dict,
@ -1219,8 +1225,9 @@ int xbps_array_replace_dict_by_name(prop_array_t array,
* @param[in] dict Proplib dictionary to be added in \a array. * @param[in] dict Proplib dictionary to be added in \a array.
* @param[in] pattern Package pattern to be matched, i.e `foo>=0'. * @param[in] pattern Package pattern to be matched, i.e `foo>=0'.
* *
* @return 0 on success, EINVAL id dictionary couldn't be set in the array * @retval 0 success.
* or ENOENT if no match. * @retval EINVAL Dictionary couldn't be set in array.
* @retval ENOENT No match.
*/ */
int xbps_array_replace_dict_by_pattern(prop_array_t array, int xbps_array_replace_dict_by_pattern(prop_array_t array,
prop_dictionary_t dict, prop_dictionary_t dict,
@ -1336,9 +1343,11 @@ int xbps_transaction_update_packages(void);
* @param[in] recursive If true, all packages that are currently depending * @param[in] recursive If true, all packages that are currently depending
* on the package to be removed, and if they are orphans, will be added. * on the package to be removed, and if they are orphans, will be added.
* *
* @return 0 on success, ENOENT if pkg is not installed, EEXIST if package * @retval 0 success.
* has reverse dependencies, EINVAL or ENXIO if a problem ocurred in the * @retval ENOENT Package is not installed.
* process. * @retval EEXIST Package has reverse dependencies.
* @retval EINVAL
* @retval ENXIO A problem ocurred in the process.
*/ */
int xbps_transaction_remove_pkg(const char *pkgname, int xbps_transaction_remove_pkg(const char *pkgname,
bool recursive); bool recursive);
@ -1347,8 +1356,10 @@ int xbps_transaction_remove_pkg(const char *pkgname,
* Finds all package orphans currently installed and adds them into * Finds all package orphans currently installed and adds them into
* the transaction dictionary. * the transaction dictionary.
* *
* @return 0 on succcess, ENOENT if no package orphans were found, ENXIO * @retval 0 success.
* or EINVAL if a problem ocurred in the process. * @retval ENOENT No package orphans were found.
* @retval ENXIO
* @retval EINVAL A problem ocurred in the process.
*/ */
int xbps_transaction_autoremove_pkgs(void); int xbps_transaction_autoremove_pkgs(void);
@ -1357,36 +1368,25 @@ int xbps_transaction_autoremove_pkgs(void);
* Before returning the package list is sorted in the correct order * Before returning the package list is sorted in the correct order
* and total installed/download size for the transaction is computed. * and total installed/download size for the transaction is computed.
* *
* @return The proplib transaction dictionary on success, otherwise NULL * @retval 0 success.
* and errno is set appropiately. ENXIO if the transaction * @retval ENXIO if transaction dictionary and missing deps array were not created,
* dictionary and the missing deps array were not created. ENODEV if * due to xbps_transaction_install_pkg() or xbps_transaction_update_pkg() not
* there are missing dependencies or any other if there was an error * previously called.
* while sorting packages or computing the transaction size. * @retval ENODEV if there are missing dependencies in transaction ("missing_deps"
* * array of strings object in xhp->transd dictionary).
* @note * @retval EINVAL There was an error sorting packages or computing the transaction
* - This function will set errno to ENXIO if xbps_transaction_install_pkg() * sizes.
* or xbps_transaction_update_pkg() functions were not called previously.
*/ */
prop_dictionary_t xbps_transaction_prepare(void); int xbps_transaction_prepare(void);
/** /**
* Commit a transaction. The transaction dictionary contains all steps * Commit a transaction. The transaction dictionary in xhp->transd contains all
* to be executed in the transaction, as returned by xbps_transaction_prepare(). * steps to be executed in the transaction, as prepared by
* * xbps_transaction_prepare().
* @param[in] transd The transaction dictionary.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_transaction_commit(prop_dictionary_t transd); int xbps_transaction_commit(void);
/**
* Returns the missing deps array if xbps_transaction_install_pkg()
* or xbps_transaction_update_pkg() failed to find required packages
* in registered repositories.
*
* @return The proplib array, NULL if it couldn't be created.
*/
prop_array_t xbps_transaction_missingdeps_get(void);
/*@}*/ /*@}*/
@ -1445,13 +1445,10 @@ struct repository_pool_index {
* Synchronizes the package index file for all remote repositories * Synchronizes the package index file for all remote repositories
* as specified in the configuration file, repositories.plist. * as specified in the configuration file, repositories.plist.
* *
* @param[in] xhp Pointer to a struct xbps_handle, as returned by
* xbps_handle_get().
*
* @return 0 on success, ENOTSUP if no repositories were found in * @return 0 on success, ENOTSUP if no repositories were found in
* the configuration file. * the configuration file.
*/ */
int xbps_repository_pool_sync(const struct xbps_handle *xhp); int xbps_repository_pool_sync(void);
/** /**
* Iterates over the repository pool and executes the \a fn function * Iterates over the repository pool and executes the \a fn function

View File

@ -120,8 +120,7 @@ int HIDDEN xbps_remove_obsoletes(const char *,
* @private * @private
* From lib/repository_finddeps.c * From lib/repository_finddeps.c
*/ */
int HIDDEN xbps_repository_find_pkg_deps(prop_dictionary_t, int HIDDEN xbps_repository_find_pkg_deps(struct xbps_handle *,
prop_array_t,
prop_dictionary_t); prop_dictionary_t);
/** /**
@ -135,13 +134,13 @@ int HIDDEN xbps_requiredby_pkg_remove(const char *);
* @private * @private
* From lib/transaction_sortdeps.c * From lib/transaction_sortdeps.c
*/ */
int HIDDEN xbps_sort_pkg_deps(void); int HIDDEN xbps_transaction_sort_pkg_deps(struct xbps_handle *);
/** /**
* @private * @private
* From lib/transaction_dictionary.c * From lib/transaction_dictionary.c
*/ */
prop_dictionary_t HIDDEN xbps_transaction_dictionary_get(void); int HIDDEN xbps_transaction_init(struct xbps_handle *);
/** /**
* @private * @private

View File

@ -62,12 +62,11 @@ configure_pkgs_cb(prop_object_t obj, void *arg, bool *done)
int int
xbps_configure_packages(bool flush) xbps_configure_packages(bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
int rv; int rv;
rv = xbps_pkgdb_foreach_cb(configure_pkgs_cb, NULL); rv = xbps_pkgdb_foreach_cb(configure_pkgs_cb, NULL);
if (rv == 0 && flush) if (rv == 0 && flush)
rv = xbps_pkgdb_update(xhp, true); rv = xbps_pkgdb_update(true);
return rv; return rv;
} }
@ -169,7 +168,7 @@ xbps_configure_pkg(const char *pkgname,
} }
free(pkgver); free(pkgver);
if (flush) if (flush)
rv = xbps_pkgdb_update(xhp, true); rv = xbps_pkgdb_update(true);
return rv; return rv;
} }

View File

@ -64,7 +64,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
if (xhp->pkgdb != NULL) if (xhp->pkgdb != NULL)
return 0; return 0;
if ((rv = xbps_pkgdb_update(xhp, false)) != 0) { if ((rv = xbps_pkgdb_update(false)) != 0) {
if (rv != ENOENT) if (rv != ENOENT)
xbps_dbg_printf("[pkgdb] cannot internalize " xbps_dbg_printf("[pkgdb] cannot internalize "
"pkgdb array: %s\n", strerror(rv)); "pkgdb array: %s\n", strerror(rv));
@ -77,8 +77,9 @@ xbps_pkgdb_init(struct xbps_handle *xhp)
} }
int int
xbps_pkgdb_update(struct xbps_handle *xhp, bool flush) xbps_pkgdb_update(bool flush)
{ {
struct xbps_handle *xhp = xbps_handle_get();
char *plist, *metadir; char *plist, *metadir;
int rv = 0; int rv = 0;
@ -213,7 +214,7 @@ xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush)
if (!flush || !rv) if (!flush || !rv)
return rv; return rv;
if ((xbps_pkgdb_update(xhp, true)) != 0) if ((xbps_pkgdb_update(true)) != 0)
return false; return false;
return true; return true;
@ -239,7 +240,7 @@ xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd,
if (!flush) if (!flush)
return rv != 0 ? false : true; return rv != 0 ? false : true;
if ((xbps_pkgdb_update(xhp, true)) != 0) if ((xbps_pkgdb_update(true)) != 0)
return false; return false;
return true; return true;

View File

@ -172,25 +172,25 @@ out:
#define MAX_DEPTH 512 #define MAX_DEPTH 512
static int static int
find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
prop_array_t mrdeps, /* missing rundeps array */ prop_array_t trans_mdeps, /* transaction missing deps array */
prop_array_t pkg_rdeps_array, /* current pkg rundeps array */ prop_array_t pkg_rdeps_array, /* current pkg rundeps array */
const char *curpkg, /* current pkgver */ const char *curpkg, /* current pkgver */
size_t *depth) /* max recursion depth */ size_t *depth) /* max recursion depth */
{ {
struct xbps_handle *xhp = xbps_handle_get();
prop_dictionary_t curpkgd, tmpd; prop_dictionary_t curpkgd, tmpd;
prop_array_t curpkgrdeps; prop_array_t curpkgrdeps;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
pkg_state_t state; pkg_state_t state;
const struct xbps_handle *xhp = xbps_handle_get();
size_t x; size_t x;
const char *reqpkg, *pkgver_q, *reason = NULL; const char *reqpkg, *pkgver_q, *reason = NULL;
char *pkgname; char *pkgname;
int rv = 0; int rv = 0;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(mrdeps) == PROP_TYPE_ARRAY); assert(prop_object_type(trans_mdeps) == PROP_TYPE_ARRAY);
assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY); assert(prop_object_type(pkg_rdeps_array) == PROP_TYPE_ARRAY);
if (*depth >= MAX_DEPTH) if (*depth >= MAX_DEPTH)
@ -335,15 +335,15 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* the array of unsorted dependencies, and check if the pattern * the array of unsorted dependencies, and check if the pattern
* was matched. * was matched.
*/ */
curpkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern(transd, curpkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern(
"unsorted_deps", reqpkg); transd, "unsorted_deps", reqpkg);
if (curpkgd == NULL) { if (curpkgd == NULL) {
/* /*
* Look for a real package matching pattern * Look for a real package matching pattern
* if no match. * if no match.
*/ */
curpkgd = xbps_find_pkg_in_dict_by_pattern(transd, curpkgd = xbps_find_pkg_in_dict_by_pattern(
"unsorted_deps", reqpkg); transd, "unsorted_deps", reqpkg);
} }
if (curpkgd != NULL) { if (curpkgd != NULL) {
prop_dictionary_get_cstring_nocopy(curpkgd, prop_dictionary_get_cstring_nocopy(curpkgd,
@ -364,7 +364,8 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
*/ */
curpkgd = xbps_repository_pool_find_virtualpkg(reqpkg, true); curpkgd = xbps_repository_pool_find_virtualpkg(reqpkg, true);
if (curpkgd == NULL) { if (curpkgd == NULL) {
curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, false); curpkgd = xbps_repository_pool_find_pkg(reqpkg, true,
false);
if (curpkgd == NULL) { if (curpkgd == NULL) {
/* pkg not found, there was some error */ /* pkg not found, there was some error */
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
@ -375,19 +376,21 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
break; break;
} }
rv = add_missing_reqdep(mrdeps, reqpkg); rv = add_missing_reqdep(trans_mdeps, reqpkg);
if (rv != 0 && rv != EEXIST) { if (rv != 0 && rv != EEXIST) {
xbps_dbg_printf_append("`%s': " xbps_dbg_printf_append("`%s': "
"add_missing_reqdep failed %s\n", reqpkg); "add_missing_reqdep failed %s\n",
reqpkg);
break; break;
} else if (rv == EEXIST) { } else if (rv == EEXIST) {
xbps_dbg_printf_append("`%s' missing dep " xbps_dbg_printf_append("`%s' missing "
"already added.\n", reqpkg); "dep already added.\n", reqpkg);
rv = 0; rv = 0;
continue; continue;
} else { } else {
xbps_dbg_printf_append("`%s' added " xbps_dbg_printf_append("`%s' added "
"into the missing deps array.\n", reqpkg); "into the missing deps array.\n",
reqpkg);
continue; continue;
} }
} }
@ -428,7 +431,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
* Recursively find rundeps for current pkg dictionary. * Recursively find rundeps for current pkg dictionary.
*/ */
(*depth)++; (*depth)++;
rv = find_repo_deps(transd, mrdeps, curpkgrdeps, rv = find_repo_deps(transd, trans_mdeps, curpkgrdeps,
pkgver_q, depth); pkgver_q, depth);
if (rv != 0) { if (rv != 0) {
xbps_dbg_printf("Error checking %s for rundeps: %s\n", xbps_dbg_printf("Error checking %s for rundeps: %s\n",
@ -443,17 +446,15 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
} }
int HIDDEN int HIDDEN
xbps_repository_find_pkg_deps(prop_dictionary_t transd, xbps_repository_find_pkg_deps(struct xbps_handle *xhp,
prop_array_t mdeps,
prop_dictionary_t repo_pkgd) prop_dictionary_t repo_pkgd)
{ {
prop_array_t pkg_rdeps; prop_array_t mdeps, pkg_rdeps;
const char *pkgver; const char *pkgver;
size_t depth = 0; size_t depth = 0;
int rv = 0; int rv = 0;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY);
assert(prop_object_type(mdeps) == PROP_TYPE_ARRAY);
assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY);
pkg_rdeps = prop_dictionary_get(repo_pkgd, "run_depends"); pkg_rdeps = prop_dictionary_get(repo_pkgd, "run_depends");
@ -462,11 +463,12 @@ xbps_repository_find_pkg_deps(prop_dictionary_t transd,
prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(repo_pkgd, "pkgver", &pkgver);
xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver); xbps_dbg_printf("Finding required dependencies for '%s':\n", pkgver);
mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
/* /*
* This will find direct and indirect deps, if any of them is not * This will find direct and indirect deps, if any of them is not
* there it will be added into the missing_deps array. * there it will be added into the missing_deps array.
*/ */
if ((rv = find_repo_deps(transd, mdeps, pkg_rdeps, if ((rv = find_repo_deps(xhp->transd, mdeps, pkg_rdeps,
pkgver, &depth)) != 0) { pkgver, &depth)) != 0) {
xbps_dbg_printf("Error '%s' while checking rundeps!\n", xbps_dbg_printf("Error '%s' while checking rundeps!\n",
strerror(rv)); strerror(rv));

View File

@ -181,8 +181,9 @@ xbps_repository_pool_release(struct xbps_handle *xhp)
} }
int int
xbps_repository_pool_sync(const struct xbps_handle *xhp) xbps_repository_pool_sync(void)
{ {
const struct xbps_handle *xhp = xbps_handle_get();
const char *repouri; const char *repouri;
size_t i; size_t i;
int rv; int rv;

View File

@ -180,9 +180,9 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter)
} }
int int
xbps_transaction_commit(prop_dictionary_t transd) xbps_transaction_commit(void)
{ {
struct xbps_handle *xhp; struct xbps_handle *xhp = xbps_handle_get();
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
size_t i; size_t i;
@ -190,11 +190,10 @@ xbps_transaction_commit(prop_dictionary_t transd)
int rv = 0; int rv = 0;
bool update, install; bool update, install;
assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY);
update = install = false; update = install = false;
xhp = xbps_handle_get(); iter = xbps_array_iter_from_dict(xhp->transd, "packages");
iter = xbps_array_iter_from_dict(transd, "packages");
if (iter == NULL) if (iter == NULL)
return EINVAL; return EINVAL;
/* /*
@ -219,7 +218,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if ((xhp->transaction_frequency_flush > 0) && if ((xhp->transaction_frequency_flush > 0) &&
(++i >= xhp->transaction_frequency_flush)) { (++i >= xhp->transaction_frequency_flush)) {
rv = xbps_pkgdb_update(xhp, true); rv = xbps_pkgdb_update(true);
if (rv != 0 && rv != ENOENT) if (rv != 0 && rv != ENOENT)
goto out; goto out;
@ -295,7 +294,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
prop_object_iterator_reset(iter); prop_object_iterator_reset(iter);
/* force a flush now packages were removed/unpacked */ /* force a flush now packages were removed/unpacked */
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) if ((rv = xbps_pkgdb_update(true)) != 0)
goto out; goto out;
/* if there are no packages to install or update we are done */ /* if there are no packages to install or update we are done */
@ -310,7 +309,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
if (xhp->transaction_frequency_flush > 0 && if (xhp->transaction_frequency_flush > 0 &&
++i >= xhp->transaction_frequency_flush) { ++i >= xhp->transaction_frequency_flush) {
if ((rv = xbps_pkgdb_update(xhp, true)) != 0) if ((rv = xbps_pkgdb_update(true)) != 0)
goto out; goto out;
i = 0; i = 0;
@ -344,7 +343,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
} }
/* Force a flush now that packages are configured */ /* Force a flush now that packages are configured */
rv = xbps_pkgdb_update(xhp, true); rv = xbps_pkgdb_update(true);
out: out:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2009-2011 Juan Romero Pardines. * Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -52,55 +52,8 @@
* data type is specified on its edge, i.e string, array, integer, dictionary. * data type is specified on its edge, i.e string, array, integer, dictionary.
*/ */
static prop_dictionary_t transd;
static prop_array_t trans_mdeps;
static bool transd_initialized;
static bool trans_mdeps_initialized;
static int static int
create_transaction_dictionary(void) compute_transaction_stats(prop_dictionary_t transd)
{
prop_array_t unsorted;
if (transd_initialized)
return 0;
transd = prop_dictionary_create();
if (transd == NULL)
return ENOMEM;
unsorted = prop_array_create();
if (unsorted == NULL) {
prop_object_release(transd);
return ENOMEM;
}
if (!xbps_add_obj_to_dict(transd, unsorted, "unsorted_deps")) {
prop_object_release(unsorted);
prop_object_release(transd);
return EINVAL;
}
transd_initialized = true;
return 0;
}
static int
create_transaction_missingdeps(void)
{
if (trans_mdeps_initialized)
return 0;
trans_mdeps = prop_array_create();
if (trans_mdeps == NULL)
return ENOMEM;
trans_mdeps_initialized = true;
return 0;
}
static int
compute_transaction_stats(void)
{ {
prop_dictionary_t pkg_metad; prop_dictionary_t pkg_metad;
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -229,74 +182,93 @@ out:
return rv; return rv;
} }
prop_dictionary_t HIDDEN int HIDDEN
xbps_transaction_dictionary_get(void) xbps_transaction_init(struct xbps_handle *xhp)
{ {
if (create_transaction_dictionary() != 0) prop_array_t unsorted, mdeps;
return NULL;
return transd; if (xhp->transd != NULL)
return 0;
xhp->transd = prop_dictionary_create();
if (xhp->transd == NULL)
return ENOMEM;
unsorted = prop_array_create();
if (unsorted == NULL) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return ENOMEM;
}
if (!xbps_add_obj_to_dict(xhp->transd, unsorted, "unsorted_deps")) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return EINVAL;
}
mdeps = prop_array_create();
if (mdeps == NULL) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return ENOMEM;
}
if (!xbps_add_obj_to_dict(xhp->transd, mdeps, "missing_deps")) {
prop_object_release(xhp->transd);
xhp->transd = NULL;
return EINVAL;
}
return 0;
} }
prop_array_t int
xbps_transaction_missingdeps_get(void)
{
if (create_transaction_missingdeps() != 0)
return NULL;
return trans_mdeps;
}
prop_dictionary_t
xbps_transaction_prepare(void) xbps_transaction_prepare(void)
{ {
prop_array_t mdeps;
struct xbps_handle *xhp = xbps_handle_get();
int rv = 0; int rv = 0;
if (!transd_initialized && !trans_mdeps_initialized) { if (xhp->transd == NULL)
errno = ENXIO; return ENXIO;
return NULL;
}
/* /*
* If there are missing deps bail out. * If there are missing deps bail out.
*/ */
if (prop_array_count(trans_mdeps) > 0) { mdeps = prop_dictionary_get(xhp->transd, "missing_deps");
prop_object_release(transd); if (prop_array_count(mdeps) > 0)
errno = ENODEV; return ENODEV;
return NULL;
}
/* /*
* Check for packages to be replaced. * Check for packages to be replaced.
*/ */
if ((rv = xbps_transaction_package_replace(transd)) != 0) { if ((rv = xbps_transaction_package_replace(xhp->transd)) != 0) {
errno = rv; prop_object_release(xhp->transd);
prop_object_release(transd); xhp->transd = NULL;
prop_object_release(trans_mdeps); return rv;
return NULL;
} }
/* /*
* Sort package dependencies if necessary. * Sort package dependencies if necessary.
*/ */
if ((rv = xbps_sort_pkg_deps()) != 0) { if ((rv = xbps_transaction_sort_pkg_deps(xhp)) != 0) {
errno = rv; prop_object_release(xhp->transd);
prop_object_release(transd); xhp->transd = NULL;
prop_object_release(trans_mdeps); return rv;
return NULL;
} }
/* /*
* Add transaction stats for total download/installed size, * Add transaction stats for total download/installed size,
* number of packages to be installed, updated, configured * number of packages to be installed, updated, configured
* and removed to the transaction dictionary. * and removed to the transaction dictionary.
*/ */
if ((rv = compute_transaction_stats()) != 0) { if ((rv = compute_transaction_stats(xhp->transd)) != 0) {
errno = rv; prop_object_release(xhp->transd);
prop_object_release(transd); xhp->transd = NULL;
prop_object_release(trans_mdeps); return rv;
return NULL;
} }
/* /*
* The missing deps array is not necessary anymore. * The missing deps array is not necessary anymore.
*/ */
prop_object_release(trans_mdeps); prop_dictionary_remove(xhp->transd, "missing_deps");
prop_dictionary_make_immutable(xhp->transd);
return prop_dictionary_copy(transd); return 0;
} }

View File

@ -60,8 +60,8 @@ static int
transaction_find_pkg(const char *pattern, int action) transaction_find_pkg(const char *pattern, int action)
{ {
prop_dictionary_t pkg_pkgdb, pkg_repod = NULL; prop_dictionary_t pkg_pkgdb, pkg_repod = NULL;
prop_dictionary_t transd; prop_array_t unsorted;
prop_array_t mdeps, unsorted; struct xbps_handle *xhp = xbps_handle_get();
const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason; const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason;
int rv = 0; int rv = 0;
bool bypattern, bestpkg; bool bypattern, bestpkg;
@ -125,21 +125,15 @@ transaction_find_pkg(const char *pattern, int action)
/* /*
* Prepare transaction dictionary and missing deps array. * Prepare transaction dictionary and missing deps array.
*/ */
if ((transd = xbps_transaction_dictionary_get()) == NULL) { if ((rv = xbps_transaction_init(xhp)) != 0)
rv = EINVAL;
goto out; goto out;
}
if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) {
rv = EINVAL;
goto out;
}
/* /*
* Prepare required package dependencies and add them into the * Prepare required package dependencies and add them into the
* "unsorted" array in transaction dictionary. * "unsorted" array in transaction dictionary.
*/ */
if (xbps_pkg_has_rundeps(pkg_repod)) { if (xbps_pkg_has_rundeps(pkg_repod)) {
rv = xbps_repository_find_pkg_deps(transd, mdeps, pkg_repod); rv = xbps_repository_find_pkg_deps(xhp, pkg_repod);
if (rv != 0) if (rv != 0)
goto out; goto out;
} }
@ -174,7 +168,7 @@ transaction_find_pkg(const char *pattern, int action)
/* /*
* Add required package dictionary into the unsorted array. * Add required package dictionary into the unsorted array.
*/ */
unsorted = prop_dictionary_get(transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (unsorted == NULL) { if (unsorted == NULL) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
@ -191,7 +185,7 @@ transaction_find_pkg(const char *pattern, int action)
pkgver, repoloc); pkgver, repoloc);
out: out:
if (prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY) if (pkg_repod != NULL)
prop_object_release(pkg_repod); prop_object_release(pkg_repod);
return rv; return rv;
@ -249,9 +243,10 @@ xbps_transaction_install_pkg(const char *pkgpattern)
int int
xbps_transaction_remove_pkg(const char *pkgname, bool recursive) xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
{ {
prop_dictionary_t transd, pkgd; prop_dictionary_t pkgd;
prop_array_t mdeps, orphans, orphans_pkg, unsorted, reqby; prop_array_t orphans, orphans_pkg, unsorted, reqby;
prop_object_t obj; prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver; const char *pkgver;
size_t count; size_t count;
int rv = 0; int rv = 0;
@ -265,15 +260,10 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive)
/* /*
* Prepare transaction dictionary and missing deps array. * Prepare transaction dictionary and missing deps array.
*/ */
if ((transd = xbps_transaction_dictionary_get()) == NULL) { if ((rv = xbps_transaction_init(xhp)) != 0)
rv = ENXIO;
goto out; goto out;
}
if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) { unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
rv = ENXIO;
goto out;
}
unsorted = prop_dictionary_get(transd, "unsorted_deps");
if (!recursive) if (!recursive)
goto rmpkg; goto rmpkg;
/* /*
@ -329,9 +319,9 @@ out:
int int
xbps_transaction_autoremove_pkgs(void) xbps_transaction_autoremove_pkgs(void)
{ {
prop_dictionary_t transd; prop_array_t orphans, unsorted;
prop_array_t orphans, mdeps, unsorted;
prop_object_t obj; prop_object_t obj;
struct xbps_handle *xhp = xbps_handle_get();
const char *pkgver; const char *pkgver;
size_t count; size_t count;
int rv = 0; int rv = 0;
@ -349,18 +339,12 @@ xbps_transaction_autoremove_pkgs(void)
/* /*
* Prepare transaction dictionary and missing deps array. * Prepare transaction dictionary and missing deps array.
*/ */
if ((transd = xbps_transaction_dictionary_get()) == NULL) { if ((rv = xbps_transaction_init(xhp)) != 0)
rv = ENXIO;
goto out; goto out;
}
if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) {
rv = ENXIO;
goto out;
}
/* /*
* Add pkg orphan dictionary into the unsorted_deps array. * Add pkg orphan dictionary into the unsorted_deps array.
*/ */
unsorted = prop_dictionary_get(transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
while (count--) { while (count--) {
obj = prop_array_get(orphans, count); obj = prop_array_get(orphans, count);
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver);
@ -371,7 +355,7 @@ xbps_transaction_autoremove_pkgs(void)
pkgver); pkgver);
} }
out: out:
if (prop_object_type(orphans) == PROP_TYPE_ARRAY) if (orphans != NULL)
prop_object_release(orphans); prop_object_release(orphans);
return rv; return rv;
} }

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2009-2011 Juan Romero Pardines. * Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -303,9 +303,8 @@ again:
} }
int HIDDEN int HIDDEN
xbps_sort_pkg_deps(void) xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
{ {
prop_dictionary_t transd;
prop_array_t sorted, unsorted, rundeps; prop_array_t sorted, unsorted, rundeps;
prop_object_t obj; prop_object_t obj;
prop_object_iterator_t iter; prop_object_iterator_t iter;
@ -314,25 +313,22 @@ xbps_sort_pkg_deps(void)
const char *pkgname, *pkgver, *tract; const char *pkgname, *pkgver, *tract;
int rv = 0; int rv = 0;
if ((transd = xbps_transaction_dictionary_get()) == NULL)
return EINVAL;
sorted = prop_array_create(); sorted = prop_array_create();
if (sorted == NULL) if (sorted == NULL)
return ENOMEM; return ENOMEM;
/* /*
* Add sorted packages array into transaction dictionary (empty). * Add sorted packages array into transaction dictionary (empty).
*/ */
if (!prop_dictionary_set(transd, "packages", sorted)) { if (!prop_dictionary_set(xhp->transd, "packages", sorted)) {
rv = EINVAL; rv = EINVAL;
goto out; goto out;
} }
/* /*
* All required deps are satisfied (already installed). * All required deps are satisfied (already installed).
*/ */
unsorted = prop_dictionary_get(transd, "unsorted_deps"); unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
if (prop_array_count(unsorted) == 0) { if (prop_array_count(unsorted) == 0) {
prop_dictionary_set(transd, "packages", sorted); prop_dictionary_set(xhp->transd, "packages", sorted);
return 0; return 0;
} }
/* /*
@ -395,7 +391,7 @@ xbps_sort_pkg_deps(void)
/* /*
* Sort package run-time dependencies for this package. * Sort package run-time dependencies for this package.
*/ */
if ((rv = sort_pkg_rundeps(transd, pd, rundeps)) != 0) { if ((rv = sort_pkg_rundeps(xhp->transd, pd, rundeps)) != 0) {
pkgdep_end(NULL); pkgdep_end(NULL);
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
goto out; goto out;
@ -418,10 +414,10 @@ xbps_sort_pkg_deps(void)
* We are done, all packages were sorted... remove the * We are done, all packages were sorted... remove the
* temporary array with unsorted packages. * temporary array with unsorted packages.
*/ */
prop_dictionary_remove(transd, "unsorted_deps"); prop_dictionary_remove(xhp->transd, "unsorted_deps");
out: out:
if (rv != 0) if (rv != 0)
prop_dictionary_remove(transd, "packages"); prop_dictionary_remove(xhp->transd, "packages");
prop_object_release(sorted); prop_object_release(sorted);