aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Groffen <grobian@gentoo.org>2018-12-20 12:44:41 +0100
committerFabian Groffen <grobian@gentoo.org>2018-12-20 19:22:36 +0100
commit5d274dbc605c72b43c13f8ac61c988eae40531ce (patch)
tree029fa5e7e5dab4067f2077fc01e3a3ceb7cf7e6e
parentqsearch: avoid printing a trailing space, bug #672764 (diff)
downloadportage-utils-5d274dbc605c72b43c13f8ac61c988eae40531ce.tar.gz
portage-utils-5d274dbc605c72b43c13f8ac61c988eae40531ce.tar.bz2
portage-utils-5d274dbc605c72b43c13f8ac61c988eae40531ce.zip
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@gentoo.org>
-rw-r--r--libq/xmkdir.c4
1 files changed, 3 insertions, 1 deletions
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);