index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Dan McGee <dan@archlinux.org> | 2012-01-18 21:43:00 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2012-01-23 12:21:11 -0600 |
commit | be038f9cb2d4302d74c0edadd9abf2b282adc7c3 (patch) | |
tree | 675ffc363d23d1ebb5520db69a2127172e647a2a /lib/libalpm/be_local.c | |
parent | ac239c54d0b8f83ee8a0a94456fc84da7f583ccb (diff) |
-rw-r--r-- | lib/libalpm/be_local.c | 40 |
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 36b2c5dc..137da1a8 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -907,14 +907,44 @@ cleanup: int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info) { int ret = 0; - char *pkgpath = _alpm_local_db_pkgpath(db, info, NULL); + DIR *dirp; + struct dirent *dp; + char *pkgpath; + size_t pkgpath_len; - /* TODO explicit file removes and then an rmdir? */ - ret = _alpm_rmrf(pkgpath); - free(pkgpath); - if(ret != 0) { + pkgpath = _alpm_local_db_pkgpath(db, info, NULL); + if(!pkgpath) { + return -1; + } + pkgpath_len = strlen(pkgpath); + + dirp = opendir(pkgpath); + if(!dirp) { + return -1; + } + /* go through the local DB entry, removing the files within, which we know + * are not nested directories of any kind. */ + for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { + if(strcmp(dp->d_name, "..") != 0 && strcmp(dp->d_name, ".") != 0) { + char name[PATH_MAX]; + if(pkgpath_len + strlen(dp->d_name) + 2 > PATH_MAX) { + /* file path is too long to remove, hmm. */ + ret = -1; + } else { + sprintf(name, "%s/%s", pkgpath, dp->d_name); + if(unlink(name)) { + ret = -1; + } + } + } + } + closedir(dirp); + + /* after removing all enclosed files, we can remove the directory itself. */ + if(rmdir(pkgpath)) { ret = -1; } + free(pkgpath); return ret; } |