mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 05:39:38 +02:00
flatfile: check whether the file has been closed successfully
This commit is contained in:
@@ -46,7 +46,9 @@ FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool read_only) const
|
|||||||
}
|
}
|
||||||
if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) {
|
if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) {
|
||||||
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, fs::PathToString(path));
|
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, fs::PathToString(path));
|
||||||
fclose(file);
|
if (fclose(file) != 0) {
|
||||||
|
LogError("Unable to close file %s", fs::PathToString(path));
|
||||||
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
@@ -68,7 +70,10 @@ size_t FlatFileSeq::Allocate(const FlatFilePos& pos, size_t add_size, bool& out_
|
|||||||
if (file) {
|
if (file) {
|
||||||
LogDebug(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
|
LogDebug(BCLog::VALIDATION, "Pre-allocating up to position 0x%x in %s%05u.dat\n", new_size, m_prefix, pos.nFile);
|
||||||
AllocateFileRange(file, pos.nPos, inc_size);
|
AllocateFileRange(file, pos.nPos, inc_size);
|
||||||
fclose(file);
|
if (fclose(file) != 0) {
|
||||||
|
LogError("Cannot close file %s%05u.dat after extending it with %u bytes", m_prefix, pos.nFile, new_size);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return inc_size;
|
return inc_size;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -86,17 +91,24 @@ bool FlatFileSeq::Flush(const FlatFilePos& pos, bool finalize) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (finalize && !TruncateFile(file, pos.nPos)) {
|
if (finalize && !TruncateFile(file, pos.nPos)) {
|
||||||
fclose(file);
|
|
||||||
LogError("%s: failed to truncate file %d\n", __func__, pos.nFile);
|
LogError("%s: failed to truncate file %d\n", __func__, pos.nFile);
|
||||||
|
if (fclose(file) != 0) {
|
||||||
|
LogError("Failed to close file %d", pos.nFile);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!FileCommit(file)) {
|
if (!FileCommit(file)) {
|
||||||
fclose(file);
|
|
||||||
LogError("%s: failed to commit file %d\n", __func__, pos.nFile);
|
LogError("%s: failed to commit file %d\n", __func__, pos.nFile);
|
||||||
|
if (fclose(file) != 0) {
|
||||||
|
LogError("Failed to close file %d", pos.nFile);
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DirectoryCommit(m_dir);
|
DirectoryCommit(m_dir);
|
||||||
|
|
||||||
fclose(file);
|
if (fclose(file) != 0) {
|
||||||
|
LogError("Failed to close file %d after flush", pos.nFile);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user