aboutsummaryrefslogtreecommitdiff
path: root/src/flatfile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/flatfile.cpp')
-rw-r--r--src/flatfile.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/flatfile.cpp b/src/flatfile.cpp
index d9fd4041b7..1cdead6bf5 100644
--- a/src/flatfile.cpp
+++ b/src/flatfile.cpp
@@ -72,3 +72,22 @@ size_t FlatFileSeq::Allocate(const CDiskBlockPos& pos, size_t add_size, bool& ou
}
return 0;
}
+
+bool FlatFileSeq::Flush(const CDiskBlockPos& pos, bool finalize)
+{
+ FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
+ if (!file) {
+ return error("%s: failed to open file %d", __func__, pos.nFile);
+ }
+ if (finalize && !TruncateFile(file, pos.nPos)) {
+ fclose(file);
+ return error("%s: failed to truncate file %d", __func__, pos.nFile);
+ }
+ if (!FileCommit(file)) {
+ fclose(file);
+ return error("%s: failed to commit file %d", __func__, pos.nFile);
+ }
+
+ fclose(file);
+ return true;
+}