Remove empty dirs while removing obsolete files.

This commit is contained in:
Juan RP 2010-10-27 00:15:59 +02:00
parent 18e247486d
commit 418ee6eec4
2 changed files with 19 additions and 1 deletions

5
NEWS
View File

@ -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

View File

@ -31,6 +31,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <libgen.h>
#include <xbps_api.h>
@ -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) {