xbps-repo: properly remove (no)arch old entry/binpkg from index.

This commit is contained in:
Juan RP 2012-07-21 21:50:16 +02:00
parent f7a5c55bc7
commit 29f9724ba0

View File

@ -154,7 +154,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
struct stat st; struct stat st;
const char *pkgname, *version, *regver, *oldfilen, *oldpkgver; const char *pkgname, *version, *regver, *oldfilen, *oldpkgver;
const char *arch, *oldarch; const char *arch, *oldarch;
char *sha256, *filen, *repodir, *buf; char *sha256, *filen, *repodir, *buf, *buf2;
char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL; char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL;
char *plist_lock = NULL; char *plist_lock = NULL;
int i, ret = 0, rv = 0, fdlock = -1; 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. * pass to the next one.
*/ */
curpkgd = 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 (curpkgd == NULL) {
if (errno && errno != ENOENT) { if (errno && errno != ENOENT) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
@ -231,6 +231,12 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
goto out; goto out;
} }
} else { } 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, prop_dictionary_get_cstring_nocopy(curpkgd,
"version", &regver); "version", &regver);
ret = xbps_cmpver(version, regver); 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 * Index version is greater, remove current
* package. * 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) { if (rv != 0) {
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(tmpfilen); free(tmpfilen);
free(buf);
goto out; goto out;
} }
buf = xbps_xasprintf("`%s-%s' (%s)", printf("index: removed obsolete binpkg %s.\n", buf);
pkgname, version, arch);
assert(buf);
printf("index: removed obsolete binpkg %s.\n",
buf);
free(buf); free(buf);
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(tmpfilen); free(tmpfilen);
newpkgd = NULL; newpkgd = NULL;
filen = NULL; filen = buf = NULL;
continue; continue;
} }
/* /*
* Current package version is greater than * Current package version is greater than
* index version. * index version.
*/ */
prop_dictionary_get_cstring_nocopy(curpkgd, buf = xbps_xasprintf("`%s' (%s)", oldpkgver, oldarch);
"filename", &oldfilen); assert(buf);
prop_dictionary_get_cstring_nocopy(curpkgd, buf2 = strdup(oldpkgver);
"pkgver", &oldpkgver); assert(buf2);
prop_dictionary_get_cstring_nocopy(curpkgd,
"architecture", &oldarch);
if ((buf = strdup(oldpkgver)) == NULL) {
prop_object_release(newpkgd);
free(tmpfilen);
rv = ENOMEM;
goto out;
}
rv = remove_oldpkg(repodir, oldarch, oldfilen); rv = remove_oldpkg(repodir, oldarch, oldfilen);
if (rv != 0) { if (rv != 0) {
free(buf); free(buf);
free(buf2);
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(tmpfilen); free(tmpfilen);
goto out; goto out;
} }
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx, if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
buf, oldarch)) { buf2, NULL)) {
xbps_error_printf("failed to remove `%s' " xbps_error_printf("failed to remove `%s' "
"from plist index: %s\n", buf, "from plist index: %s\n", buf,
strerror(errno)); strerror(errno));
rv = errno; rv = errno;
free(buf); free(buf);
free(buf2);
prop_object_release(newpkgd); prop_object_release(newpkgd);
free(tmpfilen); free(tmpfilen);
goto out; goto out;
} }
printf("index: removed obsolete entry/binpkg `%s' " free(buf2);
"(%s).\n", buf, arch); printf("index: removed obsolete entry/binpkg %s.\n", buf);
free(buf); free(buf);
buf = buf2 = NULL;
} }
/* /*
* We have the dictionary now, add the required * We have the dictionary now, add the required