summaryrefslogtreecommitdiffstats
path: root/src/shared/rm-rf.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-23 15:55:45 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-12-21 14:36:56 +0100
commit3bac86abfa1b1720180840ffb9d06b3d54841c11 (patch)
tree7309cadd61d1f95338a2c32aae7838a1f91b34eb /src/shared/rm-rf.c
parenttimedatectl: Uniform commas in NTPMessage output (diff)
downloadsystemd-3bac86abfa1b1720180840ffb9d06b3d54841c11.tar.xz
systemd-3bac86abfa1b1720180840ffb9d06b3d54841c11.zip
shared/rm_rf: refactor rm_rf_children_inner() to shorten code a bit
Diffstat (limited to 'src/shared/rm-rf.c')
-rw-r--r--src/shared/rm-rf.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c
index fd54b2ccaf..6dbdc648ea 100644
--- a/src/shared/rm-rf.c
+++ b/src/shared/rm-rf.c
@@ -124,7 +124,7 @@ static int rm_rf_children_inner(
const struct stat *root_dev) {
struct stat st;
- int r;
+ int r, q = 0;
assert(fd >= 0);
assert(fname);
@@ -142,7 +142,6 @@ static int rm_rf_children_inner(
if (is_dir) {
_cleanup_close_ int subdir_fd = -1;
- int q;
/* if root_dev is set, remove subdirectories only if device is same */
if (root_dev && st.st_dev != root_dev->st_dev)
@@ -178,23 +177,15 @@ static int rm_rf_children_inner(
* again for each directory */
q = rm_rf_children(TAKE_FD(subdir_fd), flags | REMOVE_PHYSICAL, root_dev);
- r = unlinkat_harder(fd, fname, AT_REMOVEDIR, flags);
- if (r < 0)
- return r;
- if (q < 0)
- return q;
-
- return 1;
-
- } else if (!(flags & REMOVE_ONLY_DIRECTORIES)) {
- r = unlinkat_harder(fd, fname, 0, flags);
- if (r < 0)
- return r;
-
- return 1;
- }
+ } else if (flags & REMOVE_ONLY_DIRECTORIES)
+ return 0;
- return 0;
+ r = unlinkat_harder(fd, fname, is_dir ? AT_REMOVEDIR : 0, flags);
+ if (r < 0)
+ return r;
+ if (q < 0)
+ return q;
+ return 1;
}
int rm_rf_children(