remove: also remove package metadata stuff.

--HG--
extra : convert_revision : 0a286d1fb33b81a90b0bfb5b41f25c1874d72093
This commit is contained in:
Juan RP 2009-02-03 22:37:20 +01:00
parent fa2748d9b2
commit 7e677c32d9
1 changed files with 45 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <dirent.h>
#include <xbps_api.h>
@ -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;
}