commit: 5d274dbc605c72b43c13f8ac61c988eae40531ce
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Dec 20 11:44:41 2018 +0000
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Dec 20 18:22:36 2018 +0000
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=5d274dbc
rm_rf_at: remove the object path points to
To better emulate 'rm -Rf' behaviour, if path points to a file, just
remove it. If it points to a directory, remove that directory instead
of leaving the (now) empty directory behind.
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>
libq/xmkdir.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/libq/xmkdir.c b/libq/xmkdir.c
index 9a120ae..ed30d6d 100644
--- a/libq/xmkdir.c
+++ b/libq/xmkdir.c
@@ -58,7 +58,7 @@ rm_rf_at(int dfd, const char *path)
dir = fdopendir(subdfd);
if (!dir) {
close(subdfd);
- return -1;
+ return unlinkat(dfd, path, 0);
}
while ((de = readdir(dir)) != NULL) {
@@ -78,6 +78,8 @@ rm_rf_at(int dfd, const char *path)
}
}
+ unlinkat(dfd, path, AT_REMOVEDIR);
+
/* this also does close(subdfd); */
closedir(dir);