rm-rf: optionally fsync() after removing directory tree

This commit is contained in:
Lennart Poettering
2021-10-11 16:00:34 +02:00
parent 678ca2133c
commit bdfe7ada0d
2 changed files with 4 additions and 0 deletions
+3
View 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;
}
+1
View 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);