diff --git a/bin/xbps-bin/check.c b/bin/xbps-bin/check.c index 9aee5585..87ec4941 100644 --- a/bin/xbps-bin/check.c +++ b/bin/xbps-bin/check.c @@ -63,14 +63,13 @@ cb_pkg_integrity(prop_object_t obj, void *arg, bool *done) int check_pkg_integrity_all(void) { - struct xbps_handle *xhp = xbps_handle_get(); struct checkpkg cpkg; int rv; memset(&cpkg, 0, sizeof(cpkg)); (void)xbps_pkgdb_foreach_cb(cb_pkg_integrity, &cpkg); 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", strerror(rv)); return rv; diff --git a/bin/xbps-bin/transaction.c b/bin/xbps-bin/transaction.c index a9395a99..95a4cb0f 100644 --- a/bin/xbps-bin/transaction.c +++ b/bin/xbps-bin/transaction.c @@ -368,30 +368,32 @@ remove_pkg(const char *pkgname, bool recursive) int exec_transaction(bool yes, bool show_download_urls) { + prop_array_t mdeps; struct transaction *trans; - prop_array_t array; + struct xbps_handle *xhp = xbps_handle_get(); int rv = 0; trans = calloc(1, sizeof(*trans)); if (trans == NULL) return ENOMEM; - if ((trans->d = xbps_transaction_prepare()) == NULL) { - if (errno == ENODEV) { + if ((rv = xbps_transaction_prepare()) != 0) { + if (rv == ENODEV) { + mdeps = + prop_dictionary_get(xhp->transd, "missing_deps"); /* missing packages */ - array = xbps_transaction_missingdeps_get(); - show_missing_deps(array); - rv = errno; + show_missing_deps(mdeps); goto out; } xbps_dbg_printf("Empty transaction dictionary: %s\n", strerror(errno)); - return errno; + return rv; } 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) { rv = errno; 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! */ - rv = xbps_transaction_commit(trans->d); - if (rv == 0) { + if ((rv = xbps_transaction_commit()) == 0) { printf("\nxbps-bin: %u installed, %u updated, " "%u configured, %u removed.\n", 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: if (trans->iter) prop_object_iterator_release(trans->iter); - if (trans->d) - prop_object_release(trans->d); if (trans) free(trans); diff --git a/bin/xbps-repo/main.c b/bin/xbps-repo/main.c index 897f4952..3fb1e983 100644 --- a/bin/xbps-repo/main.c +++ b/bin/xbps-repo/main.c @@ -241,7 +241,7 @@ main(int argc, char **argv) if (argc != 1) usage(); - rv = xbps_repository_pool_sync(&xh); + rv = xbps_repository_pool_sync(); if (rv == ENOTSUP) { xbps_error_printf("xbps-repo: no repositories " "currently registered!\n"); diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 950b4040..2e84d7a9 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -389,7 +389,7 @@ main(int argc, char **argv) } xh.pkgdb = prop_array_copy(array); prop_object_release(dict); - rv = xbps_pkgdb_update(&xh, true); + rv = xbps_pkgdb_update(true); if (rv == 0) { printf("Migrated regpkgdb to pkgdb " "successfully.\n"); diff --git a/include/xbps_api.h b/include/xbps_api.h index d1180b64..62fc3a7d 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,7 +56,7 @@ */ #define XBPS_PKGINDEX_VERSION "1.4" -#define XBPS_API_VERSION "20120120-1" +#define XBPS_API_VERSION "20120122" #define XBPS_VERSION "0.12" /** @@ -440,6 +440,13 @@ struct xbps_handle { * stored in XBPS_META_PATH/XBPS_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 * 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 * 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 * be flushed atomically to storage. * * @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] pkgname Package name to be matched. * - * @return 0 on success, EINVAL if dictionary couldn't be set in - * array or ENOENT if no match. + * @retval 0 success. + * @retval EINVAL Dictionary couldn't be set in array. + * @retval ENOENT No match. */ int xbps_array_replace_dict_by_name(prop_array_t array, 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] pattern Package pattern to be matched, i.e `foo>=0'. * - * @return 0 on success, EINVAL id dictionary couldn't be set in the array - * or ENOENT if no match. + * @retval 0 success. + * @retval EINVAL Dictionary couldn't be set in array. + * @retval ENOENT No match. */ int xbps_array_replace_dict_by_pattern(prop_array_t array, 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 * 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 - * has reverse dependencies, EINVAL or ENXIO if a problem ocurred in the - * process. + * @retval 0 success. + * @retval ENOENT Package is not installed. + * @retval EEXIST Package has reverse dependencies. + * @retval EINVAL + * @retval ENXIO A problem ocurred in the process. */ int xbps_transaction_remove_pkg(const char *pkgname, bool recursive); @@ -1347,8 +1356,10 @@ int xbps_transaction_remove_pkg(const char *pkgname, * Finds all package orphans currently installed and adds them into * the transaction dictionary. * - * @return 0 on succcess, ENOENT if no package orphans were found, ENXIO - * or EINVAL if a problem ocurred in the process. + * @retval 0 success. + * @retval ENOENT No package orphans were found. + * @retval ENXIO + * @retval EINVAL A problem ocurred in the process. */ 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 * and total installed/download size for the transaction is computed. * - * @return The proplib transaction dictionary on success, otherwise NULL - * and errno is set appropiately. ENXIO if the transaction - * dictionary and the missing deps array were not created. ENODEV if - * there are missing dependencies or any other if there was an error - * while sorting packages or computing the transaction size. - * - * @note - * - This function will set errno to ENXIO if xbps_transaction_install_pkg() - * or xbps_transaction_update_pkg() functions were not called previously. + * @retval 0 success. + * @retval ENXIO if transaction dictionary and missing deps array were not created, + * due to xbps_transaction_install_pkg() or xbps_transaction_update_pkg() not + * previously called. + * @retval ENODEV if there are missing dependencies in transaction ("missing_deps" + * array of strings object in xhp->transd dictionary). + * @retval EINVAL There was an error sorting packages or computing the transaction + * sizes. */ -prop_dictionary_t xbps_transaction_prepare(void); +int xbps_transaction_prepare(void); /** - * Commit a transaction. The transaction dictionary contains all steps - * to be executed in the transaction, as returned by xbps_transaction_prepare(). - * - * @param[in] transd The transaction dictionary. + * Commit a transaction. The transaction dictionary in xhp->transd contains all + * steps to be executed in the transaction, as prepared by + * xbps_transaction_prepare(). * * @return 0 on success, otherwise an errno value. */ -int xbps_transaction_commit(prop_dictionary_t transd); - -/** - * 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); +int xbps_transaction_commit(void); /*@}*/ @@ -1445,13 +1445,10 @@ struct repository_pool_index { * Synchronizes the package index file for all remote repositories * 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 * 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 diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 4ee76bd9..b8cb147b 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -120,8 +120,7 @@ int HIDDEN xbps_remove_obsoletes(const char *, * @private * From lib/repository_finddeps.c */ -int HIDDEN xbps_repository_find_pkg_deps(prop_dictionary_t, - prop_array_t, +int HIDDEN xbps_repository_find_pkg_deps(struct xbps_handle *, prop_dictionary_t); /** @@ -135,13 +134,13 @@ int HIDDEN xbps_requiredby_pkg_remove(const char *); * @private * From lib/transaction_sortdeps.c */ -int HIDDEN xbps_sort_pkg_deps(void); +int HIDDEN xbps_transaction_sort_pkg_deps(struct xbps_handle *); /** * @private * From lib/transaction_dictionary.c */ -prop_dictionary_t HIDDEN xbps_transaction_dictionary_get(void); +int HIDDEN xbps_transaction_init(struct xbps_handle *); /** * @private diff --git a/lib/package_configure.c b/lib/package_configure.c index c7b1a1c1..4582cd00 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -62,12 +62,11 @@ configure_pkgs_cb(prop_object_t obj, void *arg, bool *done) int xbps_configure_packages(bool flush) { - struct xbps_handle *xhp = xbps_handle_get(); int rv; rv = xbps_pkgdb_foreach_cb(configure_pkgs_cb, NULL); if (rv == 0 && flush) - rv = xbps_pkgdb_update(xhp, true); + rv = xbps_pkgdb_update(true); return rv; } @@ -169,7 +168,7 @@ xbps_configure_pkg(const char *pkgname, } free(pkgver); if (flush) - rv = xbps_pkgdb_update(xhp, true); + rv = xbps_pkgdb_update(true); return rv; } diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 65e50795..810d3845 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -64,7 +64,7 @@ xbps_pkgdb_init(struct xbps_handle *xhp) if (xhp->pkgdb != NULL) return 0; - if ((rv = xbps_pkgdb_update(xhp, false)) != 0) { + if ((rv = xbps_pkgdb_update(false)) != 0) { if (rv != ENOENT) xbps_dbg_printf("[pkgdb] cannot internalize " "pkgdb array: %s\n", strerror(rv)); @@ -77,8 +77,9 @@ xbps_pkgdb_init(struct xbps_handle *xhp) } 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; int rv = 0; @@ -213,7 +214,7 @@ xbps_pkgdb_remove_pkgd(const char *pkg, bool bypattern, bool flush) if (!flush || !rv) return rv; - if ((xbps_pkgdb_update(xhp, true)) != 0) + if ((xbps_pkgdb_update(true)) != 0) return false; return true; @@ -239,7 +240,7 @@ xbps_pkgdb_replace_pkgd(prop_dictionary_t pkgd, if (!flush) return rv != 0 ? false : true; - if ((xbps_pkgdb_update(xhp, true)) != 0) + if ((xbps_pkgdb_update(true)) != 0) return false; return true; diff --git a/lib/repository_finddeps.c b/lib/repository_finddeps.c index a456b13e..23dccf5c 100644 --- a/lib/repository_finddeps.c +++ b/lib/repository_finddeps.c @@ -172,25 +172,25 @@ out: #define MAX_DEPTH 512 static int -find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ - prop_array_t mrdeps, /* missing rundeps array */ +find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ + prop_array_t trans_mdeps, /* transaction missing deps array */ prop_array_t pkg_rdeps_array, /* current pkg rundeps array */ const char *curpkg, /* current pkgver */ size_t *depth) /* max recursion depth */ { + struct xbps_handle *xhp = xbps_handle_get(); prop_dictionary_t curpkgd, tmpd; prop_array_t curpkgrdeps; prop_object_t obj; prop_object_iterator_t iter; pkg_state_t state; - const struct xbps_handle *xhp = xbps_handle_get(); size_t x; const char *reqpkg, *pkgver_q, *reason = NULL; char *pkgname; int rv = 0; 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); 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 * was matched. */ - curpkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern(transd, - "unsorted_deps", reqpkg); + curpkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern( + transd, "unsorted_deps", reqpkg); if (curpkgd == NULL) { /* * Look for a real package matching pattern * if no match. */ - curpkgd = xbps_find_pkg_in_dict_by_pattern(transd, - "unsorted_deps", reqpkg); + curpkgd = xbps_find_pkg_in_dict_by_pattern( + transd, "unsorted_deps", reqpkg); } if (curpkgd != NULL) { 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); if (curpkgd == NULL) { - curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, false); + curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, + false); if (curpkgd == NULL) { /* pkg not found, there was some error */ if (errno && errno != ENOENT) { @@ -375,19 +376,21 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ break; } - rv = add_missing_reqdep(mrdeps, reqpkg); + rv = add_missing_reqdep(trans_mdeps, reqpkg); if (rv != 0 && rv != EEXIST) { xbps_dbg_printf_append("`%s': " - "add_missing_reqdep failed %s\n", reqpkg); + "add_missing_reqdep failed %s\n", + reqpkg); break; } else if (rv == EEXIST) { - xbps_dbg_printf_append("`%s' missing dep " - "already added.\n", reqpkg); + xbps_dbg_printf_append("`%s' missing " + "dep already added.\n", reqpkg); rv = 0; continue; } else { xbps_dbg_printf_append("`%s' added " - "into the missing deps array.\n", reqpkg); + "into the missing deps array.\n", + reqpkg); continue; } } @@ -428,7 +431,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */ * Recursively find rundeps for current pkg dictionary. */ (*depth)++; - rv = find_repo_deps(transd, mrdeps, curpkgrdeps, + rv = find_repo_deps(transd, trans_mdeps, curpkgrdeps, pkgver_q, depth); if (rv != 0) { 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 -xbps_repository_find_pkg_deps(prop_dictionary_t transd, - prop_array_t mdeps, +xbps_repository_find_pkg_deps(struct xbps_handle *xhp, prop_dictionary_t repo_pkgd) { - prop_array_t pkg_rdeps; + prop_array_t mdeps, pkg_rdeps; const char *pkgver; size_t depth = 0; int rv = 0; - assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); - assert(prop_object_type(mdeps) == PROP_TYPE_ARRAY); + assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY); assert(prop_object_type(repo_pkgd) == PROP_TYPE_DICTIONARY); 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); 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 * 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) { xbps_dbg_printf("Error '%s' while checking rundeps!\n", strerror(rv)); diff --git a/lib/repository_pool.c b/lib/repository_pool.c index f10cb621..17052407 100644 --- a/lib/repository_pool.c +++ b/lib/repository_pool.c @@ -181,8 +181,9 @@ xbps_repository_pool_release(struct xbps_handle *xhp) } 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; size_t i; int rv; diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 23cd4762..05a34f73 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -180,9 +180,9 @@ download_binpkgs(struct xbps_handle *xhp, prop_object_iterator_t iter) } 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_iterator_t iter; size_t i; @@ -190,11 +190,10 @@ xbps_transaction_commit(prop_dictionary_t transd) int rv = 0; bool update, install; - assert(prop_object_type(transd) == PROP_TYPE_DICTIONARY); + assert(prop_object_type(xhp->transd) == PROP_TYPE_DICTIONARY); update = install = false; - xhp = xbps_handle_get(); - iter = xbps_array_iter_from_dict(transd, "packages"); + iter = xbps_array_iter_from_dict(xhp->transd, "packages"); if (iter == NULL) return EINVAL; /* @@ -219,7 +218,7 @@ xbps_transaction_commit(prop_dictionary_t transd) while ((obj = prop_object_iterator_next(iter)) != NULL) { if ((xhp->transaction_frequency_flush > 0) && (++i >= xhp->transaction_frequency_flush)) { - rv = xbps_pkgdb_update(xhp, true); + rv = xbps_pkgdb_update(true); if (rv != 0 && rv != ENOENT) goto out; @@ -295,7 +294,7 @@ xbps_transaction_commit(prop_dictionary_t transd) prop_object_iterator_reset(iter); /* 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; /* 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) { if (xhp->transaction_frequency_flush > 0 && ++i >= xhp->transaction_frequency_flush) { - if ((rv = xbps_pkgdb_update(xhp, true)) != 0) + if ((rv = xbps_pkgdb_update(true)) != 0) goto out; i = 0; @@ -344,7 +343,7 @@ xbps_transaction_commit(prop_dictionary_t transd) } /* Force a flush now that packages are configured */ - rv = xbps_pkgdb_update(xhp, true); + rv = xbps_pkgdb_update(true); out: prop_object_iterator_release(iter); diff --git a/lib/transaction_dictionary.c b/lib/transaction_dictionary.c index 08602154..965d0785 100644 --- a/lib/transaction_dictionary.c +++ b/lib/transaction_dictionary.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2011 Juan Romero Pardines. + * Copyright (c) 2009-2012 Juan Romero Pardines. * All rights reserved. * * 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. */ -static prop_dictionary_t transd; -static prop_array_t trans_mdeps; -static bool transd_initialized; -static bool trans_mdeps_initialized; - static int -create_transaction_dictionary(void) -{ - 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) +compute_transaction_stats(prop_dictionary_t transd) { prop_dictionary_t pkg_metad; prop_object_iterator_t iter; @@ -229,74 +182,93 @@ out: return rv; } -prop_dictionary_t HIDDEN -xbps_transaction_dictionary_get(void) +int HIDDEN +xbps_transaction_init(struct xbps_handle *xhp) { - if (create_transaction_dictionary() != 0) - return NULL; + prop_array_t unsorted, mdeps; - 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 -xbps_transaction_missingdeps_get(void) -{ - if (create_transaction_missingdeps() != 0) - return NULL; - - return trans_mdeps; -} - -prop_dictionary_t +int xbps_transaction_prepare(void) { + prop_array_t mdeps; + struct xbps_handle *xhp = xbps_handle_get(); int rv = 0; - if (!transd_initialized && !trans_mdeps_initialized) { - errno = ENXIO; - return NULL; - } + if (xhp->transd == NULL) + return ENXIO; + /* * If there are missing deps bail out. */ - if (prop_array_count(trans_mdeps) > 0) { - prop_object_release(transd); - errno = ENODEV; - return NULL; - } + mdeps = prop_dictionary_get(xhp->transd, "missing_deps"); + if (prop_array_count(mdeps) > 0) + return ENODEV; + /* * Check for packages to be replaced. */ - if ((rv = xbps_transaction_package_replace(transd)) != 0) { - errno = rv; - prop_object_release(transd); - prop_object_release(trans_mdeps); - return NULL; + if ((rv = xbps_transaction_package_replace(xhp->transd)) != 0) { + prop_object_release(xhp->transd); + xhp->transd = NULL; + return rv; } /* * Sort package dependencies if necessary. */ - if ((rv = xbps_sort_pkg_deps()) != 0) { - errno = rv; - prop_object_release(transd); - prop_object_release(trans_mdeps); - return NULL; + if ((rv = xbps_transaction_sort_pkg_deps(xhp)) != 0) { + prop_object_release(xhp->transd); + xhp->transd = NULL; + return rv; } /* * Add transaction stats for total download/installed size, * number of packages to be installed, updated, configured * and removed to the transaction dictionary. */ - if ((rv = compute_transaction_stats()) != 0) { - errno = rv; - prop_object_release(transd); - prop_object_release(trans_mdeps); - return NULL; + if ((rv = compute_transaction_stats(xhp->transd)) != 0) { + prop_object_release(xhp->transd); + xhp->transd = NULL; + return rv; } /* * 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; } diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 93d988b2..5686c0d9 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -60,8 +60,8 @@ static int transaction_find_pkg(const char *pattern, int action) { prop_dictionary_t pkg_pkgdb, pkg_repod = NULL; - prop_dictionary_t transd; - prop_array_t mdeps, unsorted; + prop_array_t unsorted; + struct xbps_handle *xhp = xbps_handle_get(); const char *pkgname, *pkgver, *repoloc, *repover, *instver, *reason; int rv = 0; bool bypattern, bestpkg; @@ -125,21 +125,15 @@ transaction_find_pkg(const char *pattern, int action) /* * Prepare transaction dictionary and missing deps array. */ - if ((transd = xbps_transaction_dictionary_get()) == NULL) { - rv = EINVAL; + if ((rv = xbps_transaction_init(xhp)) != 0) goto out; - } - if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) { - rv = EINVAL; - goto out; - } /* * Prepare required package dependencies and add them into the * "unsorted" array in transaction dictionary. */ 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) goto out; } @@ -174,7 +168,7 @@ transaction_find_pkg(const char *pattern, int action) /* * 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) { rv = EINVAL; goto out; @@ -191,7 +185,7 @@ transaction_find_pkg(const char *pattern, int action) pkgver, repoloc); out: - if (prop_object_type(pkg_repod) == PROP_TYPE_DICTIONARY) + if (pkg_repod != NULL) prop_object_release(pkg_repod); return rv; @@ -249,9 +243,10 @@ xbps_transaction_install_pkg(const char *pkgpattern) int xbps_transaction_remove_pkg(const char *pkgname, bool recursive) { - prop_dictionary_t transd, pkgd; - prop_array_t mdeps, orphans, orphans_pkg, unsorted, reqby; + prop_dictionary_t pkgd; + prop_array_t orphans, orphans_pkg, unsorted, reqby; prop_object_t obj; + struct xbps_handle *xhp = xbps_handle_get(); const char *pkgver; size_t count; int rv = 0; @@ -265,15 +260,10 @@ xbps_transaction_remove_pkg(const char *pkgname, bool recursive) /* * Prepare transaction dictionary and missing deps array. */ - if ((transd = xbps_transaction_dictionary_get()) == NULL) { - rv = ENXIO; + if ((rv = xbps_transaction_init(xhp)) != 0) goto out; - } - if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) { - rv = ENXIO; - goto out; - } - unsorted = prop_dictionary_get(transd, "unsorted_deps"); + + unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps"); if (!recursive) goto rmpkg; /* @@ -329,9 +319,9 @@ out: int xbps_transaction_autoremove_pkgs(void) { - prop_dictionary_t transd; - prop_array_t orphans, mdeps, unsorted; + prop_array_t orphans, unsorted; prop_object_t obj; + struct xbps_handle *xhp = xbps_handle_get(); const char *pkgver; size_t count; int rv = 0; @@ -349,18 +339,12 @@ xbps_transaction_autoremove_pkgs(void) /* * Prepare transaction dictionary and missing deps array. */ - if ((transd = xbps_transaction_dictionary_get()) == NULL) { - rv = ENXIO; + if ((rv = xbps_transaction_init(xhp)) != 0) goto out; - } - if ((mdeps = xbps_transaction_missingdeps_get()) == NULL) { - rv = ENXIO; - goto out; - } /* * 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--) { obj = prop_array_get(orphans, count); prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); @@ -371,7 +355,7 @@ xbps_transaction_autoremove_pkgs(void) pkgver); } out: - if (prop_object_type(orphans) == PROP_TYPE_ARRAY) + if (orphans != NULL) prop_object_release(orphans); return rv; } diff --git a/lib/transaction_sortdeps.c b/lib/transaction_sortdeps.c index ab386651..8773e90c 100644 --- a/lib/transaction_sortdeps.c +++ b/lib/transaction_sortdeps.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2011 Juan Romero Pardines. + * Copyright (c) 2009-2012 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -303,9 +303,8 @@ again: } 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_object_t obj; prop_object_iterator_t iter; @@ -314,25 +313,22 @@ xbps_sort_pkg_deps(void) const char *pkgname, *pkgver, *tract; int rv = 0; - if ((transd = xbps_transaction_dictionary_get()) == NULL) - return EINVAL; - sorted = prop_array_create(); if (sorted == NULL) return ENOMEM; /* * 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; goto out; } /* * 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) { - prop_dictionary_set(transd, "packages", sorted); + prop_dictionary_set(xhp->transd, "packages", sorted); return 0; } /* @@ -395,7 +391,7 @@ xbps_sort_pkg_deps(void) /* * 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); prop_object_iterator_release(iter); goto out; @@ -418,10 +414,10 @@ xbps_sort_pkg_deps(void) * We are done, all packages were sorted... remove the * temporary array with unsorted packages. */ - prop_dictionary_remove(transd, "unsorted_deps"); + prop_dictionary_remove(xhp->transd, "unsorted_deps"); out: if (rv != 0) - prop_dictionary_remove(transd, "packages"); + prop_dictionary_remove(xhp->transd, "packages"); prop_object_release(sorted);