xbps-repo: remove old binpkg symlinks too, fix index-files.
This commit is contained in:
@ -76,8 +76,11 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir)
|
|||||||
/*
|
/*
|
||||||
* Iterate over index-files array to find obsolete entries.
|
* Iterate over index-files array to find obsolete entries.
|
||||||
*/
|
*/
|
||||||
for (x = 0; x < prop_array_count(idx); x++) {
|
obsoletes = prop_array_create();
|
||||||
obj = prop_array_get(idx, x);
|
assert(obsoletes);
|
||||||
|
|
||||||
|
for (x = 0; x < prop_array_count(idxfiles); x++) {
|
||||||
|
obj = prop_array_get(idxfiles, x);
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &ipkgver);
|
prop_dictionary_get_cstring_nocopy(obj, "pkgver", &ipkgver);
|
||||||
prop_dictionary_get_cstring_nocopy(obj, "architecture", &iarch);
|
prop_dictionary_get_cstring_nocopy(obj, "architecture", &iarch);
|
||||||
if (xbps_find_pkg_in_array_by_pkgver(xhp, idx, ipkgver, iarch)) {
|
if (xbps_find_pkg_in_array_by_pkgver(xhp, idx, ipkgver, iarch)) {
|
||||||
|
@ -109,6 +109,39 @@ again:
|
|||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
remove_oldpkg(const char *repodir, const char *arch, const char *file)
|
||||||
|
{
|
||||||
|
char *filepath;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
/* Remove real binpkg */
|
||||||
|
filepath = xbps_xasprintf("%s/%s/%s", repodir, arch, file);
|
||||||
|
assert(filepath);
|
||||||
|
if (remove(filepath) == -1) {
|
||||||
|
rv = errno;
|
||||||
|
xbps_error_printf("failed to remove old binpkg `%s': %s\n",
|
||||||
|
file, strerror(rv));
|
||||||
|
free(filepath);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
free(filepath);
|
||||||
|
|
||||||
|
/* Remove symlink to binpkg */
|
||||||
|
filepath = xbps_xasprintf("%s/%s", repodir, file);
|
||||||
|
assert(filepath);
|
||||||
|
if (remove(filepath) == -1) {
|
||||||
|
rv = errno;
|
||||||
|
xbps_error_printf("failed to remove old binpkg `%s': %s\n",
|
||||||
|
file, strerror(rv));
|
||||||
|
free(filepath);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
free(filepath);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Adds a binary package into the index and removes old binary package
|
* Adds a binary package into the index and removes old binary package
|
||||||
* and entry when it's necessary.
|
* and entry when it's necessary.
|
||||||
@ -121,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, *oldfilepath, *buf;
|
char *sha256, *filen, *repodir, *buf;
|
||||||
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;
|
||||||
@ -204,8 +237,8 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
/* Same version */
|
/* Same version */
|
||||||
fprintf(stderr, "index: skipping `%s-%s' "
|
fprintf(stderr, "index: skipping `%s-%s' "
|
||||||
"(%s), `%s-%s' already registered.\n",
|
"(%s), already registered.\n",
|
||||||
pkgname, version, arch, pkgname, regver);
|
pkgname, version, arch);
|
||||||
prop_object_release(newpkgd);
|
prop_object_release(newpkgd);
|
||||||
free(tmpfilen);
|
free(tmpfilen);
|
||||||
newpkgd = NULL;
|
newpkgd = NULL;
|
||||||
@ -216,23 +249,15 @@ 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.
|
||||||
*/
|
*/
|
||||||
oldfilepath = xbps_xasprintf("%s/%s/%s",
|
rv = remove_oldpkg(repodir, arch, filen);
|
||||||
repodir, arch, filen);
|
if (rv != 0) {
|
||||||
assert(oldfilepath != NULL);
|
|
||||||
if (remove(oldfilepath) == -1) {
|
|
||||||
rv = errno;
|
|
||||||
xbps_error_printf("failed to remove "
|
|
||||||
"old binpkg `%s': %s\n",
|
|
||||||
oldfilepath, strerror(rv));
|
|
||||||
prop_object_release(newpkgd);
|
prop_object_release(newpkgd);
|
||||||
free(tmpfilen);
|
free(tmpfilen);
|
||||||
free(oldfilepath);
|
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
free(oldfilepath);
|
|
||||||
buf = xbps_xasprintf("`%s-%s' (%s)",
|
buf = xbps_xasprintf("`%s-%s' (%s)",
|
||||||
pkgname, version, arch);
|
pkgname, version, arch);
|
||||||
assert(buf != NULL);
|
assert(buf);
|
||||||
printf("index: removed obsolete binpkg %s.\n",
|
printf("index: removed obsolete binpkg %s.\n",
|
||||||
buf);
|
buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
@ -254,30 +279,18 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
|||||||
"architecture", &oldarch);
|
"architecture", &oldarch);
|
||||||
|
|
||||||
if ((buf = strdup(oldpkgver)) == NULL) {
|
if ((buf = strdup(oldpkgver)) == NULL) {
|
||||||
|
prop_object_release(newpkgd);
|
||||||
|
free(tmpfilen);
|
||||||
rv = ENOMEM;
|
rv = ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
oldfilepath = xbps_xasprintf("%s/%s/%s",
|
rv = remove_oldpkg(repodir, oldarch, oldfilen);
|
||||||
repodir, oldarch, oldfilen);
|
if (rv != 0) {
|
||||||
if (oldfilepath == NULL) {
|
|
||||||
rv = errno;
|
|
||||||
free(buf);
|
free(buf);
|
||||||
prop_object_release(newpkgd);
|
prop_object_release(newpkgd);
|
||||||
free(tmpfilen);
|
free(tmpfilen);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (remove(oldfilepath) == -1) {
|
|
||||||
rv = errno;
|
|
||||||
xbps_error_printf("failed to remove old "
|
|
||||||
"package file `%s': %s\n", oldfilepath,
|
|
||||||
strerror(errno));
|
|
||||||
free(oldfilepath);
|
|
||||||
free(buf);
|
|
||||||
prop_object_release(newpkgd);
|
|
||||||
free(tmpfilen);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
free(oldfilepath);
|
|
||||||
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
|
if (!xbps_remove_pkg_from_array_by_pkgver(xhp, idx,
|
||||||
buf, oldarch)) {
|
buf, oldarch)) {
|
||||||
xbps_error_printf("failed to remove `%s' "
|
xbps_error_printf("failed to remove `%s' "
|
||||||
|
Reference in New Issue
Block a user