From: Lennart Poettering Date: Tue, 5 Oct 2021 08:32:56 +0000 (+0200) Subject: rm-rf: optionally fsync() after removing directory tree X-Git-Tag: archive/raspbian/247.3-7+rpi1+deb11u5^2~52 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=8060383f24d880a56f1f796988d8b3d4b30dc9cd;p=systemd.git 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) Gbp-Pq: Name rm-rf-optionally-fsync-after-removing-directory-tree.patch --- diff --git a/src/basic/rm-rf.c b/src/basic/rm-rf.c index f1b8445d..cf671c25 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 b0d5b638..2619fc52 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);