lib/transaction_files.c: fix leaving behind obsolete directories

Deleting obsolete directories is different from deleting obsolete files,
files need to be deleted by the first package that might change the file
into a different file type.
Directories need to be deleted by the last package that removes files
out of the directory to avoid ENOTEMPTY if another package has a file in
the given directory which is uninstalled later.

This fixes #282.
This commit is contained in:
Duncan Overbruck
2020-05-17 15:20:15 +02:00
parent a8d095a2ba
commit 62962208fd
2 changed files with 220 additions and 3 deletions

View File

@ -443,7 +443,16 @@ collect_file(struct xbps_handle *xhp, const char *file, size_t size,
} else if (type == TYPE_DIR && item->old.type == TYPE_DIR) {
/*
* Multiple packages removing the same directory.
* Record the last package to remove this directory.
*/
if (idx < item->old.index || item->old.preserve)
return 0;
item->old.pkgname = pkgname;
item->old.pkgver = pkgver;
item->old.index = idx;
item->old.preserve = preserve;
item->old.update = update;
item->old.removepkg = removepkg;
return 0;
} else {
/*
@ -777,9 +786,9 @@ xbps_transaction_files(struct xbps_handle *xhp, xbps_object_iterator_t iter)
while ((obj = xbps_object_iterator_next(iter)) != NULL) {
bool update = false;
/*
* `idx` is used as package install index, to chose which
* choose the first package which owns or used to own the
* file deletes it.
* `idx` is used as package install index, to choose which
* choose the first or last package which owns or used to
* own the file or directory deletes it.
*/
idx++;