static bool repo_open_local(struct xbps_repo *repo, const char *repofile) { struct stat st; int rv = 0; if (fstat(repo->fd, &st) == -1) { rv = errno; xbps_dbg_printf(repo->xhp, "[repo] `%s' fstat repodata %s\n", repofile, strerror(rv)); return false; } repo->ar = archive_read_new(); archive_read_support_compression_gzip(repo->ar); archive_read_support_format_tar(repo->ar); if (archive_read_open_fd(repo->ar, repo->fd, st.st_blksize) == ARCHIVE_FATAL) { rv = archive_errno(repo->ar); xbps_dbg_printf(repo->xhp, "[repo] `%s' failed to open repodata archive %s\n", repofile, strerror(rv)); return false; } if ((repo->idx = repo_get_dict(repo)) == NULL) { rv = archive_errno(repo->ar); xbps_dbg_printf(repo->xhp, "[repo] `%s' failed to internalize " " index on archive, removing file.\n", repofile); /* broken archive, remove it */ (void)unlink(repofile); return false; } xbps_dictionary_make_immutable(repo->idx); repo->idxmeta = repo_get_dict(repo); if (repo->idxmeta != NULL) { repo->is_signed = true; xbps_dictionary_make_immutable(repo->idxmeta); } return true; }
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; }
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; }