diff --git a/NEWS b/NEWS index 4afd9dfb..6e318f70 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +xbps-0.6.2 (???): + + * When updating a package and removing obsolete files, don't forget to + remove those directories if they were empty. + xbps-0.6.1 (2010-10-23): * When replacing a package that is going to be updated in the transaction diff --git a/lib/remove_obsoletes.c b/lib/remove_obsoletes.c index 7427e41e..60a538c2 100644 --- a/lib/remove_obsoletes.c +++ b/lib/remove_obsoletes.c @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -43,7 +44,7 @@ xbps_remove_obsoletes(prop_dictionary_t oldd, prop_dictionary_t newd) struct stat st; const char *array_str = "files"; const char *oldhash = NULL; - char *file = NULL; + char *dname = NULL, *file = NULL; int rv = 0; bool found, dolinks = false; @@ -134,6 +135,18 @@ again: printf("Removed obsolete %s: %s\n", dolinks ? "link" : "file", prop_string_cstring_nocopy(oldstr)); + /* + * Try to remove the directory where the obsole file or link + * was currently living on. + */ + dname = dirname(file); + if (rmdir(dname) == -1) { + if (errno != 0 && errno != EEXIST && errno != ENOTEMPTY) + fprintf(stderr, + "WARNING: couldn't remove obsolete " + "directory %s: %s\n", dname, + strerror(errno)); + } free(file); } if (!dolinks) {