MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Flush

Method Flush

src/flatfile.cpp:88–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize) const
89{
90 FILE* file = Open(FlatFilePos(pos.nFile, 0)); // Avoid fseek to nPos
91 if (!file) {
92 LogError("%s: failed to open file %d\n", __func__, pos.nFile);
93 return false;
94 }
95 if (finalize && !TruncateFile(file, pos.nPos)) {
96 LogError("%s: failed to truncate file %d\n", __func__, pos.nFile);
97 if (fclose(file) != 0) {
98 LogError("Failed to close file %d", pos.nFile);
99 }
100 return false;
101 }
102 if (!FileCommit(file)) {
103 LogError("%s: failed to commit file %d\n", __func__, pos.nFile);
104 if (fclose(file) != 0) {
105 LogError("Failed to close file %d", pos.nFile);
106 }
107 return false;
108 }
109 DirectoryCommit(m_dir);
110
111 if (fclose(file) != 0) {
112 LogError("Failed to close file %d after flush", pos.nFile);
113 return false;
114 }
115 return true;
116}

Callers

nothing calls this directly

Calls 4

FlatFilePosClass · 0.85
TruncateFileFunction · 0.85
FileCommitFunction · 0.85
DirectoryCommitFunction · 0.85

Tested by

no test coverage detected