int xbps_alternatives_unregister(struct xbps_handle *xhp, xbps_dictionary_t pkgd) { xbps_array_t allkeys; xbps_dictionary_t alternatives, pkg_alternatives; const char *pkgver; char *pkgname; bool update = false; int rv = 0; assert(xhp); alternatives = xbps_dictionary_get(xhp->pkgdb, "_XBPS_ALTERNATIVES_"); if (alternatives == NULL) return 0; pkg_alternatives = xbps_dictionary_get(pkgd, "alternatives"); if (!xbps_dictionary_count(pkg_alternatives)) return 0; xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); if ((pkgname = xbps_pkg_name(pkgver)) == NULL) return EINVAL; xbps_dictionary_get_bool(pkgd, "alternatives-update", &update); allkeys = xbps_dictionary_all_keys(pkg_alternatives); for (unsigned int i = 0; i < xbps_array_count(allkeys); i++) { xbps_array_t array; xbps_object_t keysym; const char *first = NULL, *keyname; keysym = xbps_array_get(allkeys, i); keyname = xbps_dictionary_keysym_cstring_nocopy(keysym); array = xbps_dictionary_get(alternatives, keyname); if (array == NULL) continue; xbps_array_get_cstring_nocopy(array, 0, &first); if (strcmp(pkgname, first) == 0) { /* this pkg is the current alternative for this group */ rv = remove_symlinks(xhp, xbps_dictionary_get(pkg_alternatives, keyname), keyname); if (rv != 0) break; } xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_REMOVED, 0, NULL, "%s: unregistered '%s' alternatives group", pkgver, keyname); if (!update) xbps_remove_string_from_array(array, pkgname); if (xbps_array_count(array) == 0) { xbps_dictionary_remove(alternatives, keyname); } else { xbps_dictionary_t curpkgd; first = NULL; xbps_array_get_cstring_nocopy(array, 0, &first); curpkgd = xbps_pkgdb_get_pkg(xhp, first); assert(curpkgd); xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_SWITCHED, 0, NULL, "Switched '%s' alternatives group to '%s'", keyname, first); pkg_alternatives = xbps_dictionary_get(curpkgd, "alternatives"); rv = create_symlinks(xhp, xbps_dictionary_get(pkg_alternatives, keyname), keyname); if (rv != 0) break; } } xbps_object_release(allkeys); free(pkgname); return rv; }
int HIDDEN xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update, bool soft_replace) { xbps_dictionary_t pkgd = NULL; char *pkgname, *buf = NULL; int rv = 0; pkg_state_t state = 0; assert(xhp); assert(pkgver); pkgname = xbps_pkg_name(pkgver); assert(pkgname); if ((rv = xbps_pkg_state_installed(xhp, pkgname, &state)) != 0) goto out; xbps_dbg_printf(xhp, "attempting to remove %s state %d\n", pkgver, state); if (!update) xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgver, NULL); if (chdir(xhp->rootdir) == -1) { rv = errno; xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] failed to chdir to rootdir `%s': %s", pkgver, xhp->rootdir, strerror(rv)); goto out; } /* internalize pkg dictionary from metadir */ buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname); pkgd = xbps_dictionary_internalize_from_file(buf); free(buf); if (pkgd == NULL) xbps_dbg_printf(xhp, "WARNING: metaplist for %s " "doesn't exist!\n", pkgver); /* If package was "half-removed", remove it fully. */ if (state == XBPS_PKG_STATE_HALF_REMOVED) goto purge; /* * Run the pre remove action. */ if (pkgd) { rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "pre", update); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, errno, pkgver, "%s: [remove] REMOVE script failed to " "execute pre ACTION: %s", pkgver, strerror(rv)); goto out; } } /* * If updating a package, we just need to execute the current * pre-remove action target and we are done. Its files will be * overwritten later in unpack phase. */ if (update) { if (pkgd) xbps_object_release(pkgd); free(pkgname); return 0; } else if (soft_replace) { /* * Soft replace a package. Do not remove its files, but * execute PURGE action, remove metadata files and unregister * from pkgdb. */ goto softreplace; } if (pkgd) { /* Remove regular files */ if ((rv = xbps_remove_pkg_files(xhp, pkgd, "files", pkgver)) != 0) goto out; /* Remove configuration files */ if ((rv = xbps_remove_pkg_files(xhp, pkgd, "conf_files", pkgver)) != 0) goto out; /* Remove links */ if ((rv = xbps_remove_pkg_files(xhp, pkgd, "links", pkgver)) != 0) goto out; /* Remove dirs */ if ((rv = xbps_remove_pkg_files(xhp, pkgd, "dirs", pkgver)) != 0) goto out; /* * Execute the post REMOVE action if file exists and we aren't * updating the package. */ rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] REMOVE script failed to execute " "post ACTION: %s", pkgver, strerror(rv)); goto out; } } softreplace: /* * Set package state to "half-removed". */ rv = xbps_set_pkg_state_installed(xhp, pkgver, XBPS_PKG_STATE_HALF_REMOVED); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] failed to set state to half-removed: %s", pkgver, strerror(rv)); goto out; } purge: /* * Execute the purge REMOVE action if file exists. */ if (pkgd) { rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: REMOVE script failed to execute " "purge ACTION: %s", pkgver, strerror(rv)); goto out; } xbps_object_release(pkgd); } /* * Remove package metadata plist. */ buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname); if (remove(buf) == -1) { if (errno != ENOENT) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: failed to remove metadata file: %s", pkgver, strerror(errno)); } } free(buf); /* * Unregister package from pkgdb. */ xbps_dictionary_remove(xhp->pkgdb, pkgname); if ((rv = xbps_pkgdb_update(xhp, true)) != 0) goto out; xbps_dbg_printf(xhp, "[remove] unregister %s returned %d\n", pkgver, rv); xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL); out: if (pkgname != NULL) free(pkgname); return rv; }
int HIDDEN xbps_remove_pkg(struct xbps_handle *xhp, const char *pkgver, bool update) { xbps_dictionary_t pkgd = NULL, pkgfilesd = NULL; char *pkgname, metafile[PATH_MAX]; int rv = 0; pkg_state_t state = 0; uid_t euid; assert(xhp); assert(pkgver); pkgname = xbps_pkg_name(pkgver); assert(pkgname); euid = geteuid(); if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) { rv = errno; xbps_dbg_printf(xhp, "[remove] cannot find %s in pkgdb: %s\n", pkgver, strerror(rv)); goto out; } if ((rv = xbps_pkg_state_dictionary(pkgd, &state)) != 0) { xbps_dbg_printf(xhp, "[remove] cannot find %s in pkgdb: %s\n", pkgver, strerror(rv)); goto out; } xbps_dbg_printf(xhp, "attempting to remove %s state %d\n", pkgver, state); if (!update) xbps_set_cb_state(xhp, XBPS_STATE_REMOVE, 0, pkgver, NULL); if (chdir(xhp->rootdir) == -1) { rv = errno; xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] failed to chdir to rootdir `%s': %s", pkgver, xhp->rootdir, strerror(rv)); goto out; } /* internalize pkg files dictionary from metadir */ snprintf(metafile, sizeof(metafile), "%s/.%s-files.plist", xhp->metadir, pkgname); pkgfilesd = xbps_plist_dictionary_from_file(xhp, metafile); if (pkgfilesd == NULL) xbps_dbg_printf(xhp, "WARNING: metaplist for %s " "doesn't exist!\n", pkgver); /* If package was "half-removed", remove it fully. */ if (state == XBPS_PKG_STATE_HALF_REMOVED) goto purge; /* * Run the pre remove action and show pre-remove message if exists. */ rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "pre", update); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, errno, pkgver, "%s: [remove] REMOVE script failed to " "execute pre ACTION: %s", pkgver, strerror(rv)); goto out; } /* show remove-msg if exists */ if ((rv = xbps_cb_message(xhp, pkgd, "remove-msg")) != 0) goto out; /* unregister alternatives */ if (update) xbps_dictionary_set_bool(pkgd, "alternatives-update", true); if ((rv = xbps_alternatives_unregister(xhp, pkgd)) != 0) goto out; /* * If updating a package, we just need to execute the current * pre-remove action target and we are done. Its files will be * overwritten later in unpack phase. */ if (update) { free(pkgname); return 0; } if (pkgfilesd) { /* * Do the removal in 2 phases: * 1- check if user has enough perms to remove all entries * 2- perform removal */ if (check_remove_pkg_files(xhp, pkgfilesd, pkgver, euid)) { rv = EPERM; goto out; } /* Remove links */ if ((rv = remove_pkg_files(xhp, pkgfilesd, "links", pkgver)) != 0) goto out; /* Remove regular files */ if ((rv = remove_pkg_files(xhp, pkgfilesd, "files", pkgver)) != 0) goto out; /* Remove configuration files */ if ((rv = remove_pkg_files(xhp, pkgfilesd, "conf_files", pkgver)) != 0) goto out; /* Remove dirs */ if ((rv = remove_pkg_files(xhp, pkgfilesd, "dirs", pkgver)) != 0) goto out; } /* * Execute the post REMOVE action if file exists and we aren't * updating the package. */ rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "post", false); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] REMOVE script failed to execute " "post ACTION: %s", pkgver, strerror(rv)); goto out; } /* * Set package state to "half-removed". */ rv = xbps_set_pkg_state_installed(xhp, pkgver, XBPS_PKG_STATE_HALF_REMOVED); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: [remove] failed to set state to half-removed: %s", pkgver, strerror(rv)); goto out; } purge: /* * Execute the purge REMOVE action if file exists. */ rv = xbps_pkg_exec_script(xhp, pkgd, "remove-script", "purge", false); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: REMOVE script failed to execute " "purge ACTION: %s", pkgver, strerror(rv)); goto out; } /* * Remove package metadata plist. */ if (remove(metafile) == -1) { if (errno != ENOENT) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: failed to remove metadata file: %s", pkgver, strerror(errno)); } } /* * Unregister package from pkgdb. */ xbps_dictionary_remove(xhp->pkgdb, pkgname); xbps_dbg_printf(xhp, "[remove] unregister %s returned %d\n", pkgver, rv); xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_DONE, 0, pkgver, NULL); out: if (pkgname != NULL) free(pkgname); if (rv != 0) { xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL, rv, pkgver, "%s: failed to remove package: %s", pkgver, strerror(rv)); } return rv; }
static int create_pkg_metaplist(struct xbps_handle *xhp, const char *pkgname, const char *pkgver, xbps_dictionary_t propsd, xbps_dictionary_t filesd, const void *instbuf, const size_t instbufsiz, const void *rembuf, const size_t rembufsiz) { xbps_array_t array; xbps_dictionary_t pkg_metad; xbps_data_t data; char *buf; int rv = 0; xbps_dictionary_make_immutable(propsd); pkg_metad = xbps_dictionary_copy_mutable(propsd); /* Add objects from XBPS_PKGFILES */ array = xbps_dictionary_get(filesd, "files"); if (xbps_array_count(array)) xbps_dictionary_set(pkg_metad, "files", array); array = xbps_dictionary_get(filesd, "conf_files"); if (xbps_array_count(array)) xbps_dictionary_set(pkg_metad, "conf_files", array); array = xbps_dictionary_get(filesd, "links"); if (xbps_array_count(array)) xbps_dictionary_set(pkg_metad, "links", array); array = xbps_dictionary_get(filesd, "dirs"); if (xbps_array_count(array)) xbps_dictionary_set(pkg_metad, "dirs", array); /* Add install/remove scripts data objects */ if (instbuf != NULL) { data = xbps_data_create_data(instbuf, instbufsiz); assert(data); xbps_dictionary_set(pkg_metad, "install-script", data); xbps_object_release(data); } if (rembuf != NULL) { data = xbps_data_create_data(rembuf, rembufsiz); assert(data); xbps_dictionary_set(pkg_metad, "remove-script", data); xbps_object_release(data); } /* Remove unneeded objs from transaction */ xbps_dictionary_remove(pkg_metad, "remove-and-update"); xbps_dictionary_remove(pkg_metad, "transaction"); xbps_dictionary_remove(pkg_metad, "state"); xbps_dictionary_remove(pkg_metad, "pkgname"); xbps_dictionary_remove(pkg_metad, "version"); /* * Externalize pkg dictionary to metadir. */ if (access(xhp->metadir, R_OK|X_OK) == -1) { if (errno == ENOENT) { xbps_mkpath(xhp->metadir, 0755); } else { return errno; } } buf = xbps_xasprintf("%s/.%s.plist", XBPS_META_PATH, pkgname); if (!xbps_dictionary_externalize_to_file(pkg_metad, buf)) { rv = errno; xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL, errno, pkgver, "%s: [unpack] failed to write metadata file `%s': %s", pkgver, buf, strerror(errno)); } free(buf); xbps_object_release(pkg_metad); return rv; }
static bool repodata_commit(struct xbps_handle *xhp, const char *repodir, xbps_dictionary_t idx, xbps_dictionary_t meta, xbps_dictionary_t stage) { const char *pkgname; xbps_object_iterator_t iter; xbps_object_t keysym; int rv; if(xbps_dictionary_count(stage) == 0) { // Nothing to do. return true; } /* * Find old shlibs-provides */ xbps_dictionary_t oldshlibs = xbps_dictionary_create(); xbps_dictionary_t usedshlibs = xbps_dictionary_create(); iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t oldpkg = xbps_dictionary_get(idx, pkgname); xbps_array_t pkgshlibs = xbps_dictionary_get(oldpkg, "shlib-provides"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib = NULL; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_set_cstring(oldshlibs, shlib, pkgname); } } xbps_object_iterator_release(iter); /* * throw away all unused shlibs */ iter = xbps_dictionary_iterator(idx); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t pkg = xbps_dictionary_get(stage, pkgname); if(!pkg) pkg = xbps_dictionary_get_keysym(idx, keysym); xbps_array_t pkgshlibs = xbps_dictionary_get(pkg, "shlib-requires"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib = NULL, *user = NULL; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_get_cstring_nocopy(pkg, shlib, &user); if(!user) continue; xbps_array_t users = xbps_dictionary_get(usedshlibs, shlib); if(!users) { users = xbps_array_create(); xbps_dictionary_set(usedshlibs, shlib, users); } xbps_array_add_cstring(users, user); } } xbps_object_iterator_release(iter); /* * purge all packages that are fullfilled by the stage */ iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t newpkg = xbps_dictionary_get(idx, pkgname); xbps_array_t pkgshlibs = xbps_dictionary_get(newpkg, "shlib-provides"); for(unsigned int i = 0; i < xbps_array_count(pkgshlibs); i++) { const char *shlib; xbps_array_get_cstring_nocopy(pkgshlibs, i, &shlib); xbps_dictionary_remove(usedshlibs, shlib); } } xbps_object_iterator_release(iter); if(xbps_dictionary_count(usedshlibs) != 0) { puts("Unfullfilled shlibs:"); iter = xbps_dictionary_iterator(usedshlibs); while ((keysym = xbps_object_iterator_next(iter))) { const char *shlib = xbps_dictionary_keysym_cstring_nocopy(keysym), *provider = NULL; xbps_array_t users = xbps_dictionary_get(usedshlibs, shlib); xbps_dictionary_get_cstring_nocopy(usedshlibs, shlib, &provider); printf(" %s (provided by: %s; used by: ", shlib, provider); const char *pre = ""; for(unsigned int i = 0; i < xbps_array_count(users); i++) { const char *user; xbps_array_get_cstring_nocopy(users, i, &user); xbps_dictionary_remove(usedshlibs, shlib); printf("%s%s",pre, user); pre = ", "; } puts(")"); } puts("Changes are commit to stage."); xbps_object_iterator_release(iter); // TODO FLUSH STAGE rv = true; } else { iter = xbps_dictionary_iterator(stage); while ((keysym = xbps_object_iterator_next(iter))) { pkgname = xbps_dictionary_keysym_cstring_nocopy(keysym); xbps_dictionary_t newpkg = xbps_dictionary_get_keysym(stage, keysym); xbps_dictionary_set(idx, pkgname, newpkg); } xbps_object_iterator_release(iter); rv = repodata_flush(xhp, repodir, idx, meta); } xbps_object_release(usedshlibs); xbps_object_release(oldshlibs); return rv; }
int index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force) { xbps_dictionary_t idx, idxmeta, idxstage, binpkgd, curpkgd; struct xbps_repo *repo = NULL; struct stat st; char *tmprepodir = NULL, *repodir = NULL, *rlockfname = NULL; int rv = 0, ret = 0, rlockfd = -1; assert(argv); /* * Read the repository data or create index dictionaries otherwise. */ if ((tmprepodir = strdup(argv[args])) == NULL) return ENOMEM; repodir = dirname(tmprepodir); if (!xbps_repo_lock(xhp, repodir, &rlockfd, &rlockfname)) { fprintf(stderr, "xbps-rindex: cannot lock repository " "%s: %s\n", repodir, strerror(errno)); rv = -1; goto out; } repo = xbps_repo_public_open(xhp, repodir); if (repo == NULL && errno != ENOENT) { fprintf(stderr, "xbps-rindex: cannot open/lock repository " "%s: %s\n", repodir, strerror(errno)); rv = -1; goto out; } if (repo) { idx = xbps_dictionary_copy_mutable(repo->idx); idxmeta = xbps_dictionary_copy_mutable(repo->idxmeta); } else { idx = xbps_dictionary_create(); idxmeta = NULL; } // TODO: load data from stage repository idxstage = xbps_dictionary_create(); /* * Process all packages specified in argv. */ for (int i = args; i < argmax; i++) { const char *arch = NULL, *pkg = argv[i]; char *sha256 = NULL, *pkgver = NULL, *pkgname = NULL; assert(pkg); /* * Read metadata props plist dictionary from binary package. */ binpkgd = xbps_archive_fetch_plist(pkg, "/props.plist"); if (binpkgd == NULL) { fprintf(stderr, "index: failed to read %s metadata for " "`%s', skipping!\n", XBPS_PKGPROPS, pkg); continue; } xbps_dictionary_get_cstring_nocopy(binpkgd, "architecture", &arch); xbps_dictionary_get_cstring(binpkgd, "pkgver", &pkgver); if (!xbps_pkg_arch_match(xhp, arch, NULL)) { fprintf(stderr, "index: ignoring %s, unmatched arch (%s)\n", pkgver, arch); xbps_object_release(binpkgd); free(pkgver); continue; } pkgname = xbps_pkg_name(pkgver); assert(pkgname); /* * Check if this package exists already in the index, but first * checking the version. If current package version is greater * than current registered package, update the index; otherwise * pass to the next one. */ curpkgd = xbps_dictionary_get(idxstage, pkgname); if(curpkgd == NULL) curpkgd = xbps_dictionary_get(idx, pkgname); if (curpkgd == NULL) { if (errno && errno != ENOENT) { rv = errno; free(pkgver); free(pkgname); goto out; } } else if (!force) { char *opkgver = NULL, *oarch = NULL; /* Only check version if !force */ xbps_dictionary_get_cstring(curpkgd, "pkgver", &opkgver); xbps_dictionary_get_cstring(curpkgd, "architecture", &oarch); ret = xbps_cmpver(pkgver, opkgver); /* * If the considered package reverts the package in the index, * consider the current package as the newer one. */ if (ret < 0 && xbps_pkg_reverts(binpkgd, opkgver)) { ret = 1; /* * If package in the index reverts considered package, consider the * package in the index as the newer one. */ } else if (ret > 0 && xbps_pkg_reverts(curpkgd, pkgver)) { ret = -1; } if (ret <= 0) { /* Same version or index version greater */ fprintf(stderr, "index: skipping `%s' (%s), already registered.\n", pkgver, arch); xbps_object_release(binpkgd); free(opkgver); free(oarch); free(pkgver); free(pkgname); continue; } /* * Current package version is greater than * index version. */ printf("index: removed obsolete entry `%s' (%s).\n", opkgver, oarch); xbps_dictionary_remove(idx, pkgname); free(opkgver); free(oarch); } /* * Add additional objects for repository ops: * - filename-size * - filename-sha256 */ if ((sha256 = xbps_file_hash(pkg)) == NULL) { free(pkgver); free(pkgname); rv = EINVAL; goto out; } if (!xbps_dictionary_set_cstring(binpkgd, "filename-sha256", sha256)) { free(sha256); free(pkgver); free(pkgname); rv = EINVAL; goto out; } free(sha256); if (stat(pkg, &st) == -1) { free(pkgver); free(pkgname); rv = EINVAL; goto out; } if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) { free(pkgver); free(pkgname); rv = EINVAL; goto out; } if (set_build_date(binpkgd, st.st_mtime) < 0) { free(pkgver); free(pkgname); rv = EINVAL; goto out; } /* Remove unneeded objects */ xbps_dictionary_remove(binpkgd, "pkgname"); xbps_dictionary_remove(binpkgd, "version"); xbps_dictionary_remove(binpkgd, "packaged-with"); /* * Add new pkg dictionary into the index. */ if (!xbps_dictionary_set(idxstage, pkgname, binpkgd)) { free(pkgname); free(pkgver); rv = EINVAL; goto out; } printf("index: added `%s' (%s).\n", pkgver, arch); xbps_object_release(binpkgd); free(pkgname); free(pkgver); } /* * Generate repository data files. */ if (!repodata_commit(xhp, repodir, idx, idxmeta, idxstage)) { fprintf(stderr, "%s: failed to write repodata: %s\n", _XBPS_RINDEX, strerror(errno)); goto out; } printf("index: %u packages registered.\n", xbps_dictionary_count(idx)); out: if (repo) xbps_repo_close(repo); xbps_repo_unlock(rlockfd, rlockfname); if (tmprepodir) free(tmprepodir); return rv; }
int xbps_transaction_prepare(struct xbps_handle *xhp) { xbps_array_t array, pkgs, edges; unsigned int i, cnt; int rv = 0; if (xhp->transd == NULL) return ENXIO; /* * Collect dependencies for pkgs in transaction. */ if ((edges = xbps_array_create()) == NULL) return ENOMEM; /* * The edges are also appended after its dependencies have been * collected; the edges at the original array are removed later. */ pkgs = xbps_dictionary_get(xhp->transd, "packages"); assert(xbps_object_type(pkgs) == XBPS_TYPE_ARRAY); cnt = xbps_array_count(pkgs); for (i = 0; i < cnt; i++) { xbps_dictionary_t pkgd; xbps_string_t str; const char *tract = NULL; pkgd = xbps_array_get(pkgs, i); str = xbps_dictionary_get(pkgd, "pkgver"); xbps_dictionary_get_cstring_nocopy(pkgd, "transaction", &tract); if ((strcmp(tract, "remove") == 0) || strcmp(tract, "hold") == 0) continue; assert(xbps_object_type(str) == XBPS_TYPE_STRING); if (!xbps_array_add(edges, str)) return ENOMEM; if ((rv = xbps_repository_find_deps(xhp, pkgs, pkgd)) != 0) return rv; if (!xbps_array_add(pkgs, pkgd)) return ENOMEM; } /* ... remove dup edges at head */ for (i = 0; i < xbps_array_count(edges); i++) { const char *pkgver; xbps_array_get_cstring_nocopy(edges, i, &pkgver); xbps_remove_pkg_from_array_by_pkgver(pkgs, pkgver); } xbps_object_release(edges); /* * Check for packages to be replaced. */ if ((rv = xbps_transaction_package_replace(xhp, pkgs)) != 0) { xbps_object_release(xhp->transd); xhp->transd = NULL; return rv; } /* * If there are missing deps or revdeps bail out. */ xbps_transaction_revdeps(xhp, pkgs); array = xbps_dictionary_get(xhp->transd, "missing_deps"); if (xbps_array_count(array)) { if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) { xbps_dbg_printf(xhp, "[trans] continuing with broken reverse dependencies!"); } else { return ENODEV; } } /* * If there are package conflicts bail out. */ xbps_transaction_conflicts(xhp, pkgs); array = xbps_dictionary_get(xhp->transd, "conflicts"); if (xbps_array_count(array)) return EAGAIN; /* * Check for unresolved shared libraries. */ if (xbps_transaction_shlibs(xhp, pkgs, xbps_dictionary_get(xhp->transd, "missing_shlibs"))) { if (xhp->flags & XBPS_FLAG_FORCE_REMOVE_REVDEPS) { xbps_dbg_printf(xhp, "[trans] continuing with unresolved shared libraries!"); } else { return ENOEXEC; } } /* * 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(xhp)) != 0) { return rv; } /* * Remove now unneeded objects. */ xbps_dictionary_remove(xhp->transd, "missing_shlibs"); xbps_dictionary_remove(xhp->transd, "missing_deps"); xbps_dictionary_remove(xhp->transd, "conflicts"); xbps_dictionary_make_immutable(xhp->transd); return 0; }