diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index d5693fa03..53eabae7d 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -236,18 +236,19 @@ process_one_alternative(const char *altgrname, const char *val) xbps_dictionary_t d; xbps_array_t a; const char *altfiles; - bool alloc = false; + bool alloc_dict = false, alloc_array = false; if ((d = xbps_dictionary_get(pkg_propsd, "alternatives")) == NULL) { d = xbps_dictionary_create(); if (d == NULL) die("xbps_dictionary_create"); - alloc = true; + alloc_dict = true; } if ((a = xbps_dictionary_get(d, altgrname)) == NULL) { a = xbps_array_create(); if (a == NULL) die("xbps_array_create"); + alloc_array = true; } altfiles = strchr(val, ':') + 1; assert(altfiles); @@ -256,10 +257,10 @@ process_one_alternative(const char *altgrname, const char *val) xbps_dictionary_set(d, altgrname, a); xbps_dictionary_set(pkg_propsd, "alternatives", d); - if (alloc) { + if (alloc_array) xbps_object_release(a); + if (alloc_dict) xbps_object_release(d); - } } @@ -835,14 +836,13 @@ process_archive(struct archive *ar, /* Add all package data files and release resources */ while ((xe = TAILQ_FIRST(&xentry_list)) != NULL) { TAILQ_REMOVE(&xentry_list, xe, entries); - if (xe->type == ENTRY_TYPE_METADATA || xe->type == ENTRY_TYPE_DIRS) - continue; - - if (!quiet) { - printf("%s: adding `%s' ...\n", pkgver, xe->file); - fflush(stdout); + if (xe->type != ENTRY_TYPE_METADATA && xe->type != ENTRY_TYPE_DIRS) { + if (!quiet) { + printf("%s: adding `%s' ...\n", pkgver, xe->file); + fflush(stdout); + } + process_entry_file(ar, resolver, xe, NULL); } - process_entry_file(ar, resolver, xe, NULL); free(xe->file); free(xe->target); free(xe); diff --git a/bin/xbps-fbulk/main.c b/bin/xbps-fbulk/main.c index 249869d84..4a620d2dd 100644 --- a/bin/xbps-fbulk/main.c +++ b/bin/xbps-fbulk/main.c @@ -232,6 +232,12 @@ processCompletion(struct item *item) logpath = xbps_xasprintf("%s/deps/%s.txt", LogDir, xitem->pkgn); fp = fopen(logpath, "a"); + if (!fp) { + xbps_error_printf( + "failed to open file: %s: %s\n", + logpath, strerror(errno)); + exit(EXIT_FAILURE); + } fprintf(fp, "%s\n", item->pkgn); fclose(fp); free(logpath); @@ -369,7 +375,13 @@ runBuilds(const char *bpath) */ item->xcode = -98; fp = fopen(logpath, "a"); - xbps_error_printf("xbps-fbulk: unable to fork/exec xbps-src\n"); + if (!fp) { + xbps_error_printf( + "failed to open file: %s: %s\n", + logpath, strerror(errno)); + exit(EXIT_FAILURE); + } + fprintf(fp, "xbps-fbulk: unable to fork/exec xbps-src\n"); fclose(fp); processCompletion(item); } else { @@ -426,6 +438,12 @@ addDepn(struct item *item, struct item *xitem) logpath = xbps_xasprintf("%s/deps/%s.txt", LogDir, item->pkgn); fp = fopen(logpath, "a"); + if (!fp) { + xbps_error_printf( + "failed to open file: %s: %s\n", logpath, + strerror(errno)); + exit(EXIT_FAILURE); + } fprintf(fp, "%s\n", xitem->pkgn); fclose(fp); free(logpath); @@ -461,6 +479,10 @@ ordered_depends(const char *bpath, const char *pkgn) snprintf(cmd, sizeof(cmd)-1, "%s/xbps-src show-build-deps %s 2>&1", bpath, pkgn); fp = popen(cmd, "r"); + if (!fp) { + xbps_error_printf("faile to run xbps-src show-build-deps\n"); + exit(EXIT_FAILURE); + } while (fgets(buf, sizeof(buf), fp) != NULL) { char dpath[PATH_MAX]; size_t len; diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index 8f8be8160..ad2653bbc 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -122,59 +122,54 @@ main(int argc, char **argv) { "staging", no_argument, NULL, 2 }, { NULL, 0, NULL, 0 } }; - struct xbps_handle xh; + struct xbps_handle xh = {0}; struct xferstat xfer; - const char *rootdir, *cachedir, *confdir; - int i, c, flags, rv, fflag = 0; + int i, c, rv, fflag = 0; bool syncf, yes, force, drun, update; int maxcols, eexist = 0; - rootdir = cachedir = confdir = NULL; - flags = rv = 0; syncf = yes = force = drun = update = false; - memset(&xh, 0, sizeof(xh)); - while ((c = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (c) { case 1: - flags |= XBPS_FLAG_INSTALL_REPRO; + xh.flags |= XBPS_FLAG_INSTALL_REPRO; break; case 2: - flags |= XBPS_FLAG_USE_STAGE; + xh.flags |= XBPS_FLAG_USE_STAGE; break; case 'A': - flags |= XBPS_FLAG_INSTALL_AUTO; + xh.flags |= XBPS_FLAG_INSTALL_AUTO; break; case 'C': - confdir = optarg; + xbps_strlcpy(xh.confdir, optarg, sizeof(xh.confdir)); break; case 'c': - cachedir = optarg; + xbps_strlcpy(xh.cachedir, optarg, sizeof(xh.cachedir)); break; case 'd': - flags |= XBPS_FLAG_DEBUG; + xh.flags |= XBPS_FLAG_DEBUG; break; case 'D': - flags |= XBPS_FLAG_DOWNLOAD_ONLY; + xh.flags |= XBPS_FLAG_DOWNLOAD_ONLY; break; case 'f': fflag++; if (fflag > 1) - flags |= XBPS_FLAG_FORCE_UNPACK; + xh.flags |= XBPS_FLAG_FORCE_UNPACK; force = true; break; case 'h': usage(false); /* NOTREACHED */ case 'I': - flags |= XBPS_FLAG_IGNORE_FILE_CONFLICTS; + xh.flags |= XBPS_FLAG_IGNORE_FILE_CONFLICTS; break; case 'i': - flags |= XBPS_FLAG_IGNORE_CONF_REPOS; + xh.flags |= XBPS_FLAG_IGNORE_CONF_REPOS; break; case 'M': - flags |= XBPS_FLAG_REPOS_MEMSYNC; + xh.flags |= XBPS_FLAG_REPOS_MEMSYNC; break; case 'n': drun = true; @@ -183,19 +178,19 @@ main(int argc, char **argv) xbps_repo_store(&xh, optarg); break; case 'r': - rootdir = optarg; + xbps_strlcpy(xh.rootdir, optarg, sizeof(xh.rootdir)); break; case 'S': syncf = true; break; case 'U': - flags |= XBPS_FLAG_UNPACK_ONLY; + xh.flags |= XBPS_FLAG_UNPACK_ONLY; break; case 'u': update = true; break; case 'v': - flags |= XBPS_FLAG_VERBOSE; + xh.flags |= XBPS_FLAG_VERBOSE; break; case 'V': printf("%s\n", XBPS_RELVER); @@ -218,14 +213,7 @@ main(int argc, char **argv) xh.state_cb = state_cb; xh.fetch_cb = fetch_file_progress_cb; xh.fetch_cb_data = &xfer; - if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); - if (cachedir) - xbps_strlcpy(xh.cachedir, cachedir, sizeof(xh.cachedir)); - if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); - xh.flags = flags; - if (flags & XBPS_FLAG_VERBOSE) + if (xh.flags & XBPS_FLAG_VERBOSE) xh.unpack_cb = unpack_progress_cb; if ((rv = xbps_init(&xh)) != 0) { diff --git a/bin/xbps-install/transaction.c b/bin/xbps-install/transaction.c index 9eb975f48..e82d53ff0 100644 --- a/bin/xbps-install/transaction.c +++ b/bin/xbps-install/transaction.c @@ -132,47 +132,50 @@ show_dry_run_actions(struct transaction *trans) } static void -show_package_list(struct transaction *trans, xbps_trans_type_t ttype, unsigned int cols) +show_package_list(struct transaction *trans, xbps_trans_type_t list_type, unsigned int cols) { - xbps_dictionary_t ipkgd; + char buf[1024]; xbps_object_t obj; - xbps_trans_type_t tt; - const char *pkgver, *pkgname, *ipkgver, *version, *iversion; - char *buf = NULL; while ((obj = xbps_object_iterator_next(trans->iter)) != NULL) { + xbps_trans_type_t tt; + const char *pkgver = NULL, *pkgname = NULL; bool dload = false; - pkgver = ipkgver = version = iversion = NULL; xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); xbps_dictionary_get_bool(obj, "download", &dload); - if (ttype == XBPS_TRANS_DOWNLOAD && dload) { + if (list_type == XBPS_TRANS_DOWNLOAD && dload) { tt = XBPS_TRANS_DOWNLOAD; } else { tt = xbps_transaction_pkg_type(obj); - if (ttype == XBPS_TRANS_INSTALL && tt == XBPS_TRANS_REINSTALL) { + if (list_type == XBPS_TRANS_INSTALL && tt == XBPS_TRANS_REINSTALL) { tt = XBPS_TRANS_INSTALL; } } - buf = NULL; + if (tt != list_type) + continue; + if (tt == XBPS_TRANS_UPDATE) { - /* get installed pkgver */ + xbps_dictionary_t ipkgd; + const char *version = NULL, *iversion = NULL, *ipkgver = NULL; + int l; + ipkgd = xbps_pkgdb_get_pkg(trans->xhp, pkgname); - assert(ipkgd); - xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver); + if (!ipkgd) + xbps_unreachable(); + if (!xbps_dictionary_get_cstring_nocopy(ipkgd, "pkgver", &ipkgver)) + xbps_unreachable(); version = xbps_pkg_version(pkgver); iversion = xbps_pkg_version(ipkgver); - buf = xbps_xasprintf("%s (%s -> %s)", pkgname, iversion, version); - } - if (ttype == tt) { - if (buf) { - print_package_line(buf, cols, false); - free(buf); - } else { - print_package_line(pkgver, cols, false); - } + l = snprintf(buf, sizeof(buf), "%s (%s -> %s)", pkgname, + iversion, version); + if (l < 0 || (size_t)l >= sizeof(buf)) + xbps_unreachable(); + print_package_line(buf, cols, false); + } else { + print_package_line(pkgver, cols, false); } } xbps_object_iterator_reset(trans->iter); diff --git a/bin/xbps-query/ownedby.c b/bin/xbps-query/ownedby.c index baa82c3b4..1121582e4 100644 --- a/bin/xbps-query/ownedby.c +++ b/bin/xbps-query/ownedby.c @@ -146,14 +146,17 @@ repo_match_cb(struct xbps_handle *xhp, r = xbps_pkg_path_or_url(xhp, bfile, sizeof(bfile), obj); if (r < 0) { - xbps_error_printf("could not get package path: %s\n", strerror(-r)); - return -r; + return xbps_error_errno( + r, "could not get package path: %s\n", strerror(-r)); } + errno = 0; filesd = xbps_archive_fetch_plist(bfile, "/files.plist"); if (!filesd) { - xbps_error_printf("%s: couldn't fetch files.plist from %s: %s\n", - pkgver, bfile, strerror(errno)); - return EINVAL; + if (errno == 0) + errno = EINVAL; + return xbps_error_errno(errno, + "%s: couldn't fetch files.plist from %s: %s\n", pkgver, + bfile, strerror(errno)); } files_keys = xbps_dictionary_all_keys(filesd); for (unsigned int i = 0; i < xbps_array_count(files_keys); i++) { @@ -175,7 +178,7 @@ repo_ownedby_cb(struct xbps_repo *repo, void *arg, bool *done UNUSED) ffd->repouri = repo->uri; allkeys = xbps_dictionary_all_keys(repo->idx); - rv = xbps_array_foreach_cb_multi(repo->xhp, allkeys, repo->idx, repo_match_cb, ffd); + rv = -xbps_array_foreach_cb_multi(repo->xhp, allkeys, repo->idx, repo_match_cb, ffd); xbps_object_release(allkeys); return rv; diff --git a/bin/xbps-query/search.c b/bin/xbps-query/search.c index 0ea4cd558..934370c57 100644 --- a/bin/xbps-query/search.c +++ b/bin/xbps-query/search.c @@ -96,8 +96,8 @@ search_cb(struct xbps_handle *xhp UNUSED, xbps_object_t pkgd, abort(); if (!xbps_dictionary_get_cstring_nocopy(pkgd, "short_desc", &desc)) { - xbps_error_printf("%s: missing short_desc property\n", pkgver); - return -EINVAL; + return xbps_error_errno( + EINVAL, "%s: missing short_desc property\n", pkgver); } if (ctx->repo_mode && xbps_match_virtual_pkg_in_dict(pkgd, ctx->pattern)) diff --git a/bin/xbps-query/show-deps.c b/bin/xbps-query/show-deps.c index db7b4b27f..71ee0c6b1 100644 --- a/bin/xbps-query/show-deps.c +++ b/bin/xbps-query/show-deps.c @@ -63,6 +63,7 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname, bool repomode, bool xbps_array_get_cstring_nocopy(rdeps, i, &pkgdep); puts(pkgdep); } + xbps_object_release(rdeps); return 0; } diff --git a/bin/xbps-query/show-info-files.c b/bin/xbps-query/show-info-files.c index 24799badc..edf58e776 100644 --- a/bin/xbps-query/show-info-files.c +++ b/bin/xbps-query/show-info-files.c @@ -251,15 +251,15 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp, int show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkg) { - xbps_dictionary_t d; + xbps_dictionary_t filesd; int rv = 0; - d = xbps_pkgdb_get_pkg_files(xhp, pkg); - if (d == NULL) + filesd = xbps_pkgdb_get_pkg_files(xhp, pkg); + if (filesd == NULL) return ENOENT; - rv = show_pkg_files(d); - + rv = show_pkg_files(filesd); + xbps_object_release(filesd); return rv; } @@ -341,7 +341,7 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg) filesd = xbps_archive_fetch_plist(bfile, "/files.plist"); if (filesd == NULL) { - if (errno != ENOTSUP && errno != ENOENT) { + if (errno != ENOTSUP && errno != ENOENT) { xbps_error_printf("Unexpected error: %s\n", strerror(errno)); } return errno; diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 727053b56..3fa168c42 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -274,7 +274,6 @@ index_add_pkg(struct xbps_handle *xhp, xbps_dictionary_t index, xbps_dictionary_ if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) goto err_errno; - xbps_dictionary_remove(binpkgd, "pkgname"); xbps_dictionary_remove(binpkgd, "version"); xbps_dictionary_remove(binpkgd, "packaged-with"); diff --git a/bin/xbps-rindex/repoflush.c b/bin/xbps-rindex/repoflush.c index 3bdd474c6..fda4b73bf 100644 --- a/bin/xbps-rindex/repoflush.c +++ b/bin/xbps-rindex/repoflush.c @@ -110,12 +110,10 @@ archive_dict(struct archive *ar, const char *filename, xbps_dictionary_t dict) errno = 0; buf = xbps_dictionary_externalize(dict); if (!buf) { - r = -errno; - xbps_error_printf("failed to externalize dictionary for: %s\n", - filename); - if (r == 0) - return -EINVAL; - return 0; + if (errno == 0) + errno = EINVAL; + return xbps_error_errno(errno, + "failed to externalize dictionary for: %s\n", filename); } r = xbps_archive_append_buf(ar, buf, strlen(buf), filename, 0644, @@ -147,23 +145,23 @@ repodata_flush(const char *repodir, r = snprintf(path, sizeof(path), "%s/%s-repodata", repodir, arch); if (r < 0 || (size_t)r >= sizeof(tmp)) { - xbps_error_printf("repodata path too long: %s: %s\n", path, + return xbps_error_errno(ENAMETOOLONG, + "repodata path too long: %s: %s\n", path, strerror(ENAMETOOLONG)); - return -ENAMETOOLONG; } r = snprintf(tmp, sizeof(tmp), "%s.XXXXXXX", path); if (r < 0 || (size_t)r >= sizeof(tmp)) { - xbps_error_printf("repodata tmp path too long: %s: %s\n", path, + return xbps_error_errno(ENAMETOOLONG, + "repodata tmp path too long: %s: %s\n", path, strerror(ENAMETOOLONG)); - return -ENAMETOOLONG; } prevumask = umask(S_IXUSR|S_IRWXG|S_IRWXO); fd = mkstemp(tmp); if (fd == -1) { - r = -errno; - xbps_error_printf("failed to open temp file: %s: %s", tmp, strerror(-r)); + r = xbps_error_errno(errno, "failed to open temp file: %s: %s", + tmp, strerror(-r)); umask(prevumask); goto err; } @@ -194,8 +192,7 @@ repodata_flush(const char *repodir, goto err; } if (archive_write_free(ar) == ARCHIVE_FATAL) { - r = -errno; - xbps_error_printf("failed to free archive: %s\n", strerror(-r)); + r = xbps_error_errno(errno, "failed to free archive: %s\n", strerror(errno)); goto err; } @@ -206,9 +203,8 @@ repodata_flush(const char *repodir, #endif if (fchmod(fd, 0664) == -1) { - errno = -r; - xbps_error_printf("failed to set mode: %s: %s\n", - tmp, strerror(-r)); + r = xbps_error_errno(errno, "failed to set mode: %s: %s\n", tmp, + strerror(errno)); close(fd); unlink(tmp); return r; @@ -216,9 +212,9 @@ repodata_flush(const char *repodir, close(fd); if (rename(tmp, path) == -1) { - r = -errno; - xbps_error_printf("failed to rename repodata: %s: %s: %s\n", - tmp, path, strerror(-r)); + r = xbps_error_errno(errno, + "failed to rename repodata: %s: %s: %s\n", tmp, path, + strerror(errno)); unlink(tmp); return r; } diff --git a/bin/xbps-rindex/sign.c b/bin/xbps-rindex/sign.c index 4acb203ba..b52d1d9af 100644 --- a/bin/xbps-rindex/sign.c +++ b/bin/xbps-rindex/sign.c @@ -168,14 +168,14 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, */ repo = xbps_repo_open(xhp, repodir); if (repo == NULL) { - r = -errno; - xbps_error_printf("%s: cannot read repository data: %s\n", - _XBPS_RINDEX, strerror(errno)); + r = xbps_error_errno(errno, + "%s: cannot read repository data: %s\n", _XBPS_RINDEX, + strerror(errno)); goto out; } if (xbps_dictionary_count(repo->idx) == 0) { - r = -EINVAL; - xbps_error_printf("%s: invalid repository, exiting!\n", _XBPS_RINDEX); + r = xbps_error_errno( + EINVAL, "%s: invalid repository, exiting!\n", _XBPS_RINDEX); goto out; } @@ -193,11 +193,15 @@ sign_repo(struct xbps_handle *xhp, const char *repodir, meta = xbps_dictionary_create(); if (!meta) { - r = -ENOMEM; + r = xbps_error_oom(); goto out; } data = xbps_data_create_data(buf, strlen(buf)); + if (!data) { + r = xbps_error_oom(); + goto out; + } rpubkey = xbps_dictionary_get(repo->idxmeta, "public-key"); if (!xbps_data_equals(rpubkey, data)) flush = true; diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 174488671..39749130b 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -29,12 +29,12 @@ #include #include #include -#include #include #include #include #include + #include "../xbps-install/defs.h" static void __attribute__((noreturn)) @@ -88,11 +88,11 @@ int main(int argc, char **argv) { xbps_dictionary_t dict; - struct xbps_handle xh; + struct xbps_handle xh = {0}; struct xferstat xfer; - const char *version, *rootdir = NULL, *confdir = NULL; + const char *version; char pkgname[XBPS_NAME_SIZE], *filename; - int flags = 0, c, rv = 0, i = 0; + int c, rv = 0, i = 0; const struct option longopts[] = { { "config", required_argument, NULL, 'C' }, { "debug", no_argument, NULL, 'd' }, @@ -108,17 +108,17 @@ main(int argc, char **argv) usage(false); /* NOTREACHED */ case 'C': - confdir = optarg; + xbps_strlcpy(xh.confdir, optarg, sizeof(xh.confdir)); break; case 'r': /* To specify the root directory */ - rootdir = optarg; + xbps_strlcpy(xh.rootdir, optarg, sizeof(xh.rootdir)); break; case 'd': - flags |= XBPS_FLAG_DEBUG; + xh.flags |= XBPS_FLAG_DEBUG; break; case 'v': - flags |= XBPS_FLAG_VERBOSE; + xh.flags |= XBPS_FLAG_VERBOSE; break; case 'V': printf("%s\n", XBPS_RELVER); @@ -139,8 +139,6 @@ main(int argc, char **argv) /* NOTREACHED */ } - memset(&xh, 0, sizeof(xh)); - if ((strcmp(argv[0], "version") == 0) || (strcmp(argv[0], "real-version") == 0) || (strcmp(argv[0], "arch") == 0) || @@ -151,11 +149,6 @@ main(int argc, char **argv) */ xh.fetch_cb = fetch_file_progress_cb; xh.fetch_cb_data = &xfer; - xh.flags = flags; - if (rootdir) - xbps_strlcpy(xh.rootdir, rootdir, sizeof(xh.rootdir)); - if (confdir) - xbps_strlcpy(xh.confdir, confdir, sizeof(xh.confdir)); if ((rv = xbps_init(&xh)) != 0) { xbps_error_printf("xbps-uhelper: failed to " "initialize libxbps: %s.\n", strerror(rv)); @@ -176,8 +169,10 @@ main(int argc, char **argv) xbps_error_printf("Could not find package '%s'\n", argv[i]); rv = 1; } else { - xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &version); - printf("%s\n", xbps_pkg_version(version)); + const char *pkgver = NULL; + if (!xbps_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver)) + xbps_unreachable(); + printf("%s\n", xbps_pkg_version(pkgver)); } } } else if (strcmp(argv[0], "real-version") == 0) { @@ -356,13 +351,13 @@ main(int argc, char **argv) } rv = xbps_pkgpattern_match(argv[1], argv[2]); if (rv >= 0) { - if (flags & XBPS_FLAG_VERBOSE) { + if (xh.flags & XBPS_FLAG_VERBOSE) { fprintf(stderr, "%s %s %s\n", argv[1], (rv == 1) ? "matches" : "does not match", argv[2]); } - } else if (flags & XBPS_FLAG_VERBOSE) { + } else if (xh.flags & XBPS_FLAG_VERBOSE) { xbps_error_printf("%s: not a pattern\n", argv[2]); } exit(rv); @@ -374,7 +369,7 @@ main(int argc, char **argv) } rv = xbps_cmpver(argv[1], argv[2]); - if (flags & XBPS_FLAG_VERBOSE) { + if (xh.flags & XBPS_FLAG_VERBOSE) { fprintf(stderr, "%s %s %s\n", argv[1], (rv == 1) ? ">" : ((rv == 0) ? "=" : "<"), diff --git a/include/xbps.h.in b/include/xbps.h.in index 6a35eebbd..a8c5dce48 100644 --- a/include/xbps.h.in +++ b/include/xbps.h.in @@ -1419,19 +1419,6 @@ typedef enum xbps_trans_type { */ xbps_trans_type_t xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod); -/** - * Sets the transaction type associated with \a pkg_repod. - * - * See \a xbps_trans_type_t for possible values. - * - * @param[in] pkg_repod Package dictionary stored in a repository. - * @param[in] type The transaction type to set. - * - * @return Returns true on success, false otherwise. - */ - -bool xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t type); - /**@}*/ /** @addtogroup plist_fetch */ diff --git a/include/xbps_api_impl.h b/include/xbps_api_impl.h index 11aba1585..acbb648b5 100644 --- a/include/xbps_api_impl.h +++ b/include/xbps_api_impl.h @@ -62,10 +62,6 @@ int HIDDEN dewey_match(const char *, const char *); int HIDDEN xbps_pkgdb_init(struct xbps_handle *); void HIDDEN xbps_pkgdb_release(struct xbps_handle *); int HIDDEN xbps_pkgdb_conversion(struct xbps_handle *); -int HIDDEN xbps_array_replace_dict_by_name(xbps_array_t, xbps_dictionary_t, - const char *); -int HIDDEN xbps_array_replace_dict_by_pattern(xbps_array_t, xbps_dictionary_t, - const char *); bool HIDDEN xbps_remove_pkg_from_array_by_name(xbps_array_t, const char *); bool HIDDEN xbps_remove_pkg_from_array_by_pattern(xbps_array_t, const char *); bool HIDDEN xbps_remove_pkg_from_array_by_pkgver(xbps_array_t, const char *); @@ -88,9 +84,13 @@ xbps_dictionary_t HIDDEN xbps_find_virtualpkg_in_array(struct xbps_handle *, /* transaction */ bool HIDDEN xbps_transaction_check_revdeps(struct xbps_handle *, xbps_array_t); bool HIDDEN xbps_transaction_check_shlibs(struct xbps_handle *, xbps_array_t); -bool HIDDEN xbps_transaction_check_replaces(struct xbps_handle *, xbps_array_t); +int HIDDEN transaction_check_replaces( + struct xbps_handle *xhp, xbps_array_t trans_pkgs); int HIDDEN xbps_transaction_check_conflicts(struct xbps_handle *, xbps_array_t); -bool HIDDEN xbps_transaction_store(struct xbps_handle *, xbps_array_t, xbps_dictionary_t, bool); +int HIDDEN transaction_store(struct xbps_handle *xhp, xbps_dictionary_t pkgrd, + xbps_trans_type_t ttype, bool autoinstall, bool replace); +int HIDDEN transaction_package_set_action(xbps_dictionary_t pkgd, + xbps_trans_type_t ttype); int HIDDEN xbps_transaction_init(struct xbps_handle *); int HIDDEN xbps_transaction_files(struct xbps_handle *, xbps_object_iterator_t); diff --git a/lib/archive.c b/lib/archive.c index 6fe574bcd..70b0d5763 100644 --- a/lib/archive.c +++ b/lib/archive.c @@ -58,7 +58,6 @@ xbps_archive_get_file(struct archive *ar, struct archive_entry *entry) buf = malloc(len + 1); if (!buf) { xbps_error_oom(); - errno = ENOMEM; return NULL; } @@ -246,9 +245,8 @@ xbps_archive_read_open_remote(struct archive *ar, const char *url) f = calloc(1, sizeof(*f)); if (!f) { - r = -errno; fetchFreeURL(furl); - return r; + return xbps_error_oom(); } f->url = furl; diff --git a/lib/conf.c b/lib/conf.c index 4ac1dab9d..19da83acd 100644 --- a/lib/conf.c +++ b/lib/conf.c @@ -124,35 +124,45 @@ store_virtualpkg(struct xbps_handle *xhp, const char *path, size_t line, char *v return 0; } -static void +static int store_preserved_file(struct xbps_handle *xhp, const char *file) { + char path[PATH_MAX]; glob_t globbuf; - char *p = NULL, *rfile = NULL; + char *p = NULL; size_t len; - int rv = 0; + int r; - if (xhp->preserved_files == NULL) { + if (!xhp->preserved_files) { xhp->preserved_files = xbps_array_create(); - assert(xhp->preserved_files); + if (!xhp->preserved_files) + return xbps_error_oom(); } - rfile = xbps_xasprintf("%s%s", xhp->rootdir, file); + if (xbps_path_join(path, sizeof(path), xhp->rootdir, file, (char *)NULL) == -1) + return -errno; - rv = glob(rfile, 0, NULL, &globbuf); - if (rv == GLOB_NOMATCH) { + r = glob(path, 0, NULL, &globbuf); + if (r == GLOB_NOMATCH) { if (xbps_match_string_in_array(xhp->preserved_files, file)) goto out; xbps_array_add_cstring(xhp->preserved_files, file); xbps_dbg_printf("Added preserved file: %s\n", file); + r = 0; + goto out; + } else if (r == GLOB_NOSPACE) { + r = xbps_error_oom(); goto out; - } else if (rv != 0) { + } else if (r != 0) { + r = xbps_error_errno(errno, "glob failed: %s\n", strerror(errno)); goto out; } + r = 0; for (size_t i = 0; i < globbuf.gl_pathc; i++) { if (xbps_match_string_in_array(xhp->preserved_files, globbuf.gl_pathv[i])) continue; + // XXX: clean this up len = strlen(globbuf.gl_pathv[i]) - strlen(xhp->rootdir) + 1; p = malloc(len); assert(p); @@ -163,7 +173,7 @@ store_preserved_file(struct xbps_handle *xhp, const char *file) } out: globfree(&globbuf); - free(rfile); + return r; } static bool @@ -175,28 +185,34 @@ store_repo(struct xbps_handle *xhp, const char *repo) return xbps_repo_store(xhp, repo); } -static void +static int store_ignored_pkg(struct xbps_handle *xhp, const char *pkgname) { - if (xhp->ignored_pkgs == NULL) { + if (!xhp->ignored_pkgs) { xhp->ignored_pkgs = xbps_array_create(); - assert(xhp->ignored_pkgs); + if (!xhp->ignored_pkgs) + return xbps_error_oom(); } - xbps_array_add_cstring(xhp->ignored_pkgs, pkgname); + if (!xbps_array_add_cstring(xhp->ignored_pkgs, pkgname)) + return xbps_error_oom(); xbps_dbg_printf("Added ignored package: %s\n", pkgname); + return 0; } -static void +static int store_noextract(struct xbps_handle *xhp, const char *value) { if (*value == '\0') - return; - if (xhp->noextract == NULL) { + return 0; + if (!xhp->noextract) { xhp->noextract = xbps_array_create(); - assert(xhp->noextract); + if (!xhp->noextract) + return xbps_error_oom(); } - xbps_array_add_cstring(xhp->noextract, value); + if (!xbps_array_add_cstring(xhp->noextract, value)) + return xbps_error_oom(); xbps_dbg_printf("Added noextract pattern: %s\n", value); + return 0; } enum { @@ -291,20 +307,23 @@ static int parse_files_glob(struct xbps_handle *xhp, xbps_dictionary_t seen, const char *cwd, const char *pat, bool nested) { - char tmppath[PATH_MAX]; + char path[PATH_MAX]; glob_t globbuf; - int rs, rv = 0, rv2; - - rs = snprintf(tmppath, PATH_MAX, "%s/%s", - pat[0] == '/' ? xhp->rootdir : cwd, pat); - if (rs < 0 || rs >= PATH_MAX) - return ENOMEM; - - switch (glob(tmppath, 0, NULL, &globbuf)) { - case 0: break; - case GLOB_NOSPACE: return ENOMEM; - case GLOB_NOMATCH: return 0; - default: return 0; + int r = 0; + + if (xbps_path_join(path, sizeof(path), + pat[0] == '/' ? xhp->rootdir : cwd, pat, (char *)NULL) == -1) + return -ENAMETOOLONG; + + switch (glob(path, 0, NULL, &globbuf)) { + case 0: + break; + case GLOB_NOSPACE: + r = xbps_error_oom(); + goto out; + case GLOB_NOMATCH: + default: + goto out; } for (size_t i = 0; i < globbuf.gl_pathc; i++) { if (seen != NULL) { @@ -313,14 +332,28 @@ parse_files_glob(struct xbps_handle *xhp, xbps_dictionary_t seen, fname = basename(globbuf.gl_pathv[i]); if (xbps_dictionary_get_bool(seen, fname, &mask) && mask) continue; - xbps_dictionary_set_bool(seen, fname, true); + if (!xbps_dictionary_set_bool(seen, fname, true)) { + r = xbps_error_oom(); + goto out; + } } - if ((rv2 = parse_file(xhp, globbuf.gl_pathv[i], nested)) != 0) - rv = rv2; + r = parse_file(xhp, globbuf.gl_pathv[i], nested); + if (r < 0) + goto out; } + r = 0; +out: globfree(&globbuf); + return r; +} - return rv; +static int +store_string(char *dst, size_t dstsz, const char *src) +{ + size_t n = strlcpy(dst, src, dstsz); + if (n >= dstsz) + return -ENOBUFS; + return 0; } static int @@ -330,14 +363,14 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) size_t len, nlines = 0; ssize_t rd; char *linebuf = NULL; - int rv = 0; - int size, rs; + int r = 0; char *dir; - if ((fp = fopen(path, "r")) == NULL) { - rv = errno; - xbps_error_printf("cannot read configuration file %s: %s\n", path, strerror(rv)); - return rv; + fp = fopen(path, "r"); + if (!fp) { + return xbps_error_errno(errno, + "cannot read configuration file %s: %s\n", path, + strerror(errno)); } xbps_dbg_printf("Parsing configuration file: %s\n", path); @@ -367,30 +400,21 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) "line %zu\n", path, nlines); continue; case KEY_ROOTDIR: - size = sizeof xhp->rootdir; - rs = snprintf(xhp->rootdir, size, "%s", val); - if (rs < 0 || rs >= size) { - rv = ENOMEM; + r = store_string(xhp->rootdir, sizeof(xhp->rootdir), val); + if (r < 0) break; - } xbps_dbg_printf("%s: rootdir set to %s\n", path, val); break; case KEY_CACHEDIR: - size = sizeof xhp->cachedir; - rs = snprintf(xhp->cachedir, size, "%s", val); - if (rs < 0 || rs >= size) { - rv = ENOMEM; + r = store_string(xhp->cachedir, sizeof(xhp->cachedir), val); + if (r < 0) break; - } xbps_dbg_printf("%s: cachedir set to %s\n", path, val); break; case KEY_ARCHITECTURE: - size = sizeof xhp->native_arch; - rs = snprintf(xhp->native_arch, size, "%s", val); - if (rs < 0 || rs >= size) { - rv = ENOMEM; + r = store_string(xhp->native_arch, sizeof(xhp->native_arch), val); + if (r < 0) break; - } xbps_dbg_printf("%s: native architecture set to %s\n", path, val); break; @@ -417,15 +441,10 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) xbps_dbg_printf("%s: added repository %s\n", path, val); break; case KEY_VIRTUALPKG: - rv = store_virtualpkg(xhp, path, nlines, val); - if (rv < 0) { - rv = -rv; - break; - } - rv = 0; + r = store_virtualpkg(xhp, path, nlines, val); break; case KEY_PRESERVE: - store_preserved_file(xhp, val); + r = store_preserved_file(xhp, val); break; case KEY_KEEPCONF: if (strcasecmp(val, "true") == 0) { @@ -446,10 +465,10 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) } break; case KEY_IGNOREPKG: - store_ignored_pkg(xhp, val); + r = store_ignored_pkg(xhp, val); break; case KEY_NOEXTRACT: - store_noextract(xhp, val); + r = store_noextract(xhp, val); break; case KEY_INCLUDE: /* Avoid double-nested parsing, only allow it once */ @@ -458,7 +477,7 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) continue; } dir = strdup(path); - rv = parse_files_glob(xhp, NULL, dirname(dir), val, true); + r = parse_files_glob(xhp, NULL, dirname(dir), val, true); free(dir); break; } @@ -466,31 +485,36 @@ parse_file(struct xbps_handle *xhp, const char *path, bool nested) free(linebuf); fclose(fp); - return rv; + return r; } int HIDDEN xbps_conf_init(struct xbps_handle *xhp) { xbps_dictionary_t seen; - int rv = 0; + int r = 0; assert(xhp); + seen = xbps_dictionary_create(); - assert(seen); + if (!seen) + return xbps_error_oom(); - if (*xhp->confdir) { + if (xhp->confdir[0]) { xbps_dbg_printf("Processing configuration directory: %s\n", xhp->confdir); - if ((rv = parse_files_glob(xhp, seen, xhp->confdir, "*.conf", false))) + r = parse_files_glob(xhp, seen, xhp->confdir, "*.conf", false); + if (r < 0) goto out; } - if (*xhp->sysconfdir) { + if (xhp->sysconfdir[0]) { xbps_dbg_printf("Processing system configuration directory: %s\n", xhp->sysconfdir); - if ((rv = parse_files_glob(xhp, seen, xhp->sysconfdir, "*.conf", false))) + r = parse_files_glob( + xhp, seen, xhp->sysconfdir, "*.conf", false); + if (r < 0) goto out; } out: xbps_object_release(seen); - return rv; + return r; } diff --git a/lib/initend.c b/lib/initend.c index f59d1dfee..d6d613608 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -192,4 +192,41 @@ xbps_end(struct xbps_handle *xhp) assert(xhp); xbps_pkgdb_release(xhp); + + if (xhp->vpkgd) { + xbps_object_release(xhp->vpkgd); + xhp->vpkgd = NULL; + } + if (xhp->vpkgd_conf) { + xbps_object_release(xhp->vpkgd_conf); + xhp->vpkgd_conf = NULL; + } + if (xhp->pkgdb_revdeps) { + xbps_object_release(xhp->pkgdb_revdeps); + xhp->pkgdb_revdeps = NULL; + } + if (xhp->transd) { + xbps_object_release(xhp->transd); + xhp->transd = NULL; + } + + if (xhp->preserved_files) { + xbps_object_release(xhp->preserved_files); + xhp->preserved_files = NULL; + } + if (xhp->noextract) { + xbps_object_release(xhp->noextract); + xhp->noextract = NULL; + } + if (xhp->ignored_pkgs) { + xbps_object_release(xhp->ignored_pkgs); + xhp->ignored_pkgs= NULL; + } + if (xhp->repositories) { + xbps_object_release(xhp->repositories); + xhp->ignored_pkgs= NULL; + } + + free(xhp->pkgdb_plist); + xhp->pkgdb_plist = NULL; } diff --git a/lib/package_fulldeptree.c b/lib/package_fulldeptree.c index 869fbd16a..22cbb9026 100644 --- a/lib/package_fulldeptree.c +++ b/lib/package_fulldeptree.c @@ -47,8 +47,8 @@ struct item { UT_hash_handle hh; }; +// XXX: this shouldn't be a global static... static struct item *items = NULL; -static xbps_array_t result; static struct item * lookupItem(const char *pkgn) @@ -99,7 +99,7 @@ addDepn(struct item *item, struct item *xitem) } static void -add_deps_recursive(struct item *item, bool first) +add_deps_recursive(xbps_array_t result, struct item *item, bool first) { struct depn *dep; xbps_string_t str; @@ -108,7 +108,7 @@ add_deps_recursive(struct item *item, bool first) return; for (dep = item->dbase; dep; dep = dep->dnext) - add_deps_recursive(dep->item, false); + add_deps_recursive(result, dep->item, false); if (first) return; @@ -133,19 +133,23 @@ cleanup(void) } } +struct deptree_ctx { + struct xbps_handle *xhp; + xbps_array_t result; + bool rpool; +}; + /* * Recursively calculate all dependencies. */ static struct item * -ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, - size_t depth) +ordered_depends(struct deptree_ctx *ctx, xbps_dictionary_t pkgd, size_t depth) { xbps_array_t rdeps, provides; xbps_string_t str; struct item *item = NULL, *xitem = NULL; const char *pkgver = NULL, *pkgname = NULL; - assert(xhp); assert(pkgd); rdeps = xbps_dictionary_get(pkgd, "run_depends"); @@ -154,7 +158,7 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, item = lookupItem(pkgname); if (item) { - add_deps_recursive(item, depth == 0); + add_deps_recursive(ctx->result, item, depth == 0); return item; } @@ -171,12 +175,12 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, char curdepname[XBPS_NAME_SIZE]; xbps_array_get_cstring_nocopy(rdeps, i, &curdep); - if (rpool) { - if ((curpkgd = xbps_rpool_get_pkg(xhp, curdep)) == NULL) - curpkgd = xbps_rpool_get_virtualpkg(xhp, curdep); + if (ctx->rpool) { + if ((curpkgd = xbps_rpool_get_pkg(ctx->xhp, curdep)) == NULL) + curpkgd = xbps_rpool_get_virtualpkg(ctx->xhp, curdep); } else { - if ((curpkgd = xbps_pkgdb_get_pkg(xhp, curdep)) == NULL) - curpkgd = xbps_pkgdb_get_virtualpkg(xhp, curdep); + if ((curpkgd = xbps_pkgdb_get_pkg(ctx->xhp, curdep)) == NULL) + curpkgd = xbps_pkgdb_get_virtualpkg(ctx->xhp, curdep); /* Ignore missing local runtime dependencies, because ignorepkg */ if (curpkgd == NULL) continue; @@ -199,10 +203,10 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, } xitem = lookupItem(curdepname); if (xitem) { - add_deps_recursive(xitem, false); + add_deps_recursive(ctx->result, xitem, false); continue; } - xitem = ordered_depends(xhp, curpkgd, rpool, depth+1); + xitem = ordered_depends(ctx, curpkgd, depth+1); if (xitem == NULL) { /* package depends on missing dependencies */ xbps_dbg_printf("%s: missing dependency '%s'\n", pkgver, curdep); @@ -213,10 +217,10 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, addDepn(item, xitem); } /* all deps were processed, add item to head */ - if (depth > 0 && !xbps_match_string_in_array(result, item->pkgver)) { + if (depth > 0 && !xbps_match_string_in_array(ctx->result, item->pkgver)) { str = xbps_string_create_cstring(item->pkgver); assert(str); - xbps_array_add_first(result, str); + xbps_array_add_first(ctx->result, str); xbps_object_release(str); } return item; @@ -225,11 +229,12 @@ ordered_depends(struct xbps_handle *xhp, xbps_dictionary_t pkgd, bool rpool, xbps_array_t HIDDEN xbps_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg, bool rpool) { + struct deptree_ctx ctx = { + .xhp = xhp, + .rpool = rpool, + }; xbps_dictionary_t pkgd; - result = xbps_array_create(); - assert(result); - if (rpool) { if (((pkgd = xbps_rpool_get_pkg(xhp, pkg)) == NULL) && ((pkgd = xbps_rpool_get_virtualpkg(xhp, pkg)) == NULL)) @@ -239,9 +244,20 @@ xbps_get_pkg_fulldeptree(struct xbps_handle *xhp, const char *pkg, bool rpool) ((pkgd = xbps_pkgdb_get_virtualpkg(xhp, pkg)) == NULL)) return NULL; } - if (ordered_depends(xhp, pkgd, rpool, 0) == NULL) + + ctx.result = xbps_array_create(); + if (!ctx.result) { + xbps_error_oom(); return NULL; + } + + if (ordered_depends(&ctx, pkgd, 0) == NULL) + goto err; cleanup(); - return result; + return ctx.result; +err: + cleanup(); + xbps_object_release(ctx.result); + return NULL; } diff --git a/lib/package_orphans.c b/lib/package_orphans.c index 49632d5b3..090a16527 100644 --- a/lib/package_orphans.c +++ b/lib/package_orphans.c @@ -23,11 +23,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include -#include #include -#include #include "xbps_api_impl.h" @@ -69,8 +67,11 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) if (xbps_pkgdb_init(xhp) != 0) return NULL; - if ((array = xbps_array_create()) == NULL) + array = xbps_array_create(); + if (!array) { + xbps_error_oom(); return NULL; + } if (!orphans_user) { /* automatic mode (xbps-query -O, xbps-remove -o) */ @@ -108,7 +109,10 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) if (revdepscnt == 0) { added = true; - xbps_array_add(array, pkgd); + if (!xbps_array_add(array, pkgd)) { + xbps_error_oom(); + goto err; + } xbps_dbg_printf(" %s orphan (automatic and !revdeps)\n", pkgver); continue; } @@ -122,7 +126,10 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) } if (cnt == revdepscnt) { added = true; - xbps_array_add(array, pkgd); + if (!xbps_array_add(array, pkgd)) { + xbps_error_oom(); + goto err; + } xbps_dbg_printf(" %s orphan (automatic and all revdeps)\n", pkgver); } @@ -148,7 +155,10 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) pkgd = xbps_pkgdb_get_pkg(xhp, pkgver); if (pkgd == NULL) continue; - xbps_array_add(array, pkgd); + if (!xbps_array_add(array, pkgd)) { + xbps_error_oom(); + goto err; + } } for (unsigned int i = 0; i < xbps_array_count(array); i++) { @@ -160,7 +170,13 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) pkgd = xbps_array_get(array, i); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, pkgver); + if (!rdeps) { + // XXX: we should probably abort. + xbps_error_printf("failed to get reverse dependencies: %s\n", strerror(errno)); + continue; + } if (xbps_array_count(rdeps) == 0) { + xbps_object_release(rdeps); continue; } @@ -195,11 +211,18 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user) cnt++; } if (cnt == reqbycnt) { - xbps_array_add(array, deppkgd); + if (!xbps_array_add(array, deppkgd)) { + xbps_error_oom(); + goto err; + } xbps_dbg_printf(" added %s orphan\n", deppkgver); } } + xbps_object_release(rdeps); } return array; +err: + xbps_object_release(array); + return NULL; } diff --git a/lib/package_register.c b/lib/package_register.c index 5ea2f6f9f..3863fe314 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -107,7 +107,6 @@ xbps_register_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkgrd) xbps_dictionary_remove(pkgd, "remove-and-update"); xbps_dictionary_remove(pkgd, "transaction"); xbps_dictionary_remove(pkgd, "skip-obsoletes"); - xbps_dictionary_remove(pkgd, "pkgname"); xbps_dictionary_remove(pkgd, "version"); if (!xbps_dictionary_set(xhp->pkgdb, pkgname, pkgd)) { diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 7a6e01f66..777576aa3 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -467,6 +467,8 @@ unpack_archive(struct xbps_handle *xhp, free(buf); } xbps_object_release(binpkg_filesd); + if (pkg_filesd) + xbps_object_release(pkg_filesd); return rv; } diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 037343a23..bb8f07973 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.c @@ -125,24 +125,20 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp) if (!xbps_dictionary_count(xhp->pkgdb)) return 0; - if (xhp->vpkgd == NULL) { + if (!xhp->vpkgd) { + // XXX: this is useless, xbps_init already creates it... + // should probably be removed from there... xhp->vpkgd = xbps_dictionary_create(); - if (!xhp->vpkgd) { - r = -errno; - xbps_error_printf("failed to create dictionary\n"); - return r; - } + if (!xhp->vpkgd) + return xbps_error_oom(); } /* * This maps all pkgs that have virtualpkgs in pkgdb. */ iter = xbps_dictionary_iterator(xhp->pkgdb); - if (!iter) { - r = -errno; - xbps_error_printf("failed to create iterator"); - return r; - } + if (!iter) + return xbps_error_oom(); while ((obj = xbps_object_iterator_next(iter))) { xbps_array_t provides; @@ -177,13 +173,11 @@ pkgdb_map_vpkgs(struct xbps_handle *xhp) if (!providers) { providers = xbps_dictionary_create(); if (!providers) { - r = -errno; - xbps_error_printf("failed to create dictionary\n"); + r = xbps_error_oom(); goto out; } if (!xbps_dictionary_set(xhp->vpkgd, vpkgname, providers)) { - r = -errno; - xbps_error_printf("failed to set dictionary entry\n"); + r = xbps_error_errno(errno, "failed to set dictionary entry\n"); xbps_object_release(providers); goto out; } @@ -212,7 +206,7 @@ pkgdb_map_names(struct xbps_handle *xhp) { xbps_object_iterator_t iter; xbps_object_t obj; - int rv = 0; + int r = 0; if (!xbps_dictionary_count(xhp->pkgdb)) return 0; @@ -222,34 +216,37 @@ pkgdb_map_names(struct xbps_handle *xhp) * This way we do it once and not multiple times. */ iter = xbps_dictionary_iterator(xhp->pkgdb); - assert(iter); + if (!iter) + return xbps_error_oom(); while ((obj = xbps_object_iterator_next(iter))) { xbps_dictionary_t pkgd; - const char *pkgver; - char pkgname[XBPS_NAME_SIZE] = {0}; + const char *pkgname; + + pkgname = xbps_dictionary_keysym_cstring_nocopy(obj); + + // ignore internal objs + if (strncmp(pkgname, "_XBPS_", 6) == 0) + continue; pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj); - if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) { + if (!pkgd) + xbps_unreachable(); + if (xbps_dictionary_get(pkgd, "pkgname")) continue; - } - if (!xbps_pkg_name(pkgname, sizeof(pkgname), pkgver)) { - rv = EINVAL; - break; - } if (!xbps_dictionary_set_cstring(pkgd, "pkgname", pkgname)) { - rv = EINVAL; + r = xbps_error_oom(); break; } } xbps_object_iterator_release(iter); - return rv; + return r; } int HIDDEN xbps_pkgdb_init(struct xbps_handle *xhp) { - int rv; + int r; assert(xhp); @@ -264,22 +261,19 @@ xbps_pkgdb_init(struct xbps_handle *xhp) return rv; #endif - - if ((rv = xbps_pkgdb_update(xhp, false, true)) != 0) { - if (rv != ENOENT) - xbps_error_printf("failed to initialize pkgdb: %s\n", strerror(rv)); - return rv; - } - if ((rv = pkgdb_map_names(xhp)) != 0) { - xbps_dbg_printf("[pkgdb] pkgdb_map_names %s\n", strerror(rv)); - return rv; + r = xbps_pkgdb_update(xhp, false, true); + if (r != 0) { + return -r; } - if ((rv = pkgdb_map_vpkgs(xhp)) != 0) { - xbps_dbg_printf("[pkgdb] pkgdb_map_vpkgs %s\n", strerror(rv)); - return rv; - } - assert(xhp->pkgdb); - xbps_dbg_printf("[pkgdb] initialized ok.\n"); + + r = pkgdb_map_names(xhp); + if (r < 0) + return xbps_error_errno( + r, "failed to add pkgname properties: %s\n", strerror(-r)); + + r = pkgdb_map_vpkgs(xhp); + if (r < 0) + return r; return 0; } @@ -323,8 +317,13 @@ xbps_pkgdb_update(struct xbps_handle *xhp, bool flush, bool update) if (!rv) rv = EINVAL; - if (rv == ENOENT) + if (rv == ENOENT) { xhp->pkgdb = xbps_dictionary_create(); + if (!xhp->pkgdb) { + xbps_error_oom(); + return errno; + } + } else xbps_error_printf("cannot access to pkgdb: %s\n", strerror(rv)); diff --git a/lib/plist.c b/lib/plist.c index 67730ef82..86d6a6459 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include @@ -244,63 +243,3 @@ xbps_array_iter_from_dict(xbps_dictionary_t dict, const char *key) return xbps_array_iterator(array); } - -static int -array_replace_dict(xbps_array_t array, - xbps_dictionary_t dict, - const char *str, - bool bypattern) -{ - xbps_object_t obj; - const char *pkgver, *pkgname; - - assert(xbps_object_type(array) == XBPS_TYPE_ARRAY); - assert(xbps_object_type(dict) == XBPS_TYPE_DICTIONARY); - assert(str != NULL); - - for (unsigned int i = 0; i < xbps_array_count(array); i++) { - obj = xbps_array_get(array, i); - if (obj == NULL) { - continue; - } - if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) { - continue; - } - if (bypattern) { - /* pkgpattern match */ - if (xbps_pkgpattern_match(pkgver, str)) { - if (!xbps_array_set(array, i, dict)) { - return EINVAL; - } - return 0; - } - } else { - /* pkgname match */ - xbps_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); - if (strcmp(pkgname, str) == 0) { - if (!xbps_array_set(array, i, dict)) { - return EINVAL; - } - return 0; - } - } - } - /* no match */ - return ENOENT; -} - -int HIDDEN -xbps_array_replace_dict_by_name(xbps_array_t array, - xbps_dictionary_t dict, - const char *pkgver) -{ - return array_replace_dict(array, dict, pkgver, false); -} - -int HIDDEN -xbps_array_replace_dict_by_pattern(xbps_array_t array, - xbps_dictionary_t dict, - const char *pattern) -{ - return array_replace_dict(array, dict, pattern, true); -} diff --git a/lib/plist_match.c b/lib/plist_match.c index 2be48d0e6..20d6be315 100644 --- a/lib/plist_match.c +++ b/lib/plist_match.c @@ -23,11 +23,9 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include -#include #include -#include #include "xbps_api_impl.h" diff --git a/lib/repo.c b/lib/repo.c index 8462c3104..8d8922767 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -104,9 +104,9 @@ repo_read_next(struct xbps_repo *repo, struct archive *ar, struct archive_entry r = archive_read_next_header(ar, entry); if (r == ARCHIVE_FATAL) { - xbps_error_printf("failed to read repository: %s: %s\n", - repo->uri, archive_error_string(ar)); - return -xbps_archive_errno(ar); + return xbps_error_errno(xbps_archive_errno(ar), + "failed to read repository: %s: %s\n", repo->uri, + archive_error_string(ar)); } else if (r == ARCHIVE_WARN) { xbps_warn_printf("reading repository: %s: %s\n", repo->uri, archive_error_string(ar)); @@ -130,18 +130,18 @@ repo_read_index(struct xbps_repo *repo, struct archive *ar) /* index.plist */ if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_INDEX) != 0) { - xbps_error_printf("failed to read repository index: %s: unexpected archive entry\n", + return xbps_error_errno(EINVAL, + "failed to read repository index: %s: unexpected archive " + "entry\n", repo->uri); - r = -EINVAL; - return r; } if (archive_entry_size(entry) == 0) { r = archive_read_data_skip(ar); if (r == ARCHIVE_FATAL) { - xbps_error_printf("failed to read repository: %s: archive error: %s\n", + return xbps_error_errno(xbps_archive_errno(ar), + "failed to read repository: %s: archive error: %s\n", repo->uri, archive_error_string(ar)); - return -xbps_archive_errno(ar); } repo->index = xbps_dictionary_create(); return 0; @@ -149,11 +149,9 @@ repo_read_index(struct xbps_repo *repo, struct archive *ar) buf = xbps_archive_get_file(ar, entry); if (!buf) { - r = -errno; - xbps_error_printf( + return xbps_error_errno(r, "failed to open repository: %s: failed to read index: %s\n", - repo->uri, strerror(-r)); - return r; + repo->uri, strerror(errno)); } repo->index = xbps_dictionary_internalize(buf); r = -errno; @@ -161,10 +159,9 @@ repo_read_index(struct xbps_repo *repo, struct archive *ar) if (!repo->index) { if (!r) r = -EINVAL; - xbps_error_printf( + return xbps_error_errno(r, "failed to open repository: %s: failed to parse index: %s\n", repo->uri, strerror(-r)); - return r; } xbps_dictionary_make_immutable(repo->index); @@ -183,17 +180,17 @@ repo_read_meta(struct xbps_repo *repo, struct archive *ar) return r; if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_META) != 0) { - xbps_error_printf("failed to read repository metadata: %s: unexpected archive entry\n", + return xbps_error_errno(EINVAL, + "failed to read repository metadata: %s: unexpected " + "archive entry\n", repo->uri); - r = -EINVAL; - return r; } if (archive_entry_size(entry) == 0) { r = archive_read_data_skip(ar); if (r == ARCHIVE_FATAL) { - xbps_error_printf("failed to read repository: %s: archive error: %s\n", + return xbps_error_errno(xbps_archive_errno(ar), + "failed to read repository: %s: archive error: %s\n", repo->uri, archive_error_string(ar)); - return -xbps_archive_errno(ar); } repo->idxmeta = NULL; return 0; @@ -201,12 +198,10 @@ repo_read_meta(struct xbps_repo *repo, struct archive *ar) buf = xbps_archive_get_file(ar, entry); if (!buf) { - r = -errno; - xbps_error_printf( + return xbps_error_errno(errno, "failed to read repository metadata: %s: failed to read " "metadata: %s\n", - repo->uri, strerror(-r)); - return r; + repo->uri, strerror(errno)); } /* for backwards compatibility check if the content is DEADBEEF. */ if (strcmp(buf, "DEADBEEF") == 0) { @@ -221,11 +216,10 @@ repo_read_meta(struct xbps_repo *repo, struct archive *ar) if (!repo->idxmeta) { if (!r) r = -EINVAL; - xbps_error_printf( + return xbps_error_errno(r, "failed to read repository metadata: %s: failed to parse " "metadata: %s\n", repo->uri, strerror(-r)); - return r; } repo->is_signed = true; @@ -250,10 +244,10 @@ repo_read_stage(struct xbps_repo *repo, struct archive *ar) } if (strcmp(archive_entry_pathname(entry), XBPS_REPODATA_STAGE) != 0) { - xbps_error_printf("failed to read repository stage: %s: unexpected archive entry\n", + return xbps_error_errno(EINVAL, + "failed to read repository stage: %s: unexpected archive " + "entry\n", repo->uri); - r = -EINVAL; - return r; } if (archive_entry_size(entry) == 0) { repo->stage = xbps_dictionary_create(); @@ -262,9 +256,9 @@ repo_read_stage(struct xbps_repo *repo, struct archive *ar) repo->stage = xbps_archive_get_dictionary(ar, entry); if (!repo->stage) { - xbps_error_printf("failed to open repository: %s: reading stage: %s\n", + return xbps_error_errno(EIO, + "failed to open repository: %s: reading stage: %s\n", repo->uri, archive_error_string(ar)); - return -EIO; } xbps_dictionary_make_immutable(repo->stage); return 0; @@ -294,14 +288,15 @@ repo_open_local(struct xbps_repo *repo, struct archive *ar) char path[PATH_MAX]; int r; + if (repo->is_remote) { char *cachedir; cachedir = xbps_get_remote_repo_string(repo->uri); if (!cachedir) { - r = -EINVAL; - xbps_error_printf("failed to open repository: %s: invalid repository url\n", + return xbps_error_errno(EINVAL, + "failed to open repository: %s: invalid repository " + "url\n", repo->uri); - goto err; } r = snprintf(path, sizeof(path), "%s/%s/%s-repodata", repo->xhp->metadir, cachedir, repo->arch); @@ -310,23 +305,17 @@ repo_open_local(struct xbps_repo *repo, struct archive *ar) r = snprintf(path, sizeof(path), "%s/%s-repodata", repo->uri, repo->arch); } if (r < 0 || (size_t)r >= sizeof(path)) { - r = -ENAMETOOLONG; - xbps_error_printf("failed to open repository: %s: repository path too long\n", + return xbps_error_errno(ENAMETOOLONG, + "failed to open repository: %s: repository path too long\n", repo->uri); - goto err; } r = xbps_archive_read_open(ar, path); - if (r < 0) { - if (r != -ENOENT) { - xbps_error_printf("failed to open repodata: %s: %s\n", - path, strerror(-r)); - } - goto err; + if (r < 0 && r != -ENOENT) { + return xbps_error_errno(r, + "failed to open repodata: %s: %s\n", path, + strerror(-r)); } - - return 0; -err: return r; } @@ -338,15 +327,16 @@ repo_open_remote(struct xbps_repo *repo, struct archive *ar) r = snprintf(url, sizeof(url), "%s/%s-repodata", repo->uri, repo->arch); if (r < 0 || (size_t)r >= sizeof(url)) { - xbps_error_printf("failed to open repository: %s: repository url too long\n", + return xbps_error_errno(ENAMETOOLONG, + "failed to open repository: %s: repository url too long\n", repo->uri); - return -ENAMETOOLONG; } r = xbps_archive_read_open_remote(ar, url); if (r < 0) { - xbps_error_printf("failed to open repository: %s: %s\n", repo->uri, strerror(-r)); - return r; + return xbps_error_errno(r, + "failed to open repository: %s: %s\n", repo->uri, + strerror(-r)); } return 0; @@ -359,11 +349,9 @@ repo_open(struct xbps_handle *xhp, struct xbps_repo *repo) int r; ar = xbps_archive_read_new(); - if (!ar) { - r = -errno; - xbps_error_printf("failed to open repo: %s\n", strerror(-r)); - return r; - } + if (!ar) + return xbps_error_errno( + errno, "failed to open repo: %s\n", strerror(errno)); if (repo->is_remote && (xhp->flags & XBPS_FLAG_REPOS_MEMSYNC)) r = repo_open_remote(repo, ar); @@ -497,9 +485,7 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url) repo = calloc(1, sizeof(*repo)); if (!repo) { - r = -errno; - xbps_error_printf("failed to open repository: %s\n", strerror(-r)); - errno = -r; + xbps_error_oom(); return NULL; } repo->xhp = xhp; diff --git a/lib/transaction_check_conflicts.c b/lib/transaction_check_conflicts.c index b099db47c..3434dee37 100644 --- a/lib/transaction_check_conflicts.c +++ b/lib/transaction_check_conflicts.c @@ -23,7 +23,6 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include @@ -55,9 +54,9 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, trans_cflicts = xbps_dictionary_get(xhp->transd, "conflicts"); if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &repopkgver)) - abort(); + xbps_unreachable(); if (!xbps_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &repopkgname)) - abort(); + xbps_unreachable(); for (unsigned int i = 0; i < xbps_array_count(pkg_cflicts); i++) { const char *pkgver = NULL, *pkgname = NULL, *cfpkg = NULL; @@ -101,8 +100,13 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, buf = xbps_xasprintf("CONFLICT: %s with " "installed pkg %s (matched by %s)", repopkgver, pkgver, cfpkg); - if (!xbps_array_add_cstring(trans_cflicts, buf)) + if (!buf) + return xbps_error_oom(); + if (!xbps_array_add_cstring(trans_cflicts, buf)) { + free(buf); return xbps_error_oom(); + } + free(buf); continue; } /* @@ -129,8 +133,11 @@ pkg_conflicts_trans(struct xbps_handle *xhp, xbps_array_t array, repopkgver, pkgver, cfpkg); if (!buf) return xbps_error_oom(); - if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf)) + if (!xbps_array_add_cstring(trans_cflicts, buf)) { + free(buf); return xbps_error_oom(); + } + free(buf); continue; } } @@ -192,8 +199,11 @@ pkgdb_conflicts_cb(struct xbps_handle *xhp, xbps_object_t obj, repopkgver, pkgver, cfpkg); if (!buf) return xbps_error_oom(); - if (!xbps_array_add_cstring_nocopy(trans_cflicts, buf)) + if (!xbps_array_add_cstring(trans_cflicts, buf)) { + free(buf); return xbps_error_oom(); + } + free(buf); continue; } } diff --git a/lib/transaction_check_replaces.c b/lib/transaction_check_replaces.c index 2b585b0d6..57ff7c6a9 100644 --- a/lib/transaction_check_replaces.c +++ b/lib/transaction_check_replaces.c @@ -23,16 +23,72 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include #include #include -#include -#include #include -#include +#include "xbps.h" +#include "xbps/xbps_dictionary.h" #include "xbps_api_impl.h" +static int +replace_in_transaction( + xbps_dictionary_t pkgd, const char *pattern, const char *pkgver) +{ + const char *curpkgver = NULL; + int r; + + // already being removed + if (xbps_transaction_pkg_type(pkgd) == XBPS_TRANS_REMOVE) + return 0; + + if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver)) + xbps_unreachable(); + + // XXX: ??? + if (!xbps_match_virtual_pkg_in_dict(pkgd, pattern) && + !xbps_pkgpattern_match(curpkgver, pattern)) + return 0; + + if (!xbps_dictionary_set_bool(pkgd, "replaced", true)) + return xbps_error_oom(); + r = transaction_package_set_action(pkgd, XBPS_TRANS_REMOVE); + if (r < 0) + return r; + + xbps_verbose_printf( + "Package `%s' will be replaced by `%s'\n", curpkgver, pkgver); + xbps_dbg_printf( + "[replaces] package `%s' in transaction will be replaced by `%s', " + "matched with `%s'\n", + curpkgver, pkgver, pattern); + return 0; +} + +static int +replace_in_pkgdb(struct xbps_handle *xhp, xbps_dictionary_t pkgd, + const char *pattern, const char *pkgver) +{ + const char *curpkgver = NULL; + int r; + + if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver)) + xbps_unreachable(); + + r = transaction_store(xhp, pkgd, XBPS_TRANS_REMOVE, false, true); + if (r < 0) + return r; + + xbps_verbose_printf( + "Installed package `%s' will be replaced by `%s'\n", curpkgver, pkgver); + xbps_dbg_printf( + "[replaces] installed package `%s' will be replaced by `%s', " + "matched with `%s'\n", + curpkgver, pkgver, pattern); + return 0; +} + /* * Processes the array of pkg dictionaries in "pkgs" to * find matching package replacements via "replaces" pkg obj. @@ -40,150 +96,78 @@ * This array contains the unordered list of packages in * the transaction dictionary. */ -bool HIDDEN -xbps_transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs) +int HIDDEN +transaction_check_replaces(struct xbps_handle *xhp, xbps_array_t pkgs) { - assert(xhp); - assert(pkgs); - for (unsigned int i = 0; i < xbps_array_count(pkgs); i++) { xbps_array_t replaces; - xbps_object_t obj; - xbps_object_iterator_t iter; - xbps_dictionary_t instd, reppkgd; + xbps_object_t pkgd; const char *pkgver = NULL; - char pkgname[XBPS_NAME_SIZE] = {0}; + int r; - obj = xbps_array_get(pkgs, i); - replaces = xbps_dictionary_get(obj, "replaces"); - if (replaces == NULL || xbps_array_count(replaces) == 0) - continue; + pkgd = xbps_array_get(pkgs, i); + if (!pkgd) + xbps_unreachable(); - if (!xbps_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver)) { - return false; - } - if (!xbps_pkg_name(pkgname, XBPS_NAME_SIZE, pkgver)) { - return false; - } + replaces = xbps_dictionary_get(pkgd, "replaces"); + if (!replaces || xbps_array_count(replaces) == 0) + continue; - iter = xbps_array_iterator(replaces); - assert(iter); + if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) + xbps_unreachable(); for (unsigned int j = 0; j < xbps_array_count(replaces); j++) { - const char *curpkgver = NULL, *pattern = NULL; - char curpkgname[XBPS_NAME_SIZE] = {0}; - bool instd_auto = false, hold = false; - xbps_trans_type_t ttype; + bool autoinst = false; + xbps_dictionary_t instd, transd; + const char *pattern = NULL; + const char *reppkgname = NULL; + bool hold = false; if(!xbps_array_get_cstring_nocopy(replaces, j, &pattern)) - abort(); - - /* - * Find the installed package that matches the pattern - * to be replaced. Also check if the package would be - * installed in the transaction. - */ - if (((instd = xbps_pkgdb_get_pkg(xhp, pattern)) == NULL) && - ((instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) == NULL) && - ((instd = xbps_find_pkg_in_array(pkgs, pattern, XBPS_TRANS_INSTALL)) == NULL)) + xbps_unreachable(); + + // check if the package is installed or going to be installed... + if (!(instd = xbps_pkgdb_get_pkg(xhp, pattern)) && + !(instd = xbps_pkgdb_get_virtualpkg(xhp, pattern)) && + !(instd = xbps_find_pkg_in_array(pkgs, pattern, XBPS_TRANS_INSTALL))) continue; - if (!xbps_dictionary_get_cstring_nocopy(instd, "pkgver", &curpkgver)) { - xbps_object_iterator_release(iter); - return false; - } - /* ignore pkgs on hold mode */ - if (xbps_dictionary_get_bool(instd, "hold", &hold) && hold) + // don't replace itself + if (instd == pkgd) continue; - if (!xbps_pkg_name(curpkgname, XBPS_NAME_SIZE, curpkgver)) { - xbps_object_iterator_release(iter); - return false; - } - /* - * Check that we are not replacing the same package, - * due to virtual packages. - */ - if (strcmp(pkgname, curpkgname) == 0) { + // don't replace packages on hold + if (xbps_dictionary_get_bool(pkgd, "hold", &hold) && hold) continue; - } - /* - * Make sure to not add duplicates. - */ - xbps_dictionary_get_bool(instd, "automatic-install", &instd_auto); - reppkgd = xbps_find_pkg_in_array(pkgs, curpkgname, 0); - if (reppkgd) { - ttype = xbps_transaction_pkg_type(reppkgd); - if (ttype == XBPS_TRANS_REMOVE || ttype == XBPS_TRANS_HOLD) - continue; - if (!xbps_dictionary_get_cstring_nocopy(reppkgd, - "pkgver", &curpkgver)) { - xbps_object_iterator_release(iter); - return false; - } - if (!xbps_match_virtual_pkg_in_dict(reppkgd, pattern) && - !xbps_pkgpattern_match(curpkgver, pattern)) + + // check if the package is already in the transaction + if (!xbps_dictionary_get_cstring_nocopy(instd, "pkgname", &reppkgname)) + xbps_unreachable(); + transd = xbps_find_pkg_in_array(pkgs, reppkgname, 0); + + if (transd) { + if (transd == pkgd) continue; - /* - * Package contains replaces="pkgpattern", but the - * package that should be replaced is also in the - * transaction and it's going to be updated. - */ - if (!instd_auto) { - xbps_dictionary_remove(obj, "automatic-install"); - } - if (!xbps_dictionary_set_bool(reppkgd, "replaced", true)) { - xbps_object_iterator_release(iter); - return false; - } - if (!xbps_transaction_pkg_type_set(reppkgd, XBPS_TRANS_REMOVE)) { - xbps_object_iterator_release(iter); - return false; - } - if (xbps_array_replace_dict_by_name(pkgs, reppkgd, curpkgname) != 0) { - xbps_object_iterator_release(iter); - return false; - } - xbps_verbose_printf("Package `%s' will be replaced by `%s'\n", curpkgver, pkgver); - xbps_dbg_printf( - "Package `%s' in transaction will be " - "replaced by `%s', matched with `%s'\n", - curpkgver, pkgver, pattern); - continue; - } - /* - * If new package is providing a virtual package to the - * package that we want to replace we should respect - * the automatic-install object. - */ - if (xbps_match_virtual_pkg_in_dict(obj, pattern)) { - if (!instd_auto) { - xbps_dictionary_remove(obj, "automatic-install"); - } + r = replace_in_transaction( + transd, pattern, pkgver); + if (r < 0) + return r; + xbps_dictionary_get_bool( + transd, "automatic-install", &autoinst); + } else { + r = replace_in_pkgdb( + xhp, instd, pattern, pkgver); + if (r < 0) + return r; + xbps_dictionary_get_bool( + instd, "automatic-install", &autoinst); } - /* - * Add package dictionary into the transaction and mark - * it as to be "removed". - */ - if (!xbps_transaction_pkg_type_set(instd, XBPS_TRANS_REMOVE)) { - xbps_object_iterator_release(iter); - return false; - } - if (!xbps_dictionary_set_bool(instd, "replaced", true)) { - xbps_object_iterator_release(iter); - return false; - } - if (!xbps_array_add_first(pkgs, instd)) { - xbps_object_iterator_release(iter); - return false; - } - xbps_verbose_printf("Package `%s' will be replaced by `%s'\n", curpkgver, pkgver); - xbps_dbg_printf( - "Package `%s' will be replaced by `%s', " - "matched with `%s'\n", curpkgver, pkgver, pattern); + + // inherit manually installed + if (!autoinst) + xbps_dictionary_remove(pkgd, "automatic-install"); } - xbps_object_iterator_release(iter); } - return true; + return 0; } diff --git a/lib/transaction_check_shlibs.c b/lib/transaction_check_shlibs.c index 7495fda03..0c1359679 100644 --- a/lib/transaction_check_shlibs.c +++ b/lib/transaction_check_shlibs.c @@ -22,7 +22,6 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include #include #include @@ -91,7 +90,7 @@ collect_shlib_array(struct shlib_ctx *ctx, xbps_array_t array) struct shlib_entry *entry; const char *shlib = NULL; if (!xbps_array_get_cstring_nocopy(array, i, &shlib)) - return -EINVAL; + xbps_unreachable(); entry = shlib_entry_get(ctx, shlib); if (!entry) return -errno; @@ -122,10 +121,8 @@ collect_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs) if (xbps_transaction_pkg_type(pkgd) == XBPS_TRANS_HOLD) continue; - if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) { - xbps_error_printf("invalid package: missing `pkgname` property\n"); - return -EINVAL; - } + if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgname", &pkgname)) + xbps_unreachable(); if (!xbps_dictionary_set(ctx->seen, pkgname, placeholder)) return xbps_error_oom(); @@ -193,16 +190,19 @@ check_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs) const char *shlib = NULL; char *missing; if (!xbps_array_get_cstring_nocopy(array, j, &shlib)) - return -EINVAL; + xbps_unreachable(); if (shlib_entry_find(ctx->entries, shlib)) continue; if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) - return -EINVAL; + xbps_unreachable(); missing = xbps_xasprintf( "%s: broken, unresolvable shlib `%s'", pkgver, shlib); - if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) + if (!xbps_array_add_cstring(ctx->missing, missing)) { + free(missing); return xbps_error_oom(); + } + free(missing); } } @@ -233,16 +233,19 @@ check_shlibs(struct shlib_ctx *ctx, xbps_array_t pkgs) const char *shlib = NULL; char *missing; if (!xbps_array_get_cstring_nocopy(array, i, &shlib)) - return -EINVAL; + xbps_unreachable(); if (shlib_entry_find(ctx->entries, shlib)) continue; if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)) - return -EINVAL; + xbps_unreachable(); missing = xbps_xasprintf( "%s: broken, unresolvable shlib `%s'", pkgver, shlib); - if (!xbps_array_add_cstring_nocopy(ctx->missing, missing)) + if (!xbps_array_add_cstring(ctx->missing, missing)) { + free(missing); return xbps_error_oom(); + } + free(missing); } } diff --git a/lib/transaction_files.c b/lib/transaction_files.c index 7f25745d5..55723e9d6 100644 --- a/lib/transaction_files.c +++ b/lib/transaction_files.c @@ -51,7 +51,7 @@ struct item { const char *pkgname; const char *pkgver; char *sha256; - const char *target; + char *target; uint64_t size; enum type type; /* index is the index of the package update/install/removal in the transaction @@ -534,7 +534,8 @@ collect_file(struct xbps_handle *xhp, const char *file, size_t size, item->old.preserve = preserve; item->old.update = update; item->old.removepkg = removepkg; - item->old.target = target; + if (target) + item->old.target = strdup(target); if (sha256) item->old.sha256 = strdup(sha256); } else { @@ -546,7 +547,8 @@ collect_file(struct xbps_handle *xhp, const char *file, size_t size, item->new.preserve = preserve; item->new.update = update; item->new.removepkg = removepkg; - item->new.target = target; + if (target) + item->new.target = strdup(target); } if (item->old.type && item->new.type) { /* @@ -777,6 +779,8 @@ cleanup(void) free(item->file); free(item->old.sha256); free(item->new.sha256); + free(item->old.target); + free(item->new.target); free(item); } free(items); @@ -874,6 +878,7 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter) update, removepkg, preserve, true); if (rv != 0) goto out; + xbps_object_release(filesd); } } xbps_object_iterator_reset(iter); @@ -882,7 +887,8 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter) * Sort items by path length, to make it easier to find files in * directories. */ - qsort(items, itemsidx, sizeof (struct item *), pathcmp); + if (items) + qsort(items, itemsidx, sizeof (struct item *), pathcmp); if (chdir(xhp->rootdir) == -1) { rv = errno; diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 5a5eeb034..d92b7305d 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -29,6 +29,7 @@ #include #include +#include "xbps.h" #include "xbps_api_impl.h" /** @@ -217,12 +218,6 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force) if (!force && xbps_dictionary_get(pkg_repod, "hold")) ttype = XBPS_TRANS_HOLD; - /* - * Store pkgd from repo into the transaction. - */ - if (!xbps_transaction_pkg_type_set(pkg_repod, ttype)) { - return EINVAL; - } /* * Set automatic-install to true if it was requested and this is a new install. @@ -230,11 +225,7 @@ trans_find_pkg(struct xbps_handle *xhp, const char *pkg, bool force) if (ttype == XBPS_TRANS_INSTALL) autoinst = xhp->flags & XBPS_FLAG_INSTALL_AUTO; - if (!xbps_transaction_store(xhp, pkgs, pkg_repod, autoinst)) { - return EINVAL; - } - - return 0; + return transaction_store(xhp, pkg_repod, ttype, autoinst, false); } /* @@ -464,96 +455,96 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp, bool recursive) { xbps_dictionary_t pkgd; - xbps_array_t pkgs, orphans, orphans_pkg; - xbps_object_t obj; - int rv = 0; + int r; assert(xhp); assert(pkgname); - if ((pkgd = xbps_pkgdb_get_pkg(xhp, pkgname)) == NULL) { - /* pkg not installed */ - return ENOENT; - } - /* - * Prepare transaction dictionary and missing deps array. - */ - if ((rv = xbps_transaction_init(xhp)) != 0) - return rv; + r = xbps_transaction_init(xhp); + if (r < 0) + return r; - pkgs = xbps_dictionary_get(xhp->transd, "packages"); + pkgd = xbps_pkgdb_get_pkg(xhp, pkgname); + if (!pkgd) + return -errno; - if (!recursive) - goto rmpkg; /* * If recursive is set, find out which packages would be orphans * if the supplied package were already removed. */ - if ((orphans_pkg = xbps_array_create()) == NULL) - return ENOMEM; + // XXX: this is stupid and incomplete if multiple packages + // are removed at once, in that case orphans would not be correctly + // be identified... + if (recursive) { + xbps_array_t orphans, orphans_pkg; + + orphans_pkg = xbps_array_create(); + if (!orphans_pkg) + return xbps_error_oom(); + + if (!xbps_array_set_cstring_nocopy(orphans_pkg, 0, pkgname)) { + xbps_object_release(orphans_pkg); + return xbps_error_oom(); + } - xbps_array_set_cstring_nocopy(orphans_pkg, 0, pkgname); - orphans = xbps_find_pkg_orphans(xhp, orphans_pkg); - xbps_object_release(orphans_pkg); - if (xbps_object_type(orphans) != XBPS_TYPE_ARRAY) - return EINVAL; - for (unsigned int i = 0; i < xbps_array_count(orphans); i++) { - obj = xbps_array_get(orphans, i); - xbps_transaction_pkg_type_set(obj, XBPS_TRANS_REMOVE); - if (!xbps_transaction_store(xhp, pkgs, obj, false)) { - return EINVAL; + orphans = xbps_find_pkg_orphans(xhp, orphans_pkg); + if (!orphans) { + xbps_object_release(orphans_pkg); + return -errno; + } + xbps_object_release(orphans_pkg); + for (unsigned int i = 0; i < xbps_array_count(orphans); i++) { + xbps_dictionary_t opkgd; + + opkgd = xbps_array_get(orphans, i); + if (!opkgd) + xbps_unreachable(); + + r = transaction_store(xhp, opkgd, XBPS_TRANS_REMOVE, false, false); + if (r < 0) { + xbps_object_release(orphans); + return r; + } } } - xbps_object_release(orphans); - return rv; -rmpkg: - /* - * Add pkg dictionary into the transaction pkgs queue. - */ - xbps_transaction_pkg_type_set(pkgd, XBPS_TRANS_REMOVE); - if (!xbps_transaction_store(xhp, pkgs, pkgd, false)) { - return EINVAL; - } - return rv; + return transaction_store(xhp, pkgd, XBPS_TRANS_REMOVE, false, false); } int xbps_transaction_autoremove_pkgs(struct xbps_handle *xhp) { - xbps_array_t orphans, pkgs; - xbps_object_t obj; - int rv = 0; + xbps_array_t orphans; + int r; + + r = xbps_transaction_init(xhp); + if (r < 0) + return r; orphans = xbps_find_pkg_orphans(xhp, NULL); + if (!orphans) + return -errno; if (xbps_array_count(orphans) == 0) { - /* no orphans? we are done */ - goto out; + xbps_object_release(orphans); + return 0; } - /* - * Prepare transaction dictionary and missing deps array. - */ - if ((rv = xbps_transaction_init(xhp)) != 0) - goto out; - pkgs = xbps_dictionary_get(xhp->transd, "packages"); - /* - * Add pkg orphan dictionary into the transaction pkgs queue. - */ for (unsigned int i = 0; i < xbps_array_count(orphans); i++) { - obj = xbps_array_get(orphans, i); - xbps_transaction_pkg_type_set(obj, XBPS_TRANS_REMOVE); - if (!xbps_transaction_store(xhp, pkgs, obj, false)) { - rv = EINVAL; - goto out; + xbps_object_t pkgd; + + pkgd = xbps_array_get(orphans, i); + if (!pkgd) + xbps_unreachable(); + + r = transaction_store(xhp, pkgd, XBPS_TRANS_REMOVE, false, false); + if (r < 0) { + return r; } } -out: - if (orphans) - xbps_object_release(orphans); - return rv; + xbps_object_release(orphans); + return 0; } xbps_trans_type_t @@ -569,30 +560,3 @@ xbps_transaction_pkg_type(xbps_dictionary_t pkg_repod) return r; } - -bool -xbps_transaction_pkg_type_set(xbps_dictionary_t pkg_repod, xbps_trans_type_t ttype) -{ - uint8_t r; - - if (xbps_object_type(pkg_repod) != XBPS_TYPE_DICTIONARY) - return false; - - switch (ttype) { - case XBPS_TRANS_INSTALL: - case XBPS_TRANS_UPDATE: - case XBPS_TRANS_CONFIGURE: - case XBPS_TRANS_REMOVE: - case XBPS_TRANS_REINSTALL: - case XBPS_TRANS_HOLD: - case XBPS_TRANS_DOWNLOAD: - break; - default: - return false; - } - r = ttype; - if (!xbps_dictionary_set_uint8(pkg_repod, "transaction", r)) - return false; - - return true; -} diff --git a/lib/transaction_pkg_deps.c b/lib/transaction_pkg_deps.c index c325731f7..d8c982cc7 100644 --- a/lib/transaction_pkg_deps.c +++ b/lib/transaction_pkg_deps.c @@ -148,6 +148,7 @@ repo_deps(struct xbps_handle *xhp, while ((obj = xbps_object_iterator_next(iter))) { bool error = false, foundvpkg = false; bool autoinst = true; + int r; ttype = XBPS_TRANS_UNKNOWN; reqpkg = xbps_string_cstring_nocopy(obj); @@ -340,14 +341,10 @@ repo_deps(struct xbps_handle *xhp, autoinst = pkgd_auto; } if (ttype == XBPS_TRANS_CONFIGURE) { - if (!xbps_transaction_pkg_type_set(curpkgd, ttype)) { + r = transaction_store(xhp, curpkgd, ttype, autoinst, false); + if (r < 0) { + xbps_error_printf("transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); rv = EINVAL; - xbps_dbg_printf("xbps_transaction_pkg_type_set failed for `%s': %s\n", reqpkg, strerror(rv)); - break; - } - if (!xbps_transaction_store(xhp, pkgs, curpkgd, autoinst)) { - rv = EINVAL; - xbps_dbg_printf("xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); break; } continue; @@ -477,14 +474,10 @@ repo_deps(struct xbps_handle *xhp, /* * All deps were processed, store pkg in transaction. */ - if (!xbps_transaction_pkg_type_set(repopkgd, ttype)) { - rv = EINVAL; - xbps_dbg_printf("xbps_transaction_pkg_type_set failed for `%s': %s\n", reqpkg, strerror(rv)); - break; - } - if (!xbps_transaction_store(xhp, pkgs, repopkgd, autoinst)) { + r = transaction_store(xhp, repopkgd, ttype, autoinst, false); + if (r < 0) { rv = EINVAL; - xbps_dbg_printf("xbps_transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); + xbps_error_printf("transaction_store failed for `%s': %s\n", reqpkg, strerror(rv)); break; } } diff --git a/lib/transaction_prepare.c b/lib/transaction_prepare.c index 814559f9b..6134a60e0 100644 --- a/lib/transaction_prepare.c +++ b/lib/transaction_prepare.c @@ -23,12 +23,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include +#include + +#include #include -#include #include -#include -#include #include "xbps_api_impl.h" @@ -366,11 +365,13 @@ xbps_transaction_prepare(struct xbps_handle *xhp) * Check for packages to be replaced. */ xbps_dbg_printf("%s: checking replaces\n", __func__); - if (!xbps_transaction_check_replaces(xhp, pkgs)) { + r = transaction_check_replaces(xhp, pkgs); + if (r < 0) { xbps_object_release(xhp->transd); xhp->transd = NULL; - return EINVAL; + return -r; } + /* * Check if there are missing revdeps. */ diff --git a/lib/transaction_store.c b/lib/transaction_store.c index 89d7c1fc5..5bdf607b0 100644 --- a/lib/transaction_store.c +++ b/lib/transaction_store.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2014-2020 Juan Romero Pardines. + * Copyright (c) 2026 Duncan Overbruck . * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,82 +24,165 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#include #include -#include -#include +#include "xbps.h" #include "xbps_api_impl.h" -bool HIDDEN -xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs, - xbps_dictionary_t pkgrd, bool autoinst) +static int +transaction_replace_package(xbps_array_t pkgs, const char *pkgname, const char *pkgver) { - xbps_dictionary_t d, pkgd; + xbps_dictionary_t pkgd; + const char *curpkgver = NULL; + int r; + + pkgd = xbps_find_pkg_in_array(pkgs, pkgname, 0); + if (!pkgd) + return 1; + + /* compare version stored in transaction vs current */ + if (!xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver)) + xbps_unreachable(); + + r = xbps_cmpver(pkgver, curpkgver); + if (r == 0) + return 0; + // XXX: should it be possible to replace with lower version? + if (r == -1) + return 0; + + if (!xbps_remove_pkg_from_array_by_pkgver(pkgs, curpkgver)) + xbps_unreachable(); + + xbps_dbg_printf("[trans] replaced %s with %s\n", curpkgver, pkgver); + + return 1; +} + +// XXX: the automatic self replace is weird, there should be a better way +// than having to add and remove it from the metdata... +static int +package_set_self_replace(xbps_dictionary_t pkgd, const char *pkgname) +{ + char buf[XBPS_NAME_SIZE + sizeof(">=0") - 1]; xbps_array_t replaces; - const char *pkgver, *pkgname, *curpkgver, *repo; - char *self_replaced; - int rv; - assert(xhp); - assert(pkgs); - assert(pkgrd); + replaces = xbps_dictionary_get(pkgd, "replaces"); + if (!replaces) { + replaces = xbps_array_create(); + if (!replaces) + return xbps_error_oom(); + } else { + xbps_object_retain(replaces); + } - if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver)) { - return false; + snprintf(buf,sizeof(buf), "%s>=0", pkgname); + if (!xbps_array_add_cstring(replaces, buf)) { + xbps_object_release(replaces); + return xbps_error_oom(); } - if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname)) { - return false; + + if (!xbps_dictionary_set(pkgd, "replaces", replaces)) { + xbps_object_release(replaces); + return xbps_error_oom(); } - d = xbps_find_pkg_in_array(pkgs, pkgname, 0); - if (xbps_object_type(d) == XBPS_TYPE_DICTIONARY) { - /* compare version stored in transaction vs current */ - if (!xbps_dictionary_get_cstring_nocopy(d, "pkgver", &curpkgver)) { - return false; - } - rv = xbps_cmpver(pkgver, curpkgver); - if (rv == 0 || rv == -1) { - /* same version or stored version greater than current */ - return true; - } else { - /* - * Current version is greater than stored, - * replace stored with current. - */ - if (!xbps_remove_pkg_from_array_by_pkgver(pkgs, curpkgver)) { - return false; - } - xbps_dbg_printf("[trans] replaced %s with %s\n", curpkgver, pkgver); - } + + xbps_object_release(replaces); + return 0; +} + +int HIDDEN +transaction_package_set_action(xbps_dictionary_t pkgd, xbps_trans_type_t ttype) +{ + uint8_t v; + switch (ttype) { + case XBPS_TRANS_INSTALL: + case XBPS_TRANS_UPDATE: + case XBPS_TRANS_CONFIGURE: + case XBPS_TRANS_REMOVE: + case XBPS_TRANS_REINSTALL: + case XBPS_TRANS_HOLD: + case XBPS_TRANS_DOWNLOAD: + break; + case XBPS_TRANS_UNKNOWN: + return -EINVAL; } + v = ttype; + if (!xbps_dictionary_set_uint8(pkgd, "transaction", v)) + return xbps_error_oom(); + return 0; +} - if ((pkgd = xbps_dictionary_copy_mutable(pkgrd)) == NULL) - return false; +static int +package_set_auto_install(xbps_dictionary_t pkgd, bool value) +{ + if (!value) + return 0; + if (!xbps_dictionary_set_bool(pkgd, "automatic-install", true)) + return xbps_error_oom(); + return 0; +} - /* - * Add required objects into package dep's dictionary. - */ - if (autoinst && !xbps_dictionary_set_bool(pkgd, "automatic-install", true)) - goto err; +int HIDDEN +transaction_store(struct xbps_handle *xhp, xbps_dictionary_t pkgrd, + xbps_trans_type_t ttype, bool autoinst, bool replace) +{ + xbps_array_t pkgs; + xbps_dictionary_t pkgd; + const char *pkgver = NULL, *pkgname = NULL, *repo = NULL; + int r; - /* - * Set a replaces to itself, so that virtual packages are always replaced. - */ - if ((replaces = xbps_dictionary_get(pkgd, "replaces")) == NULL) - replaces = xbps_array_create(); + assert(xhp); + assert(pkgrd); - self_replaced = xbps_xasprintf("%s>=0", pkgname); - xbps_array_add_cstring(replaces, self_replaced); - free(self_replaced); + if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgver", &pkgver)) + xbps_unreachable(); + if (!xbps_dictionary_get_cstring_nocopy(pkgrd, "pkgname", &pkgname)) + xbps_unreachable(); - if (!xbps_dictionary_set(pkgd, "replaces", replaces)) - goto err; + pkgs = xbps_dictionary_get(xhp->transd, "packages"); + if (!pkgs) + xbps_unreachable(); - /* - * Add the dictionary into the unsorted queue. - */ - if (!xbps_array_add(pkgs, pkgd)) - goto err; + r = transaction_replace_package(pkgs, pkgname, pkgver); + if (r < 0) + return r; + if (r == 0) + return 0; + + pkgd = xbps_dictionary_copy_mutable(pkgrd); + if (!pkgd) { + xbps_object_release(pkgd); + return xbps_error_oom(); + } + + r = transaction_package_set_action(pkgd, ttype); + if (r < 0) { + xbps_object_release(pkgd); + return r; + } + r = package_set_auto_install(pkgd, autoinst); + if (r < 0) { + xbps_object_release(pkgd); + return r; + } + r = package_set_self_replace(pkgd, pkgname); + if (r < 0) { + xbps_object_release(pkgd); + return r; + } + + if (replace) { + if (!xbps_dictionary_set_bool(pkgd, "replaced", true)) { + xbps_object_release(pkgd); + return r; + } + } + + if (!xbps_array_add(pkgs, pkgd)) { + xbps_object_release(pkgd); + return xbps_error_oom(); + } xbps_dictionary_get_cstring_nocopy(pkgd, "repository", &repo); @@ -109,8 +193,5 @@ xbps_transaction_store(struct xbps_handle *xhp, xbps_array_t pkgs, autoinst ? " as automatic install" : "", repo); xbps_object_release(pkgd); - return true; -err: - xbps_object_release(pkgd); - return false; + return 0; } diff --git a/run-tests b/run-tests index ab8a516d9..5d98937ea 100755 --- a/run-tests +++ b/run-tests @@ -10,7 +10,7 @@ if [ -r /proc/cpuinfo ]; then NPROCS=$(grep ^proc /proc/cpuinfo|wc -l) fi export XBPS_SYSLOG=false -LIBRARY_PATH=$PWD/lib LD_LIBRARY_PATH=$PWD/lib ATF_SHELL=/bin/sh kyua --variable parallelism=$NPROCS test -r result.db -k tests/xbps/Kyuafile +LIBRARY_PATH=$PWD/lib LD_LIBRARY_PATH=$PWD/lib ATF_SHELL=/bin/sh kyua --variable parallelism=$NPROCS test -r result.db -k tests/xbps/Kyuafile "$@" rv=$? kyua report --verbose -r result.db rm -f result.db diff --git a/tests/xbps/libxbps/config/main.c b/tests/xbps/libxbps/config/main.c index de274512f..f3a02242a 100644 --- a/tests/xbps/libxbps/config/main.c +++ b/tests/xbps/libxbps/config/main.c @@ -1,5 +1,6 @@ /*- * Copyright (c) 2014 Enno Boland. + * Copyright (c) 2026 Duncan Overbruck . * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -23,10 +24,27 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *- */ +#include +#include +#include + #include +#include + #include -#include -#include + +static ssize_t PRINTF_LIKE(3, 0) +xsnprintf(char *dst, size_t dstsz, const char *fmt, ...) +{ + int l; + va_list ap; + va_start(ap, fmt); + l = vsnprintf(dst, dstsz, fmt, ap); + va_end(ap); + if (l < 0 || (size_t)l >= dstsz) + return -ENOBUFS; + return l; +} ATF_TC(config_include_test); ATF_TC_HEAD(config_include_test, tc) @@ -36,47 +54,39 @@ ATF_TC_HEAD(config_include_test, tc) ATF_TC_BODY(config_include_test, tc) { - struct xbps_handle xh; + char pwd[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir; - char *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); - buf = xbps_xasprintf("%s/xbps.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/xbps.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/xbps.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/xbps.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/1.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/1.include.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/1.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/1.include.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/2.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/2.include.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/2.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/2.include.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); /* should contain both repositories defined in [12].include.conf */ ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 2); + xbps_end(&xh); } @@ -91,7 +101,6 @@ ATF_TC_BODY(config_include_nomatch_test, tc) struct xbps_handle xh; const char *tcsdir; char *buf, *buf2, pwd[PATH_MAX]; - int ret; /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); @@ -101,9 +110,7 @@ ATF_TC_BODY(config_include_nomatch_test, tc) xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); @@ -118,6 +125,7 @@ ATF_TC_BODY(config_include_nomatch_test, tc) /* should contain no repositories */ ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 0); + xbps_end(&xh); } ATF_TC(config_include_absolute); @@ -128,44 +136,38 @@ ATF_TC_HEAD(config_include_absolute, tc) ATF_TC_BODY(config_include_absolute, tc) { - struct xbps_handle xh; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + char pwd[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir; - char *cfg, *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); - cfg = xbps_xasprintf("%s/xbps2.d", pwd); - ATF_REQUIRE_EQ(xbps_mkpath(cfg, 0755), 0); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/xbps2.d", pwd) >= 0); + ATF_REQUIRE_EQ(xbps_mkpath(buf1, 0755), 0); - buf = xbps_xasprintf("%s/xbps_absolute.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/xbps.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/xbps_absolute.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/xbps.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/1.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps2.d/1.include.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/1.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps2.d/1.include.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); /* should contain one repository defined in 1.include.conf */ ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 1); + xbps_end(&xh); } ATF_TC(config_include_absolute_glob); @@ -176,50 +178,42 @@ ATF_TC_HEAD(config_include_absolute_glob, tc) ATF_TC_BODY(config_include_absolute_glob, tc) { - struct xbps_handle xh; + char pwd[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir; - char *cfg, *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, pwd, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, pwd, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); - cfg = xbps_xasprintf("%s/xbps2.d", pwd); - ATF_REQUIRE_EQ(xbps_mkpath(cfg, 0755), 0); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/xbps2.d", pwd) >= 0); + ATF_REQUIRE_EQ(xbps_mkpath(buf1, 0755), 0); - buf = xbps_xasprintf("%s/xbps_absolute_glob.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/xbps.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/xbps_absolute_glob.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/xbps.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/1.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps2.d/1.include.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/1.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps2.d/1.include.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/2.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps2.d/2.include.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/2.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps2.d/2.include.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); /* should contain both repositories defined in [12].include.conf */ ATF_REQUIRE_EQ(xbps_array_count(xh.repositories), 2); + xbps_end(&xh); } ATF_TC(config_masking); @@ -230,40 +224,31 @@ ATF_TC_HEAD(config_masking, tc) ATF_TC_BODY(config_masking, tc) { - struct xbps_handle xh; + char pwd[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir, *repo; - char *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); - ret = snprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.sysconfdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); + ATF_REQUIRE(xsnprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.sysconfdir, 0755), 0); - buf = xbps_xasprintf("%s/1.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/repo.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/1.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/repo.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); - buf = xbps_xasprintf("%s/2.include.cf", tcsdir); - buf2 = xbps_xasprintf("%s/sys-xbps.d/repo.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/2.include.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/sys-xbps.d/repo.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -274,6 +259,7 @@ ATF_TC_BODY(config_masking, tc) /* should contain repository=1 */ ATF_REQUIRE_EQ(xbps_array_get_cstring_nocopy(xh.repositories, 0, &repo), true); ATF_REQUIRE_STREQ(repo, "1"); + xbps_end(&xh); } ATF_TC(config_trim_values); @@ -284,34 +270,27 @@ ATF_TC_HEAD(config_trim_values, tc) ATF_TC_BODY(config_trim_values, tc) { - struct xbps_handle xh; + char pwd[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir, *repo; - char *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); - ret = snprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.sysconfdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); + ATF_REQUIRE(xsnprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.sysconfdir, 0755), 0); - buf = xbps_xasprintf("%s/trim.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/1.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/trim.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/1.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -327,6 +306,7 @@ ATF_TC_BODY(config_trim_values, tc) ATF_REQUIRE_STREQ(repo, "2"); ATF_REQUIRE_EQ(xbps_array_get_cstring_nocopy(xh.repositories, 2, &repo), true); ATF_REQUIRE_STREQ(repo, "3"); + xbps_end(&xh); } ATF_TC(config_no_trailing_newline); @@ -337,34 +317,27 @@ ATF_TC_HEAD(config_no_trailing_newline, tc) ATF_TC_BODY(config_no_trailing_newline, tc) { - struct xbps_handle xh; + char pwd[PATH_MAX]; + char buf1[PATH_MAX]; + char buf2[PATH_MAX]; + struct xbps_handle xh = {0}; const char *tcsdir, *repo; - char *buf, *buf2, pwd[PATH_MAX]; - int ret; - /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); - memset(&xh, 0, sizeof(xh)); - buf = getcwd(pwd, sizeof(pwd)); + ATF_REQUIRE(getcwd(pwd, sizeof(pwd))); xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); - ret = snprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.confdir)), 1); - ret = snprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd); - ATF_REQUIRE_EQ((ret >= 0), 1); - ATF_REQUIRE_EQ(((size_t)ret < sizeof(xh.sysconfdir)), 1); + ATF_REQUIRE(xsnprintf(xh.confdir, sizeof(xh.confdir), "%s/xbps.d", pwd) >= 0); + ATF_REQUIRE(xsnprintf(xh.sysconfdir, sizeof(xh.sysconfdir), "%s/sys-xbps.d", pwd) >= 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.confdir, 0755), 0); ATF_REQUIRE_EQ(xbps_mkpath(xh.sysconfdir, 0755), 0); - buf = xbps_xasprintf("%s/no-trailing-nl.cf", tcsdir); - buf2 = xbps_xasprintf("%s/xbps.d/1.conf", pwd); - ATF_REQUIRE_EQ(symlink(buf, buf2), 0); - free(buf); - free(buf2); + ATF_REQUIRE(xsnprintf(buf1, sizeof(buf1), "%s/no-trailing-nl.cf", tcsdir) >= 0); + ATF_REQUIRE(xsnprintf(buf2, sizeof(buf2), "%s/xbps.d/1.conf", pwd) >= 0); + ATF_REQUIRE_EQ(symlink(buf1, buf2), 0); xh.flags = XBPS_FLAG_DEBUG; ATF_REQUIRE_EQ(xbps_init(&xh), 0); @@ -375,6 +348,7 @@ ATF_TC_BODY(config_no_trailing_newline, tc) /* should contain repository=test */ ATF_REQUIRE_EQ(xbps_array_get_cstring_nocopy(xh.repositories, 0, &repo), true); ATF_REQUIRE_STREQ(repo, "test"); + xbps_end(&xh); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/libxbps/find_pkg_orphans/main.c b/tests/xbps/libxbps/find_pkg_orphans/main.c index 8ec47eecb..a613e60ab 100644 --- a/tests/xbps/libxbps/find_pkg_orphans/main.c +++ b/tests/xbps/libxbps/find_pkg_orphans/main.c @@ -71,8 +71,8 @@ ATF_TC_BODY(find_pkg_orphans_test, tc) xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ATF_REQUIRE_EQ(xbps_init(&xh), 0); - a = xbps_array_create(); - xbps_array_add_cstring_nocopy(a, "xbps-git"); + ATF_REQUIRE((a = xbps_array_create())); + ATF_REQUIRE(xbps_array_add_cstring_nocopy(a, "xbps-git")); pstr = xbps_string_create(); res = xbps_find_pkg_orphans(&xh, a); @@ -82,7 +82,11 @@ ATF_TC_BODY(find_pkg_orphans_test, tc) xbps_string_append_cstring(pstr, pkgver); xbps_string_append_cstring(pstr, "\n"); } + xbps_object_release(a); + xbps_object_release(res); ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), expected_output); + xbps_object_release(pstr); + xbps_end(&xh); } ATF_TC(find_all_orphans_test); @@ -112,13 +116,16 @@ ATF_TC_BODY(find_all_orphans_test, tc) res = xbps_find_pkg_orphans(&xh, NULL); for (i = 0; i < xbps_array_count(res); i++) { pkgd = xbps_array_get(res, i); - xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); - xbps_string_append_cstring(pstr, pkgver); - xbps_string_append_cstring(pstr, "\n"); + ATF_REQUIRE(xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver)); + ATF_REQUIRE(xbps_string_append_cstring(pstr, pkgver)); + ATF_REQUIRE(xbps_string_append_cstring(pstr, "\n")); } printf("%s", xbps_string_cstring_nocopy(pstr)); + xbps_object_release(res); ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), expected_output_all); + xbps_object_release(pstr); + xbps_end(&xh); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/libxbps/pkgdb/main.c b/tests/xbps/libxbps/pkgdb/main.c index 6e12dca94..71254ed9f 100644 --- a/tests/xbps/libxbps/pkgdb/main.c +++ b/tests/xbps/libxbps/pkgdb/main.c @@ -66,6 +66,7 @@ ATF_TC_BODY(pkgdb_get_pkg_test, tc) ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); ATF_REQUIRE_STREQ(pkgver, "mixed-0.1_1"); + xbps_end(&xh); } ATF_TC(pkgdb_get_virtualpkg_test); @@ -108,6 +109,7 @@ ATF_TC_BODY(pkgdb_get_virtualpkg_test, tc) ATF_REQUIRE_EQ(xbps_object_type(pkgd), XBPS_TYPE_DICTIONARY); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); ATF_REQUIRE_STREQ(pkgver, "virtual-mixed-0.1_1"); + xbps_end(&xh); } ATF_TC(pkgdb_get_pkg_revdeps_test); @@ -144,6 +146,8 @@ ATF_TC_BODY(pkgdb_get_pkg_revdeps_test, tc) xbps_string_append_cstring(pstr, "\n"); } ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), eout); + xbps_object_release(pstr); + xbps_end(&xh); } ATF_TC(pkgdb_pkg_reverts_test); @@ -174,6 +178,7 @@ ATF_TC_BODY(pkgdb_pkg_reverts_test, tc) ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.3_1"), 1); ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.4_1"), 1); ATF_REQUIRE_EQ(xbps_pkg_reverts(pkgd, "reverts-0.5_1"), 0); + xbps_end(&xh); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/libxbps/plist_match/main.c b/tests/xbps/libxbps/plist_match/main.c index 0bba068f9..b2b8dd0e4 100644 --- a/tests/xbps/libxbps/plist_match/main.c +++ b/tests/xbps/libxbps/plist_match/main.c @@ -50,6 +50,7 @@ ATF_TC_BODY(match_string_test, tc) xbps_array_t a = array_init(); ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.0_1"), true); ATF_REQUIRE_EQ(xbps_match_string_in_array(a, "foo-2.1_1"), false); + xbps_object_release(a); } ATF_TC(match_pkgname_test); @@ -63,6 +64,7 @@ ATF_TC_BODY(match_pkgname_test, tc) xbps_array_t a = array_init(); ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "foo"), true); ATF_REQUIRE_EQ(xbps_match_pkgname_in_array(a, "baz"), false); + xbps_object_release(a); } ATF_TC(match_pkgpattern_test); @@ -76,6 +78,7 @@ ATF_TC_BODY(match_pkgpattern_test, tc) xbps_array_t a = array_init(); ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "foo>=1.0"), true); ATF_REQUIRE_EQ(xbps_match_pkgpattern_in_array(a, "blah<1.0"), false); + xbps_object_release(a); } ATF_TC(match_pkgdep_test); @@ -88,6 +91,7 @@ ATF_TC_BODY(match_pkgdep_test, tc) { xbps_array_t a = array_init(); ATF_REQUIRE_EQ(xbps_match_pkgdep_in_array(a, "foo-2.0_1"), true); + xbps_object_release(a); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/libxbps/plist_match_virtual/main.c b/tests/xbps/libxbps/plist_match_virtual/main.c index d887c0ba1..ae9065757 100644 --- a/tests/xbps/libxbps/plist_match_virtual/main.c +++ b/tests/xbps/libxbps/plist_match_virtual/main.c @@ -64,7 +64,7 @@ pkgdict_init(void) ATF_REQUIRE(d != NULL); a = provides_init(); - ATF_REQUIRE_EQ(xbps_dictionary_set(d, "provides", a), true); + ATF_REQUIRE_EQ(xbps_dictionary_set_and_rel(d, "provides", a), true); return d; } @@ -83,6 +83,7 @@ ATF_TC_BODY(match_virtual_pkg_dict_test, tc) ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon"), true); ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon>=0"), true); ATF_REQUIRE_EQ(xbps_match_virtual_pkg_in_dict(d, "cron-daemon>2"), false); + xbps_object_release(d); } ATF_TC(match_any_virtualpkg_rundeps_test); @@ -100,6 +101,9 @@ ATF_TC_BODY(match_any_virtualpkg_rundeps_test, tc) ATF_REQUIRE_EQ( xbps_match_any_virtualpkg_in_rundeps(rundeps, provides), true); + + xbps_object_release(provides); + xbps_object_release(rundeps); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/libxbps/shell/orphans_test.sh b/tests/xbps/libxbps/shell/orphans_test.sh index dddc13c66..f05237cf4 100644 --- a/tests/xbps/libxbps/shell/orphans_test.sh +++ b/tests/xbps/libxbps/shell/orphans_test.sh @@ -56,6 +56,101 @@ tc1_body() { } + +atf_test_case tc2 + +tc2_head() { + atf_set "descr" "Tests for pkg orphans: " +} + +tc2_body() { + mkdir -p repo pkg + + atf_expect_fail "orphans broken" + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" -D "A>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n C-1.0_1 -s "C pkg" -D "B>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n D-1.0_1 -s "D pkg" -D "C>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X-1.0_1 -s "X pkg" -D "X1>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X1-1.0_1 -s "X pkg" -D "X2>=0 X2>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X2-1.0_1 -s "X pkg" -D "X3>=0 X3>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X3-1.0_1 -s "X pkg" -D "X3>=0 X1>=0 X4>=0 X5>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X4-1.0_1 -s "X pkg" -D "X4>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X5-1.0_1 -s "X pkg" -D "X3>=0" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -d -a $PWD/*.xbps + cd .. + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -y A D X + atf_check -o ignore -e ignore -- xbps-remove -r root -Rdy X1 + atf_check -o inline:"ii X-1.0_1 X pkg\n" -- xbps-query -r root -l +} + +atf_test_case tc3 + +tc3_head() { + atf_set "descr" "Tests for pkg orphans: " +} + +tc3_body() { + mkdir -p repo pkg + + atf_expect_fail "orphans broken" + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" -D "A>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n C-1.0_1 -s "C pkg" -D "B>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n D-1.0_1 -s "D pkg" -D "C>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X-1.0_1 -s "X pkg" -D "X1>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X1-1.0_1 -s "X pkg" -D "X2>=0 X2>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X2-1.0_1 -s "X pkg" -D "X3>=0 X3>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X3-1.0_1 -s "X pkg" -D "X3>=0 X1>=0 X4>=0 X5>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X4-1.0_1 -s "X pkg" -D "X4>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n X5-1.0_1 -s "X pkg" -D "X3>=0" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -d -a $PWD/*.xbps + cd .. + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -y A D X + cat <<-EOF >expect + ii A-1.0_1 A pkg + ii B-1.0_1 B pkg + ii C-1.0_1 C pkg + ii D-1.0_1 D pkg + ii X-1.0_1 X pkg + ii X1-1.0_1 X pkg + ii X2-1.0_1 X pkg + ii X3-1.0_1 X pkg + ii X4-1.0_1 X pkg + ii X5-1.0_1 X pkg + EOF + atf_check -o file:expect -- xbps-query -r root -l + atf_check -o ignore -e ignore -- xbps-remove -r root -dy X + cat <<-EOF >expect + ii A-1.0_1 A pkg + ii B-1.0_1 B pkg + ii C-1.0_1 C pkg + ii D-1.0_1 D pkg + ii X1-1.0_1 X pkg + ii X2-1.0_1 X pkg + ii X3-1.0_1 X pkg + ii X4-1.0_1 X pkg + ii X5-1.0_1 X pkg + EOF + atf_check -o file:expect -- xbps-query -r root -l + atf_check -o ignore -e ignore -- xbps-remove -r root -Rdyo + cat <<-EOF >expect + ii A-1.0_1 A pkg + ii B-1.0_1 B pkg + ii C-1.0_1 C pkg + ii D-1.0_1 D pkg + EOF + atf_check -o file:expect -- xbps-query -r root -l +} + atf_init_test_cases() { atf_add_test_case tc1 + atf_add_test_case tc2 + atf_add_test_case tc3 } diff --git a/tests/xbps/libxbps/shell/replace_test.sh b/tests/xbps/libxbps/shell/replace_test.sh index 9d02067f3..6afe75261 100644 --- a/tests/xbps/libxbps/shell/replace_test.sh +++ b/tests/xbps/libxbps/shell/replace_test.sh @@ -20,21 +20,17 @@ replace_dups_body() { mkdir -p pkg_A/usr/bin pkg_B/usr/bin echo "A-1.0_1" > pkg_A/usr/bin/foo echo "B-1.0_1" > pkg_B/usr/bin/foo + cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "A>=0 A>=0" ../pkg_B - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "A>=0 A>=0" ../pkg_B + atf_check -o ignore -e ignore -- xbps-rindex -a $PWD/*.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A - atf_check_equal $? 0 - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B - atf_check_equal $? 0 - result=$(xbps-query -C xbps.d -r root -l|wc -l) - atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed + + atf_check -o ignore -e match:"replaces" -- xbps-install -r root --repository=$PWD/some_repo -yd A + atf_check -o ignore -e match:"installed package \`A-1\.0_1' will be replaced by \`B-1\.0_1', matched with \`A>=0'" -- xbps-install -r root --repository=$PWD/some_repo -yd B + atf_check -o inline:"ii B-1.0_1 B pkg\n" -- xbps-query -r root -l + atf_check -o inline:"installed\n" -- xbps-query -r root -p state B } atf_test_case replace_ntimes @@ -56,7 +52,7 @@ replace_ntimes_body() { cd .. atf_check -o ignore -e ignore -- \ - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A B C D + xbps-install -r root --repository=$PWD/some_repo -yd A B C D cd some_repo atf_check -o ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A @@ -72,7 +68,7 @@ replace_ntimes_body() { -o match:"C-1.1_1 update" \ -o match:"D-1.1_1 update" \ -e ignore \ - -- xbps-install -C xbps.d -r root --repository=$PWD/some_repo -dvyun + -- xbps-install -r root --repository=$PWD/some_repo -dvyun } atf_test_case self_replace @@ -89,16 +85,23 @@ self_replace_body() { cd some_repo atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "A>=0" --provides="A-1.0_1" ../pkg_B - atf_check -o ignore -- xbps-rindex -a $PWD/*.xbps + atf_check -o ignore -- xbps-rindex -a *.xbps cd .. - atf_check -o ignore -e ignore -- xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A - atf_check -o ignore -e ignore -- xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B - atf_check -e ignore \ - -o match:'A-1\.0_1: installed successfully.' \ - -o match:'B-1\.0_1: removed successfully.' \ - -- xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A - atf_check -o inline:"A-1.0_1\n" -- xbps-query -C xbps.d -r root -p pkgver A - atf_check -o inline:"installed\n" -- xbps-query -C xbps.d -r root -p state A + atf_check \ + -o match:'A-1\.0_1: installed successfully\.' \ + -e ignore \ + -- xbps-install -r root -R some_repo -yd A + atf_check \ + -o ignore \ + -e match:"installed package \`A-1\.0_1' will be replaced by \`B-1\.0_1', matched with \`A>=0'" \ + -- xbps-install -r root -R some_repo -yd B + atf_check \ + -o match:'A-1\.0_1: installed successfully\.' \ + -o match:'B-1\.0_1: removed successfully\.' \ + -e match:"installed package \`B-1\.0_1' will be replaced by \`A-1\.0_1', matched with \`A>=0'" \ + -- xbps-install -r root -R some_repo -yd A + atf_check -o inline:"A-1.0_1\n" -- xbps-query -r root -p pkgver A + atf_check -o inline:"installed\n" -- xbps-query -r root -p state A } atf_test_case replace_vpkg @@ -115,16 +118,16 @@ replace_vpkg_body() { atf_check_equal $? 0 xbps-create -A noarch -n catalyst-32bit-1.0_1 -s "catalyst 32bit pkg" \ --provides "libGL-32bit-1.0_1" --replaces "libGL-32bit>=0" \ - --dependencies "qt-32bit>=0" ../catalyst-32bit + -D "qt-32bit>=0" ../catalyst-32bit atf_check_equal $? 0 - xbps-create -A noarch -n qt-32bit-1.0_1 -s "qt 32bit pkg" --dependencies "libGL-32bit>=0" ../qt-32bit + xbps-create -A noarch -n qt-32bit-1.0_1 -s "qt 32bit pkg" -D "libGL-32bit>=0" ../qt-32bit atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd libGL-32bit + xbps-install -r root --repository=$PWD/some_repo -yd libGL-32bit atf_check_equal $? 0 - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd catalyst-32bit + xbps-install -r root --repository=$PWD/some_repo -yd catalyst-32bit atf_check_equal $? 0 } @@ -151,9 +154,9 @@ replace_pkg_files_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/repo -yvd libGL + xbps-install -r root --repository=$PWD/repo -yvd libGL atf_check_equal $? 0 - xbps-install -C xbps.d -r root --repository=$PWD/repo -yvd nvidia + xbps-install -r root --repository=$PWD/repo -yvd nvidia atf_check_equal $? 0 ls -l root/usr/lib result=$(readlink root/usr/lib/libGL.so) @@ -187,9 +190,9 @@ replace_pkg_files_unmodified_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/repo -yvd libGL + xbps-install -r root --repository=$PWD/repo -yvd libGL atf_check_equal $? 0 - xbps-install -C xbps.d -r root --repository=$PWD/repo -yvd nvidia + xbps-install -r root --repository=$PWD/repo -yvd nvidia atf_check_equal $? 0 ls -l root/usr/lib result=$(readlink root/usr/lib/libGL.so) @@ -219,7 +222,7 @@ replace_pkg_with_update_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A + xbps-install -r root --repository=$PWD/some_repo -yd A atf_check_equal $? 0 cd some_repo xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A @@ -227,11 +230,11 @@ replace_pkg_with_update_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yfd A B + xbps-install -r root --repository=$PWD/some_repo -yfd A B atf_check_equal $? 0 - result=$(xbps-query -C xbps.d -r root -l|wc -l) + result=$(xbps-query -r root -l|wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed + atf_check_equal $(xbps-query -r root -p state B) installed } atf_test_case replace_vpkg_with_update @@ -241,31 +244,23 @@ replace_vpkg_with_update_head() { } replace_vpkg_with_update_body() { - mkdir some_repo root - mkdir -p pkg_A/usr/bin pkg_B/usr/bin - echo "A-1.0_1" > pkg_A/usr/bin/foo - echo "B-1.0_1" > pkg_B/usr/bin/foo - cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" --replaces "awk>=0" --provides="awk-0_1" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "awk>=0" --provides="awk-0_1" ../pkg_B - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + mkdir -p repo pkg + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" --replaces "awk>=0" --provides="awk-0_1" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" --replaces "awk>=0" --provides="awk-0_1" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A - atf_check_equal $? 0 - cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "awk>=0" --provides "awk-0_1" ../pkg_A - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -yd A + + cd repo + atf_check -o ignore -e ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "awk>=0" --provides "awk-0_1" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yfd A B - atf_check_equal $? 0 - result=$(xbps-query -C xbps.d -r root -l|wc -l) - atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed + + atf_check -o ignore -e match:"package \`A-1\.1_1' in transaction will be replaced by \`B-1\.0_1', matched with \`awk>=0'" -- xbps-install -r root -R repo -yfd A B + atf_check -o inline:"ii B-1.0_1 B pkg\n" -- xbps-query -r root -l + atf_check -o inline:"installed\n" -- xbps-query -r root -p state B } atf_test_case replace_transitional_pkg @@ -275,34 +270,26 @@ replace_transitional_pkg_head() { } replace_transitional_pkg_body() { - mkdir some_repo root - mkdir -p pkg_A/usr/bin pkg_B/usr/bin empty - echo "A-1.0_1" > pkg_A/usr/bin/foo - echo "B-1.0_1" > pkg_B/usr/bin/foo - cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg_B - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + mkdir -p repo pkg + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B - atf_check_equal $? 0 - cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "B>=0" --provides "B-1.0_1" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" --dependencies="A>=0" ../empty - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -yd B + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "B>=0" --provides "B-1.0_1" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" -D "A>=0" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -d -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu - atf_check_equal $? 0 - result=$(xbps-query -r root -l | wc -l) - atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -ydu + atf_check -o inline:"ii A-1.1_1 A pkg\n" -- xbps-query -r root -l + atf_check -o inline:"installed\n" -- xbps-query -r root -p state A + atf_check -o empty -- xbps-query -r root -p automatic-install A } atf_test_case replace_transitional_pkg_automatically_installed @@ -324,24 +311,24 @@ replace_transitional_pkg_automatically_installed_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd --automatic A + xbps-install -r root --repository=$PWD/some_repo -yd --automatic A atf_check_equal $? 0 - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B + xbps-install -r root --repository=$PWD/some_repo -yd B atf_check_equal $? 0 cd some_repo xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "B>=0" --provides "B-1.0_1" ../pkg_A atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" --dependencies="A>=0" ../empty + xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" -D "A>=0" ../empty atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu + xbps-install -r root --repository=$PWD/some_repo -ydu atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p automatic-install A) "" } atf_test_case replace_transitional_pkg_automatically_installed2 @@ -363,22 +350,22 @@ replace_transitional_pkg_automatically_installed2_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd --automatic A B + xbps-install -r root --repository=$PWD/some_repo -yd --automatic A B atf_check_equal $? 0 cd some_repo xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "B>=0" --provides "B-1.0_1" ../pkg_A atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" --dependencies="A>=0" ../empty + xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" -D "A>=0" ../empty atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu + xbps-install -r root --repository=$PWD/some_repo -ydu atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "yes" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p automatic-install A) "yes" } atf_test_case replace_transitional_pkg_automatically_installed3 @@ -400,23 +387,23 @@ replace_transitional_pkg_automatically_installed3_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd --automatic B - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A + xbps-install -r root --repository=$PWD/some_repo -yd --automatic B + xbps-install -r root --repository=$PWD/some_repo -yd A atf_check_equal $? 0 cd some_repo xbps-create -A noarch -n A-1.1_1 -s "A pkg" --replaces "B>=0" --provides "B-1.0_1" ../pkg_A atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" --dependencies="A>=0" ../empty + xbps-create -A noarch -n B-1.1_1 -s "B pkg - transitional dummy package" -D "A>=0" ../empty atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu + xbps-install -r root --repository=$PWD/some_repo -ydu atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p automatic-install A) "" } atf_test_case replace_transitional_pkg_during_install @@ -432,17 +419,17 @@ replace_transitional_pkg_during_install_body() { cd some_repo xbps-create -A noarch -n A-1.0_1 -s "A pkg" --replaces "B>=0" ../pkg_A atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "A pkg - transitional dummy package" --dependencies="A>=0" ../empty + xbps-create -A noarch -n B-1.0_1 -s "A pkg - transitional dummy package" -D "A>=0" ../empty atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B + xbps-install -r root --repository=$PWD/some_repo -yd B atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) "" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p state B) "" } atf_test_case replace_automatically_installed_dep @@ -452,39 +439,29 @@ replace_automatically_installed_dep_head() { } replace_automatically_installed_dep_body() { - mkdir some_repo root - mkdir -p pkg_A/usr/bin pkg_B/usr/bin pkg_C/usr/bin empty - echo "A-1.0_1" > pkg_A/usr/bin/a - echo "B-1.0_1" > pkg_B/usr/bin/b - echo "C-1.0_1" > pkg_C/usr/bin/c - cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" --dependencies="B>=0 C>=0" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg_B - atf_check_equal $? 0 - xbps-create -A noarch -n C-1.0_1 -s "C pkg" ../pkg_C - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + mkdir -p repo pkg + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" -D "B>=0 C>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n C-1.0_1 -s "C pkg" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A - atf_check_equal $? 0 - cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg_B - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -yd A + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -d -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu - atf_check_equal $? 0 - result=$(xbps-query -r root -l | wc -l) - atf_check_equal $result 2 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install B) "yes" + + atf_check -o ignore -e ignore -- xbps-install -r root -R repo -ydu + arf_check -o inline: "" -- xbps-query -r root -l | wc -l + atf_check -o inline:"installed\n" -- xbps-query -r root -p state A + atf_check -o inline:"installed\n" -- xbps-query -r root -p state B + atf_check -o inline:"" -- xbps-query -r root -p automatic-install A + atf_check -o inline:"yes\n" -- xbps-query -r root -p automatic-install B } atf_test_case replace_automatically_installed_dep3 @@ -500,7 +477,7 @@ replace_automatically_installed_dep3_body() { echo "B-1.0_1" > pkg_B/usr/bin/b echo "C-1.0_1" > pkg_C/usr/bin/c cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" --dependencies="B>=0 C>=0" ../pkg_A + xbps-create -A noarch -n A-1.0_1 -s "A pkg" -D "B>=0 C>=0" ../pkg_A atf_check_equal $? 0 xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg_B atf_check_equal $? 0 @@ -509,24 +486,24 @@ replace_automatically_installed_dep3_body() { xbps-rindex -d -a $PWD/*.xbps a2tf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A C + xbps-install -r root --repository=$PWD/some_repo -yd A C atf_check_equal $? 0 cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" --dependencies="B>=0" ../pkg_A + xbps-create -A noarch -n A-1.1_1 -s "A pkg" -D "B>=0" ../pkg_A atf_check_equal $? 0 xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg_B atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu + xbps-install -r root --repository=$PWD/some_repo -ydu atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 2 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install B) "" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p state B) installed + atf_check_equal $(xbps-query -r root -p automatic-install A) "" + atf_check_equal $(xbps-query -r root -p automatic-install B) "" } atf_test_case replace_automatically_installed_dep2 @@ -536,39 +513,30 @@ replace_automatically_installed_dep2_head() { } replace_automatically_installed_dep2_body() { - mkdir some_repo root - mkdir -p pkg_A/usr/bin pkg_B/usr/bin pkg_C/usr/bin empty - echo "A-1.0_1" > pkg_A/usr/bin/a - echo "B-1.0_1" > pkg_B/usr/bin/b - echo "C-1.0_1" > pkg_C/usr/bin/c - cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" --dependencies="B>=0 C>=0" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg_B - atf_check_equal $? 0 - xbps-create -A noarch -n C-1.0_1 -s "C pkg" ../pkg_C - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + mkdir -p pkg repo + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.0_1 -s "A pkg" -D "B>=0 C>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n C-1.0_1 -s "C pkg" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A C - atf_check_equal $? 0 - cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" --dependencies="B>=0" ../pkg_A - atf_check_equal $? 0 - xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg_B - atf_check_equal $? 0 - xbps-rindex -d -a $PWD/*.xbps - atf_check_equal $? 0 + + atf_check -e ignore -o ignore -- xbps-install -r root -R repo -yd A C + + cd repo + atf_check -o ignore -- xbps-create -A noarch -n A-1.1_1 -s "A pkg" -D "B>=0" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg + atf_check -o ignore -e ignore -- xbps-rindex -a *.xbps cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu - atf_check_equal $? 0 - result=$(xbps-query -r root -l | wc -l) - atf_check_equal $result 2 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install B) "" + + atf_check -o ignore -e ignore xbps-install -r root -R repo -ydu + + atf_check -o inline:"ii A-1.1_1 A pkg\nii B-1.1_1 B pkg\n" -- xbps-query -r root -l + atf_check -o inline:"installed\n" -- xbps-query -r root -p state A + atf_check -o inline:"installed\n" -- xbps-query -r root -p state B + atf_check -o empty -- xbps-query -r root -p automatic-install A + atf_check -o empty -- xbps-query -r root -p automatic-install B } atf_test_case replace_automatically_installed_dep3 @@ -584,7 +552,7 @@ replace_automatically_installed_dep3_body() { echo "B-1.0_1" > pkg_B/usr/bin/b echo "C-1.0_1" > pkg_C/usr/bin/c cd some_repo - xbps-create -A noarch -n A-1.0_1 -s "A pkg" --dependencies="B>=0 C>=0" ../pkg_A + xbps-create -A noarch -n A-1.0_1 -s "A pkg" -D "B>=0 C>=0" ../pkg_A atf_check_equal $? 0 xbps-create -A noarch -n B-1.0_1 -s "B pkg" ../pkg_B atf_check_equal $? 0 @@ -593,24 +561,24 @@ replace_automatically_installed_dep3_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd A + xbps-install -r root --repository=$PWD/some_repo -yd A atf_check_equal $? 0 cd some_repo - xbps-create -A noarch -n A-1.1_1 -s "A pkg" --dependencies="B>=0" ../pkg_A + xbps-create -A noarch -n A-1.1_1 -s "A pkg" -D "B>=0" ../pkg_A atf_check_equal $? 0 xbps-create -A noarch -n B-1.1_1 -s "B pkg" --replaces "C>=0" --provides "C-1.0_1" ../pkg_B atf_check_equal $? 0 xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -ydu + xbps-install -r root --repository=$PWD/some_repo -ydu atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 2 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install A) "" - atf_check_equal $(xbps-query -C xbps.d -r root -p automatic-install B) "yes" + atf_check_equal $(xbps-query -r root -p state A) installed + atf_check_equal $(xbps-query -r root -p state B) installed + atf_check_equal $(xbps-query -r root -p automatic-install A) "" + atf_check_equal $(xbps-query -r root -p automatic-install B) "yes" } atf_test_case dont_replace_alternative_pkg_during_install @@ -631,12 +599,12 @@ dont_replace_alternative_pkg_during_install_body() { xbps-rindex -d -a $PWD/*.xbps atf_check_equal $? 0 cd .. - xbps-install -C xbps.d -r root --repository=$PWD/some_repo -yd B + xbps-install -r root --repository=$PWD/some_repo -yd B atf_check_equal $? 0 result=$(xbps-query -r root -l | wc -l) atf_check_equal $result 1 - atf_check_equal $(xbps-query -C xbps.d -r root -p state A) "" - atf_check_equal $(xbps-query -C xbps.d -r root -p state B) installed + atf_check_equal $(xbps-query -r root -p state A) "" + atf_check_equal $(xbps-query -r root -p state B) installed } atf_init_test_cases() { diff --git a/tests/xbps/libxbps/util/main.c b/tests/xbps/libxbps/util/main.c index bdfd5bb8f..7f80bd01c 100644 --- a/tests/xbps/libxbps/util/main.c +++ b/tests/xbps/libxbps/util/main.c @@ -23,6 +23,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *- */ +#include #include #include #include @@ -37,6 +38,7 @@ ATF_TC_HEAD(util_test, tc) ATF_TC_BODY(util_test, tc) { char name[XBPS_NAME_SIZE]; + char *s; ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-a"), false); ATF_CHECK_EQ(xbps_pkg_name(name, sizeof(name), "font-adobe-1"), false); @@ -81,18 +83,28 @@ ATF_TC_BODY(util_test, tc) ATF_REQUIRE_STREQ(name, "systemd"); ATF_CHECK_EQ(xbps_pkgpattern_name(name, sizeof(name), "*nslookup"), false); - ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64.xbps"), "x86_64"); - ATF_REQUIRE_STREQ(xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl"); - ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64-musl.xbps"), "x86_64-musl"); - ATF_REQUIRE_STREQ(xbps_binpkg_arch("foo-1.0_1.x86_64.xbps"), "x86_64"); + ATF_REQUIRE_STREQ((s = xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64.xbps")), "x86_64"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_arch("/path/to/foo-1.0_1.x86_64-musl.xbps")), "x86_64-musl"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_arch("foo-1.0_1.x86_64-musl.xbps")), "x86_64-musl"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_arch("foo-1.0_1.x86_64.xbps")), "x86_64"); + free(s); - ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64.xbps"), "foo-1.0_1"); - ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1"); - ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64.xbps"), "foo-1.0_1"); - ATF_REQUIRE_STREQ(xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64-musl.xbps"), "foo-1.0_1"); + ATF_REQUIRE_STREQ((s = xbps_binpkg_pkgver("foo-1.0_1.x86_64.xbps")), "foo-1.0_1"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_pkgver("foo-1.0_1.x86_64-musl.xbps")), "foo-1.0_1"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64.xbps")), "foo-1.0_1"); + free(s); + ATF_REQUIRE_STREQ((s = xbps_binpkg_pkgver("/path/to/foo-1.0_1.x86_64-musl.xbps")), "foo-1.0_1"); + free(s); - ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64.xbps"), NULL); - ATF_CHECK_EQ(xbps_binpkg_pkgver("foo-1.0.x86_64"), NULL); + ATF_CHECK_EQ((s = xbps_binpkg_pkgver("foo-1.0.x86_64.xbps")), NULL); + free(s); + ATF_CHECK_EQ((s = xbps_binpkg_pkgver("foo-1.0.x86_64")), NULL); + free(s); } ATF_TP_ADD_TCS(tp) diff --git a/tests/xbps/xbps-query/query_test.sh b/tests/xbps/xbps-query/query_test.sh index 6bfaf9743..fe9ec9313 100644 --- a/tests/xbps/xbps-query/query_test.sh +++ b/tests/xbps/xbps-query/query_test.sh @@ -82,33 +82,33 @@ search_prop_head() { } search_prop_body() { - mkdir -p root some_repo pkg_A pkg_B pkg_C + mkdir -p repo pkg - cd some_repo - atf_check -o ignore -- xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg_A - atf_check -o ignore -- xbps-create -A noarch -n bar-1.0_1 -s "bar pkg" ../pkg_B - atf_check -o ignore -- xbps-create -A noarch -n fizz-1.0_1 -s "fizz pkg" ../pkg_C + cd repo + atf_check -o ignore -- xbps-create -A noarch -n foo-1.0_1 -s "foo pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n bar-1.0_1 -s "bar pkg" ../pkg + atf_check -o ignore -- xbps-create -A noarch -n fizz-1.0_1 -s "fizz pkg" ../pkg atf_check -o ignore -- xbps-rindex -a $PWD/*.xbps cd .. - xbps-query -r root --repository=some_repo -S foo - xbps-query -r root --repository=some_repo -S bar - xbps-query -r root --repository=some_repo -S fizz + atf_check -o ignore -- xbps-query -r root --repository=repo -S foo + atf_check -o ignore -- xbps-query -r root --repository=repo -S bar + atf_check -o ignore -- xbps-query -r root --repository=repo -S fizz # regex error atf_check -e match:"ERROR: failed to compile regexp: \(:" -s exit:1 -- \ - xbps-query -r root --repository=some_repo --property pkgver --regex -s '(' + xbps-query -r root --repository=repo --property pkgver --regex -s '(' # repo mode atf_check -o match:"^foo-1\.0_1: foo-1\.0_1 \(.*\)$" -- \ - xbps-query -r root --repository=some_repo --property pkgver -s foo + xbps-query -r root --repository=repo --property pkgver -s foo atf_check \ -o match:"^foo-1\.0_1: foo-1\.0_1 \(.*\)$" \ -o match:"^fizz-1\.0_1: fizz-1\.0_1 \(.*\)$" \ - -- xbps-query -r root --repository=some_repo --property pkgver -s f + -- xbps-query -r root --repository=repo --property pkgver -s f - atf_check -o ignore -- \ - xbps-install -r root --repository=some_repo -y foo + atf_check -o match:"foo-1\.0_1: installed successfully\." -- \ + xbps-install -r root -R repo -y foo # installed mode atf_check -o match:"^foo-1\.0_1: foo-1\.0_1$" -- \