summaryrefslogtreecommitdiffstats
path: root/debian/patches/rm-rf-optionally-fsync-after-removing-directory-tree.patch
blob: 66a1ef5806feb19b17ad60c0f8864c703d566aef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
From: Lennart Poettering <lennart@poettering.net>
Date: Tue, 5 Oct 2021 10:32:56 +0200
Subject: rm-rf: optionally fsync() after removing directory tree

(cherry picked from commit bdfe7ada0d4d66e6d6e65f2822acbb1ec230f9c2)
(cherry picked from commit 2426beacca09d84091759be45b25c88116302184)
(cherry picked from commit 0e180f8e9c25c707b0465ad1b9447a4360f785f1)
(cherry picked from commit 9a9c2220cd3cb61c2de9c482f8ed7fa60807b14a)
---
 src/basic/rm-rf.c | 3 +++
 src/basic/rm-rf.h | 1 +
 2 files changed, 4 insertions(+)

diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c
index f1b8445..cf671c2 100644
--- a/src/basic/rm-rf.c
+++ b/src/basic/rm-rf.c
@@ -249,6 +249,9 @@ int rm_rf_children(
                         ret = r;
         }
 
+        if (FLAGS_SET(flags, REMOVE_SYNCFS) && syncfs(dirfd(d)) < 0 && ret >= 0)
+                ret = -errno;
+
         return ret;
 }
 
diff --git a/src/basic/rm-rf.h b/src/basic/rm-rf.h
index b0d5b63..2619fc5 100644
--- a/src/basic/rm-rf.h
+++ b/src/basic/rm-rf.h
@@ -12,6 +12,7 @@ typedef enum RemoveFlags {
         REMOVE_SUBVOLUME        = 1 << 3, /* Drop btrfs subvolumes in the tree too */
         REMOVE_MISSING_OK       = 1 << 4, /* If the top-level directory is missing, ignore the ENOENT for it */
         REMOVE_CHMOD            = 1 << 5, /* chmod() for write access if we cannot delete something */
+        REMOVE_SYNCFS           = 1 << 6, /* syncfs() the root of the specified directory after removing everything in it */
 } RemoveFlags;
 
 int rm_rf_children(int fd, RemoveFlags flags, const struct stat *root_dev);