From 7e677c32d94acc5ecc299090363453f5810566e8 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Tue, 3 Feb 2009 22:37:20 +0100 Subject: [PATCH] remove: also remove package metadata stuff. --HG-- extra : convert_revision : 0a286d1fb33b81a90b0bfb5b41f25c1874d72093 --- lib/remove.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lib/remove.c b/lib/remove.c index 1c0d25441e..154cceab53 100644 --- a/lib/remove.c +++ b/lib/remove.c @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -77,6 +78,49 @@ xbps_unregister_pkg(const char *pkgname) return rv; } +static int +xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir) +{ + struct dirent *dp; + DIR *dirp; + char metadir[PATH_MAX - 1], path[PATH_MAX - 1]; + int rv = 0; + + assert(pkgname != NULL); + + if (destdir == NULL) + destdir = ""; + + (void)snprintf(metadir, sizeof(metadir), "%s%s/metadata/%s", + destdir, XBPS_META_PATH, pkgname); + + dirp = opendir(metadir); + if (dirp == NULL) + return errno; + + while ((dp = readdir(dirp)) != NULL) { + if ((strcmp(dp->d_name, ".") == 0) || + (strcmp(dp->d_name, "..") == 0)) + continue; + + if (snprintf(path, sizeof(path), "%s%s/metadata/%s/%s", + destdir, XBPS_META_PATH, pkgname, dp->d_name) < 0) { + (void)closedir(dirp); + return -1; + } + + if ((rv = unlink(path)) == -1) { + printf("WARNING: can't remove %s (%s)\n", + pkgname, strerror(errno)); + } + (void)memset(&path, 0, sizeof(path)); + } + (void)closedir(dirp); + rv = rmdir(metadir); + + return rv; +} + int xbps_remove_binary_pkg(const char *pkgname, const char *destdir) { @@ -204,6 +248,7 @@ next: out: free(buf); + rv = xbps_remove_binary_pkg_meta(pkgname, destdir); return rv; }