From 8051232e822c1f841c1d90fa4e45a43d61f60c6c Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 29 Oct 2010 09:10:41 +0200 Subject: [PATCH] libxbps: xbps_repository_unregister(): in remote repositories, also remove the pkg index file and its directory. --- NEWS | 5 +++++ lib/repository.c | 43 +++++++++++++++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index f4e51a4e..c5448d04 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,10 @@ xbps-0.6.2 (???): + * libxbps: xbps_repository_unregister(): in remote repositories, also + remove the pkg index file and its directory. + + * libxbps: xbps_get_pkg_index_plist(): fixed a memleak. + * xbps-bin(8): modify the 'list' target to accept an optional argument to list packages in the specified state, so that you can list packages that need to be purged, configured and broken (will be used in the future). diff --git a/lib/repository.c b/lib/repository.c index 66df9330..5dca13b5 100644 --- a/lib/repository.c +++ b/lib/repository.c @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -117,7 +118,8 @@ xbps_repository_unregister(const char *uri) { prop_dictionary_t dict; prop_array_t array; - char *plist; + const char *pkgindexdir; + char *plist, *pkgindex; int rv = 0; assert(uri != NULL); @@ -139,11 +141,44 @@ xbps_repository_unregister(const char *uri) goto out; } - rv = xbps_remove_string_from_array(array, uri); - if (rv == 0) { + if ((rv = xbps_remove_string_from_array(array, uri)) == 0) { /* Update plist file. */ - if (!prop_dictionary_externalize_to_zfile(dict, plist)) + if (!prop_dictionary_externalize_to_zfile(dict, plist)) { rv = errno; + goto out; + } + } + + /* + * If it's a remote repository, also remove the stored XBPS_PKGINDEX + * file and its directory. + */ + if (xbps_check_is_repo_string_remote(uri)) { + pkgindex = xbps_get_pkg_index_plist(uri); + if (pkgindex == NULL) { + rv = EINVAL; + goto out; + } + if (unlink(pkgindex) == -1) { + if (errno == ENOENT) { + free(pkgindex); + goto out; + } + fprintf(stderr, "E: cannot remove pkgindex file at " + "%s: %s\n", pkgindex, strerror(errno)); + free(pkgindex); + rv = errno; + goto out; + } + pkgindexdir = dirname(pkgindex); + if (rmdir(pkgindexdir) == -1) { + fprintf(stderr, "E: cannot remove pkgindex dir at " + "%s: %s\n", pkgindexdir, strerror(errno)); + free(pkgindex); + rv = errno; + goto out; + } + free(pkgindex); } out: