From fa7afa796553761019ee514ba6cecfa313e8b30f Mon Sep 17 00:00:00 2001 From: Alessio Sergi Date: Wed, 19 Oct 2016 17:31:21 +0200 Subject: [PATCH] xbps: patches from master to fix issues with xbps-alternatives https://github.com/voidlinux/xbps/pull/193 --- srcpkgs/xbps-static/template | 2 +- srcpkgs/xbps/patches/issue-193-1.patch | 78 ++++++++++++ srcpkgs/xbps/patches/issue-193-2.patch | 169 +++++++++++++++++++++++++ srcpkgs/xbps/template | 2 +- 4 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 srcpkgs/xbps/patches/issue-193-1.patch create mode 100644 srcpkgs/xbps/patches/issue-193-2.patch diff --git a/srcpkgs/xbps-static/template b/srcpkgs/xbps-static/template index e5b4cde97db..89040601c74 100644 --- a/srcpkgs/xbps-static/template +++ b/srcpkgs/xbps-static/template @@ -3,7 +3,7 @@ # NOTE: keep this package synchronized with "srcpkgs/xbps". pkgname=xbps-static version=0.51 -revision=8 +revision=12 build_style=configure short_desc="The XBPS package system utilities - static binaries" maintainer="Juan RP " diff --git a/srcpkgs/xbps/patches/issue-193-1.patch b/srcpkgs/xbps/patches/issue-193-1.patch new file mode 100644 index 00000000000..75ed9bff49f --- /dev/null +++ b/srcpkgs/xbps/patches/issue-193-1.patch @@ -0,0 +1,78 @@ +--- lib/package_alternatives.c.orig ++++ lib/package_alternatives.c +@@ -249,8 +249,8 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname, + const char *group) + { + xbps_array_t allkeys; +- xbps_dictionary_t alternatives, pkg_alternatives, pkgd; +- const char *pkgver; ++ xbps_dictionary_t alternatives, pkg_alternatives, pkgd, prevpkgd, prevpkg_alts; ++ const char *pkgver, *prevpkgname; + int rv = 0; + + assert(xhp); +@@ -289,6 +289,20 @@ xbps_alternatives_set(struct xbps_handle *xhp, const char *pkgname, + if (array == NULL) + continue; + ++ /* remove symlinks from previous alternative */ ++ xbps_array_get_cstring_nocopy(array, 0, &prevpkgname); ++ if (prevpkgname && strcmp(pkgname, prevpkgname) != 0) { ++ if ((prevpkgd = xbps_pkgdb_get_pkg(xhp, prevpkgname)) && ++ (prevpkg_alts = xbps_dictionary_get(prevpkgd, "alternatives")) && ++ xbps_dictionary_count(prevpkg_alts)) { ++ rv = remove_symlinks(xhp, ++ xbps_dictionary_get(prevpkg_alts, keyname), ++ keyname); ++ if (rv != 0) ++ break; ++ } ++ } ++ + /* put this alternative group at the head */ + xbps_remove_string_from_array(array, pkgname); + kstr = xbps_string_create_cstring(pkgname); +--- tests/xbps/xbps-alternatives/main.sh.orig ++++ tests/xbps/xbps-alternatives/main.sh +@@ -429,6 +429,35 @@ update_pkgs_body() { + atf_check_equal $rv 0 + } + ++atf_test_case less_entries ++ ++less_entries_pkgs_head() { ++ atf_set "descr" "xbps-alternatives: remove symlinks not provided by the new alternative" ++} ++less_entries_body() { ++ mkdir -p repo pkg_A/usr/bin pkg_B/usr/bin ++ touch pkg_A/usr/bin/A1 pkg_A/usr/bin/A2 pkg_B/usr/bin/B1 ++ cd repo ++ xbps-create -A noarch -n A-1.1_1 -s "A pkg" --alternatives "1:1:/usr/bin/A1 1:2:/usr/bin/A2" ../pkg_A ++ atf_check_equal $? 0 ++ xbps-create -A noarch -n B-1.1_1 -s "B pkg" --alternatives "1:1:/usr/bin/B1" ../pkg_B ++ atf_check_equal $? 0 ++ xbps-rindex -d -a $PWD/*.xbps ++ atf_check_equal $? 0 ++ cd .. ++ ++ xbps-install -r root --repository=repo -ydv A B ++ atf_check_equal $? 0 ++ ++ xbps-alternatives -r root -s B ++ atf_check_equal $? 0 ++ ++ rv=1 ++ [ -e root/usr/bin/2 ] || rv=0 ++ atf_check_equal $rv 0 ++} ++ ++ + atf_init_test_cases() { + atf_add_test_case register_one + atf_add_test_case register_one_dangling +@@ -441,4 +470,5 @@ atf_init_test_cases() { + atf_add_test_case set_pkg + atf_add_test_case set_pkg_group + atf_add_test_case update_pkgs ++ atf_add_test_case less_entries + } diff --git a/srcpkgs/xbps/patches/issue-193-2.patch b/srcpkgs/xbps/patches/issue-193-2.patch new file mode 100644 index 00000000000..8b2825490c2 --- /dev/null +++ b/srcpkgs/xbps/patches/issue-193-2.patch @@ -0,0 +1,169 @@ +--- lib/package_alternatives.c.orig ++++ lib/package_alternatives.c +@@ -145,99 +145,84 @@ remove_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) + static int + create_symlinks(struct xbps_handle *xhp, xbps_array_t a, const char *grname) + { +- unsigned int i, cnt; ++ int rv; ++ unsigned int i, n; ++ char *alternative, *tok1, *tok2, *linkpath, *target, *dir, *p; + +- cnt = xbps_array_count(a); +- for (i = 0; i < cnt; i++) { +- xbps_string_t str; +- char *tgt_dup, *tgt_dir, *lnk_dup, *lnk_dir; +- char *l, *lnk, *tgt = NULL; +- const char *tgt0; +- int rv; ++ n = xbps_array_count(a); + +- str = xbps_array_get(a, i); +- l = left(xbps_string_cstring_nocopy(str)); +- assert(l); +- tgt0 = right(xbps_string_cstring_nocopy(str)); +- assert(tgt0); +- /* always create target dir, for dangling symlinks */ +- tgt_dup = strdup(tgt0); +- assert(tgt_dup); +- tgt_dir = dirname(tgt_dup); +- if (strcmp(tgt_dir, ".")) { +- tgt = xbps_xasprintf("%s%s", xhp->rootdir, tgt_dir); +- if (xbps_mkpath(tgt, 0755) != 0) { +- if (errno != EEXIST) { +- rv = errno; +- xbps_dbg_printf(xhp, "failed to create " +- "target dir '%s' for group '%s': %s\n", +- tgt, grname, strerror(errno)); +- free(tgt_dup); +- free(tgt); +- free(l); +- return rv; +- } +- } +- free(tgt); ++ for (i = 0; i < n; i++) { ++ alternative = xbps_string_cstring(xbps_array_get(a, i)); ++ ++ if (!(tok1 = strtok(alternative, ":")) || ++ !(tok2 = strtok(NULL, ":"))) { ++ free(alternative); ++ return -1; + } +- /* always create link dir, for dangling symlinks */ +- lnk_dup = strdup(l); +- assert(lnk_dup); +- lnk_dir = dirname(lnk_dup); +- if (strcmp(lnk_dir, ".")) { +- lnk = xbps_xasprintf("%s%s", xhp->rootdir, lnk_dir); +- if (xbps_mkpath(lnk, 0755) != 0) { +- if (errno != EEXIST) { +- rv = errno; +- xbps_dbg_printf(xhp, "failed to create symlink" +- "dir '%s' for group '%s': %s\n", +- lnk, grname, strerror(errno)); +- free(tgt_dup); +- free(lnk_dup); +- free(lnk); +- free(l); +- return rv; +- } +- } +- free(lnk); ++ target = strdup(tok2); ++ dir = dirname(tok2); ++ ++ /* add target dir to relative links */ ++ if (tok1[0] != '/') ++ linkpath = xbps_xasprintf("%s/%s/%s", xhp->rootdir, dir, tok1); ++ else ++ linkpath = xbps_xasprintf("%s/%s", xhp->rootdir, tok1); ++ ++ /* create target directory, necessary for dangling symlinks */ ++ dir = xbps_xasprintf("%s/%s", xhp->rootdir, dir); ++ if (strcmp(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { ++ rv = errno; ++ xbps_dbg_printf(xhp, ++ "failed to create target dir '%s' for group '%s': %s\n", ++ dir, grname, strerror(errno)); ++ free(dir); ++ goto err; + } +- free(lnk_dup); +- +- if (l[0] != '/') { +- lnk = xbps_xasprintf("%s%s/%s", xhp->rootdir, tgt_dir, l); +- free(tgt_dup); +- tgt_dup = strdup(tgt0); +- assert(tgt_dup); +- tgt = strdup(basename(tgt_dup)); +- free(tgt_dup); +- } else { +- free(tgt_dup); +- tgt = strdup(tgt0); +- lnk = xbps_xasprintf("%s%s", xhp->rootdir, l); ++ free(dir); ++ ++ /* create link directory, necessary for dangling symlinks */ ++ p = strdup(linkpath); ++ dir = dirname(p); ++ if (strcmp(dir, ".") && xbps_mkpath(dir, 0755) && errno != EEXIST) { ++ rv = errno; ++ xbps_dbg_printf(xhp, ++ "failed to create symlink dir '%s' for group '%s': %s\n", ++ dir, grname, strerror(errno)); ++ free(p); ++ goto err; + } ++ free(p); ++ + xbps_set_cb_state(xhp, XBPS_STATE_ALTGROUP_LINK_ADDED, 0, NULL, +- "Creating '%s' alternatives group symlink: %s -> %s", grname, l, tgt); +- unlink(lnk); +- if (tgt[0] == '/') { +- tgt_dup = relpath(lnk + strlen(xhp->rootdir), tgt); +- free(tgt); +- tgt = tgt_dup; ++ "Creating '%s' alternatives group symlink: %s -> %s", ++ grname, tok1, target); ++ ++ if (target[0] == '/') { ++ p = relpath(linkpath + strlen(xhp->rootdir), target); ++ free(target); ++ target = p; + } +- if ((rv = symlink(tgt, lnk)) != 0) { +- xbps_dbg_printf(xhp, "failed to create alt symlink '%s'" +- "for group '%s': %s\n", lnk, grname, +- strerror(errno)); +- free(tgt); +- free(lnk); +- free(l); +- return rv; ++ ++ unlink(linkpath); ++ if ((rv = symlink(target, linkpath)) != 0) { ++ xbps_dbg_printf(xhp, ++ "failed to create alt symlink '%s' for group '%s': %s\n", ++ linkpath, grname, strerror(errno)); ++ goto err; + } +- free(tgt); +- free(lnk); +- free(l); ++ ++ free(alternative); ++ free(target); ++ free(linkpath); + } + + return 0; ++ ++err: ++ free(alternative); ++ free(target); ++ free(linkpath); ++ return rv; + } + + int diff --git a/srcpkgs/xbps/template b/srcpkgs/xbps/template index b3fab42dd9b..80b1f9f3606 100644 --- a/srcpkgs/xbps/template +++ b/srcpkgs/xbps/template @@ -1,7 +1,7 @@ # Template file for 'xbps' pkgname=xbps version=0.51 -revision=11 +revision=12 bootstrap=yes build_style=configure short_desc="The XBPS package system utilities"