aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/util.hh
diff options
context:
space:
mode:
authorsqualus <squalus@squalus.net>2022-09-19 11:15:31 -0700
committersqualus <squalus@squalus.net>2022-09-19 20:13:30 -0700
commit1b595026e18afb050de3f62ded8f7180bc8b2b0e (patch)
tree6a6c3834483a46ce194cd37bafb0a8168742148c /src/libutil/util.hh
parent9d860f34673fbf07a2cf07ff854ae6683dae2fb8 (diff)
Improve durability of schema version file writes
- call close explicitly in writeFile to prevent the close exception from being ignored - fsync after writing schema file to flush data to disk - fsync schema file parent to flush metadata to disk https://github.com/NixOS/nix/issues/7064
Diffstat (limited to 'src/libutil/util.hh')
-rw-r--r--src/libutil/util.hh8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index cd83f250f..e5c678682 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -115,9 +115,12 @@ std::string readFile(const Path & path);
void readFile(const Path & path, Sink & sink);
/* Write a string to a file. */
-void writeFile(const Path & path, std::string_view s, mode_t mode = 0666);
+void writeFile(const Path & path, std::string_view s, mode_t mode = 0666, bool sync = false);
-void writeFile(const Path & path, Source & source, mode_t mode = 0666);
+void writeFile(const Path & path, Source & source, mode_t mode = 0666, bool sync = false);
+
+/* Flush a file's parent directory to disk */
+void syncParent(const Path & path);
/* Read a line from a file descriptor. */
std::string readLine(int fd);
@@ -231,6 +234,7 @@ public:
explicit operator bool() const;
int release();
void close();
+ void fsync();
};