From 46be602e28e1cbac4ff928bae40a22e617f637a8 Mon Sep 17 00:00:00 2001 From: Jan Tatje Date: Fri, 2 Sep 2016 15:55:09 +0200 Subject: [PATCH] xbps-remove: fix --dry-run for --clean-cache `xbps-remove --clean-cache --dry-run` did not consider the --dry-run flag, this has been fixed. --- bin/xbps-remove/clean-cache.c | 15 ++++++++++----- bin/xbps-remove/defs.h | 2 +- bin/xbps-remove/main.c | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/bin/xbps-remove/clean-cache.c b/bin/xbps-remove/clean-cache.c index b89fea24..dacc9a59 100644 --- a/bin/xbps-remove/clean-cache.c +++ b/bin/xbps-remove/clean-cache.c @@ -38,12 +38,17 @@ static int cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, - const char *key _unused, void *arg _unused, + const char *key _unused, void *arg, bool *done _unused) { xbps_dictionary_t repo_pkgd; const char *binpkg, *rsha256; char *binpkgsig, *pkgver, *arch; + bool drun = false; + + /* Extract drun (dry-run) flag from arg*/ + if (arg != NULL) + drun = *(bool*)arg; /* Internalize props.plist dictionary from binary pkg */ binpkg = xbps_string_cstring_nocopy(obj); @@ -73,13 +78,13 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, } } binpkgsig = xbps_xasprintf("%s.sig", binpkg); - if (unlink(binpkg) == -1) { + if (!drun && unlink(binpkg) == -1) { fprintf(stderr, "Failed to remove `%s': %s\n", binpkg, strerror(errno)); } else { printf("Removed %s from cachedir (obsolete)\n", binpkg); } - if (unlink(binpkgsig) == -1) { + if (!drun && unlink(binpkgsig) == -1) { if (errno != ENOENT) { fprintf(stderr, "Failed to remove `%s': %s\n", binpkgsig, strerror(errno)); @@ -91,7 +96,7 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, } int -clean_cachedir(struct xbps_handle *xhp) +clean_cachedir(struct xbps_handle *xhp, bool drun) { xbps_array_t array = NULL; DIR *dirp; @@ -123,7 +128,7 @@ clean_cachedir(struct xbps_handle *xhp) (void)closedir(dirp); if (xbps_array_count(array)) { - rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, NULL); + rv = xbps_array_foreach_cb_multi(xhp, array, NULL, cleaner_cb, (void*)&drun); xbps_object_release(array); } return rv; diff --git a/bin/xbps-remove/defs.h b/bin/xbps-remove/defs.h index 512b4b82..0788812c 100644 --- a/bin/xbps-remove/defs.h +++ b/bin/xbps-remove/defs.h @@ -27,6 +27,6 @@ #define _XBPS_REMOVE_DEFS_H_ /* From clean-cache.c */ -int clean_cachedir(struct xbps_handle *); +int clean_cachedir(struct xbps_handle *, bool drun); #endif /* !_XBPS_REMOVE_DEFS_H_ */ diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index f8086e9d..25554e8c 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -262,7 +262,7 @@ main(int argc, char **argv) maxcols = get_maxcols(); if (clean_cache) { - rv = clean_cachedir(&xh); + rv = clean_cachedir(&xh, drun); if (!orphans || rv) exit(rv);; }