From 29f9724ba0dc3e1b7de61c5b78443ba06c3a63f1 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Sat, 21 Jul 2012 21:50:16 +0200 Subject: [PATCH] xbps-repo: properly remove (no)arch old entry/binpkg from index. --- bin/xbps-repo/index.c | 50 +++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index 5b2fd821..89b6f4d6 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -154,7 +154,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) struct stat st; const char *pkgname, *version, *regver, *oldfilen, *oldpkgver; const char *arch, *oldarch; - char *sha256, *filen, *repodir, *buf; + char *sha256, *filen, *repodir, *buf, *buf2; char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL; char *plist_lock = NULL; int i, ret = 0, rv = 0, fdlock = -1; @@ -222,7 +222,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) * pass to the next one. */ curpkgd = - xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, arch); + xbps_find_pkg_in_array_by_name(xhp, idx, pkgname, NULL); if (curpkgd == NULL) { if (errno && errno != ENOENT) { prop_object_release(newpkgd); @@ -231,6 +231,12 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) goto out; } } else { + prop_dictionary_get_cstring_nocopy(curpkgd, + "filename", &oldfilen); + prop_dictionary_get_cstring_nocopy(curpkgd, + "pkgver", &oldpkgver); + prop_dictionary_get_cstring_nocopy(curpkgd, + "architecture", &oldarch); prop_dictionary_get_cstring_nocopy(curpkgd, "version", ®ver); ret = xbps_cmpver(version, regver); @@ -249,62 +255,56 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) * Index version is greater, remove current * package. */ - rv = remove_oldpkg(repodir, arch, filen); + buf = xbps_xasprintf("`%s' (%s)", + oldpkgver, oldarch); + assert(buf); + rv = remove_oldpkg(repodir, oldarch, oldfilen); if (rv != 0) { prop_object_release(newpkgd); free(tmpfilen); + free(buf); goto out; } - buf = xbps_xasprintf("`%s-%s' (%s)", - pkgname, version, arch); - assert(buf); - printf("index: removed obsolete binpkg %s.\n", - buf); + printf("index: removed obsolete binpkg %s.\n", buf); free(buf); prop_object_release(newpkgd); free(tmpfilen); newpkgd = NULL; - filen = NULL; + filen = buf = NULL; continue; } /* * Current package version is greater than * index version. */ - prop_dictionary_get_cstring_nocopy(curpkgd, - "filename", &oldfilen); - prop_dictionary_get_cstring_nocopy(curpkgd, - "pkgver", &oldpkgver); - prop_dictionary_get_cstring_nocopy(curpkgd, - "architecture", &oldarch); - - if ((buf = strdup(oldpkgver)) == NULL) { - prop_object_release(newpkgd); - free(tmpfilen); - rv = ENOMEM; - goto out; - } + buf = xbps_xasprintf("`%s' (%s)", oldpkgver, oldarch); + assert(buf); + buf2 = strdup(oldpkgver); + assert(buf2); rv = remove_oldpkg(repodir, oldarch, oldfilen); if (rv != 0) { free(buf); + free(buf2); prop_object_release(newpkgd); free(tmpfilen); goto out; } if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx, - buf, oldarch)) { + buf2, NULL)) { xbps_error_printf("failed to remove `%s' " "from plist index: %s\n", buf, strerror(errno)); rv = errno; free(buf); + free(buf2); prop_object_release(newpkgd); free(tmpfilen); goto out; } - printf("index: removed obsolete entry/binpkg `%s' " - "(%s).\n", buf, arch); + free(buf2); + printf("index: removed obsolete entry/binpkg %s.\n", buf); free(buf); + buf = buf2 = NULL; } /* * We have the dictionary now, add the required