xbps-remove: make -O also remove signature files and skip pkgs with unmatched arch.

This commit is contained in:
Juan RP 2014-02-07 03:50:30 +01:00
parent 9fe6b363d6
commit f97ea2b915
2 changed files with 34 additions and 12 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.32 (???): xbps-0.32 (???):
* xbps-remove(8): -O now also remove obsolete pkg signatures from
cachedir, and ignores pkgs of other architectures.
* xbps-rindex(8): set correct permissions to the POSIX semaphore * xbps-rindex(8): set correct permissions to the POSIX semaphore
by clearing file permission bits before its creation. by clearing file permission bits before its creation.

View File

@ -1,5 +1,5 @@
/*- /*-
* Copyright (c) 2008-2013 Juan Romero Pardines. * Copyright (c) 2008-2014 Juan Romero Pardines.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -122,8 +122,8 @@ cachedir_clean(struct xbps_handle *xhp)
xbps_dictionary_t pkg_propsd, repo_pkgd; xbps_dictionary_t pkg_propsd, repo_pkgd;
DIR *dirp; DIR *dirp;
struct dirent *dp; struct dirent *dp;
const char *pkgver, *rsha256; const char *pkgver, *arch, *rsha256;
char *binpkg, *ext; char *binpkg, *binpkgsig, *ext;
int rv = 0; int rv = 0;
if ((dirp = opendir(xhp->cachedir)) == NULL) if ((dirp = opendir(xhp->cachedir)) == NULL)
@ -138,7 +138,7 @@ cachedir_clean(struct xbps_handle *xhp)
if ((ext = strrchr(dp->d_name, '.')) == NULL) if ((ext = strrchr(dp->d_name, '.')) == NULL)
continue; continue;
if (strcmp(ext, ".xbps")) { if (strcmp(ext, ".xbps")) {
printf("ignoring unknown file: %s\n", dp->d_name); xbps_dbg_printf(xhp, "ignoring unknown file: %s\n", dp->d_name);
continue; continue;
} }
/* Internalize props.plist dictionary from binary pkg */ /* Internalize props.plist dictionary from binary pkg */
@ -152,34 +152,53 @@ cachedir_clean(struct xbps_handle *xhp)
rv = errno; rv = errno;
break; break;
} }
xbps_dictionary_get_cstring_nocopy(pkg_propsd, "architecture", &arch);
xbps_dictionary_get_cstring_nocopy(pkg_propsd, "pkgver", &pkgver); xbps_dictionary_get_cstring_nocopy(pkg_propsd, "pkgver", &pkgver);
if (!xbps_pkg_arch_match(xhp, arch, NULL)) {
xbps_dbg_printf(xhp, "%s: ignoring pkg with unmatched arch (%s)\n", pkgver, arch);
free(binpkg);
xbps_object_release(pkg_propsd);
continue;
}
/* /*
* Remove binary pkg if it's not registered in any repository * Remove binary pkg if it's not registered in any repository
* or if hash doesn't match. * or if hash doesn't match.
*/ */
binpkgsig = xbps_xasprintf("%s.sig", binpkg);
repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver); repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver);
if (repo_pkgd) { if (repo_pkgd) {
xbps_dictionary_get_cstring_nocopy(repo_pkgd, xbps_dictionary_get_cstring_nocopy(repo_pkgd,
"filename-sha256", &rsha256); "filename-sha256", &rsha256);
if (xbps_file_hash_check(binpkg, rsha256) == ERANGE) { if (xbps_file_hash_check(binpkg, rsha256) == ERANGE) {
printf("Removed %s from cachedir (sha256 mismatch)\n", if (unlink(binpkg) == -1) {
dp->d_name);
xbps_object_release(pkg_propsd);
if (unlink(binpkg) == -1)
fprintf(stderr, "Failed to remove " fprintf(stderr, "Failed to remove "
"`%s': %s\n", binpkg, "`%s': %s\n", binpkg, strerror(errno));
strerror(errno)); } else {
printf("Removed %s from cachedir (sha256 mismatch)\n", dp->d_name);
}
if ((access(binpkgsig, R_OK) == 0) && (unlink(binpkgsig) == -1)) {
fprintf(stderr, "Failed to remove "
"`%s': %s\n", binpkgsig, strerror(errno));
}
} }
xbps_object_release(pkg_propsd); xbps_object_release(pkg_propsd);
free(binpkg); free(binpkg);
free(binpkgsig);
continue; continue;
} }
printf("Removed %s from cachedir (obsolete)\n", dp->d_name); if (unlink(binpkg) == -1) {
if (unlink(binpkg) == -1)
fprintf(stderr, "Failed to remove `%s': %s\n", fprintf(stderr, "Failed to remove `%s': %s\n",
binpkg, strerror(errno)); binpkg, strerror(errno));
} else {
printf("Removed %s from cachedir (obsolete)\n", dp->d_name);
}
if ((access(binpkgsig, R_OK) == 0) && (unlink(binpkgsig) == -1)) {
fprintf(stderr, "Failed to remove `%s': %s\n",
binpkgsig, strerror(errno));
}
xbps_object_release(pkg_propsd); xbps_object_release(pkg_propsd);
free(binpkg); free(binpkg);
free(binpkgsig);
} }
closedir(dirp); closedir(dirp);
return rv; return rv;