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: v250-rc1~531^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdfe7ada0d4d66e6d6e65f2822acbb1ec230f9c2;p=thirdparty%2Fsystemd.git rm-rf: optionally fsync() after removing directory tree --- diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index d9cd8fb2b2d..a8693660fab 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -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; } diff --git a/src/shared/rm-rf.h b/src/shared/rm-rf.h index 577a2795e0f..24fd9a2aa2d 100644 --- a/src/shared/rm-rf.h +++ b/src/shared/rm-rf.h @@ -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);