]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
rm-rf: optionally fsync() after removing directory tree
authorLennart Poettering <lennart@poettering.net>
Tue, 5 Oct 2021 08:32:56 +0000 (10:32 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 11 Oct 2021 14:00:34 +0000 (16:00 +0200)
src/shared/rm-rf.c
src/shared/rm-rf.h

index d9cd8fb2b2d01445bf872cd613221b0c42719d70..a8693660fab2f4d823e17cdf7c33e4cf934b8f60 100644 (file)
@@ -250,6 +250,9 @@ int rm_rf_children(
                         ret = r;
         }
 
+        if (FLAGS_SET(flags, REMOVE_SYNCFS) && syncfs(dirfd(d)) < 0 && ret >= 0)
+                ret = -errno;
+
         return ret;
 }
 
index 577a2795e0f34f7834128a21f64e7ca5af82aa99..24fd9a2aa2d2650984ac81cde2f4be13604ba658 100644 (file)
@@ -14,6 +14,7 @@ typedef enum RemoveFlags {
         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 or access something */
         REMOVE_CHMOD_RESTORE    = 1 << 6, /* Restore the old mode before returning */
+        REMOVE_SYNCFS           = 1 << 7, /* syncfs() the root of the specified directory after removing everything in it */
 } RemoveFlags;
 
 int unlinkat_harder(int dfd, const char *filename, int unlink_flags, RemoveFlags remove_flags);