xbps-repo: new 'remove-obsoletes' target to remove obsolete pkgs in a local repo.
This commit is contained in:
@@ -36,95 +36,6 @@
|
||||
#include <xbps_api.h>
|
||||
#include "defs.h"
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static int
|
||||
remove_obsolete_binpkgs(struct xbps_handle *xhp,
|
||||
prop_array_t idx,
|
||||
const char *repodir)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
DIR *dirp;
|
||||
struct dirent *dp;
|
||||
const char *pkgver, *arch;
|
||||
int rv = 0;
|
||||
|
||||
if (chdir(repodir) == -1) {
|
||||
fprintf(stderr, "cannot chdir to %s: %s\n",
|
||||
repodir, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
if ((dirp = opendir(repodir)) == NULL) {
|
||||
fprintf(stderr, "failed to open %s: %s\n",
|
||||
repodir, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
while ((dp = readdir(dirp))) {
|
||||
if (strcmp(dp->d_name, "..") == 0)
|
||||
continue;
|
||||
if (!strstr(dp->d_name, ".xbps"))
|
||||
continue;
|
||||
|
||||
pkgd = xbps_dictionary_metadata_plist_by_url(dp->d_name,
|
||||
"./props.plist");
|
||||
if (pkgd == NULL) {
|
||||
fprintf(stderr, "failed to read metadata for `%s',"
|
||||
" skipping!\n", dp->d_name);
|
||||
continue;
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
|
||||
/*
|
||||
* If binpkg is not registered in index, remove binpkg.
|
||||
*/
|
||||
if (!xbps_find_pkg_in_array_by_pkgver(xhp, idx, pkgver, arch)) {
|
||||
rv = remove_oldpkg(repodir, arch, dp->d_name);
|
||||
if (rv != 0) {
|
||||
fprintf(stderr, "index: failed to remove "
|
||||
"package `%s': %s\n", dp->d_name,
|
||||
strerror(rv));
|
||||
prop_object_release(pkgd);
|
||||
break;
|
||||
}
|
||||
printf("Removed obsolete package `%s'.\n", dp->d_name);
|
||||
}
|
||||
prop_object_release(pkgd);
|
||||
}
|
||||
(void)closedir(dirp);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
* Removes stalled pkg entries in repository's index.plist file, if any
|
||||
* binary package cannot be read (unavailable, not enough perms, etc).
|
||||
@@ -187,13 +98,10 @@ again:
|
||||
}
|
||||
free(binpkg);
|
||||
}
|
||||
rv = remove_obsolete_binpkgs(xhp, array, repodir);
|
||||
if (rv != 0)
|
||||
goto out;
|
||||
|
||||
if (flush && !prop_array_externalize_to_zfile(array, plist))
|
||||
if (flush && !prop_array_externalize_to_zfile(array, plist)) {
|
||||
rv = errno;
|
||||
|
||||
goto out;
|
||||
}
|
||||
printf("index: %u packages registered.\n", prop_array_count(array));
|
||||
out:
|
||||
free(plist);
|
||||
@@ -316,7 +224,8 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
||||
buf = xbps_xasprintf("`%s' (%s)",
|
||||
oldpkgver, oldarch);
|
||||
assert(buf);
|
||||
rv = remove_oldpkg(repodir, oldarch, oldfilen);
|
||||
rv = repo_remove_pkg(repodir,
|
||||
oldarch, oldfilen);
|
||||
if (rv != 0) {
|
||||
prop_object_release(newpkgd);
|
||||
free(tmpfilen);
|
||||
@@ -337,7 +246,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv)
|
||||
assert(buf);
|
||||
buf2 = strdup(oldpkgver);
|
||||
assert(buf2);
|
||||
rv = remove_oldpkg(repodir, oldarch, oldfilen);
|
||||
rv = repo_remove_pkg(repodir, oldarch, oldfilen);
|
||||
if (rv != 0) {
|
||||
free(buf);
|
||||
free(buf2);
|
||||
|
||||
Reference in New Issue
Block a user