mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 02:25:40 +01:00
Style cleanup.
This commit is contained in:
parent
4c01e4e159
commit
04cca33094
@ -30,25 +30,24 @@ fs::path FlatFileSeq::FileName(const FlatFilePos& pos) const
|
||||
return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile);
|
||||
}
|
||||
|
||||
FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool fReadOnly)
|
||||
FILE* FlatFileSeq::Open(const FlatFilePos& pos, bool read_only)
|
||||
{
|
||||
if (pos.IsNull())
|
||||
if (pos.IsNull()) {
|
||||
return nullptr;
|
||||
}
|
||||
fs::path path = FileName(pos);
|
||||
fs::create_directories(path.parent_path());
|
||||
FILE* file = fsbridge::fopen(path, fReadOnly ? "rb": "rb+");
|
||||
if (!file && !fReadOnly)
|
||||
FILE* file = fsbridge::fopen(path, read_only ? "rb": "rb+");
|
||||
if (!file && !read_only)
|
||||
file = fsbridge::fopen(path, "wb+");
|
||||
if (!file) {
|
||||
LogPrintf("Unable to open file %s\n", path.string());
|
||||
return nullptr;
|
||||
}
|
||||
if (pos.nPos) {
|
||||
if (fseek(file, pos.nPos, SEEK_SET)) {
|
||||
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
||||
fclose(file);
|
||||
return nullptr;
|
||||
}
|
||||
if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) {
|
||||
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
||||
fclose(file);
|
||||
return nullptr;
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
@ -24,14 +24,12 @@ struct FlatFilePos
|
||||
READWRITE(VARINT(nPos));
|
||||
}
|
||||
|
||||
FlatFilePos() {
|
||||
SetNull();
|
||||
}
|
||||
FlatFilePos() : nFile(-1), nPos(0) {}
|
||||
|
||||
FlatFilePos(int nFileIn, unsigned int nPosIn) {
|
||||
nFile = nFileIn;
|
||||
nPos = nPosIn;
|
||||
}
|
||||
FlatFilePos(int nFileIn, unsigned int nPosIn) :
|
||||
nFile(nFileIn),
|
||||
nPos(nPosIn)
|
||||
{}
|
||||
|
||||
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
|
||||
return (a.nFile == b.nFile && a.nPos == b.nPos);
|
||||
@ -72,7 +70,7 @@ public:
|
||||
fs::path FileName(const FlatFilePos& pos) const;
|
||||
|
||||
/** Open a handle to the file at the given position. */
|
||||
FILE* Open(const FlatFilePos& pos, bool fReadOnly = false);
|
||||
FILE* Open(const FlatFilePos& pos, bool read_only = false);
|
||||
|
||||
/**
|
||||
* Allocate additional space in a file after the given starting position. The amount allocated
|
||||
|
@ -135,12 +135,12 @@ bool DirIsWritable(const fs::path& directory)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes)
|
||||
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes)
|
||||
{
|
||||
constexpr uint64_t nMinDiskSpace = 52428800; // 50 MiB
|
||||
constexpr uint64_t min_disk_space = 52428800; // 50 MiB
|
||||
|
||||
uint64_t nFreeBytesAvailable = fs::space(dir).available;
|
||||
return nFreeBytesAvailable >= nMinDiskSpace + nAdditionalBytes;
|
||||
uint64_t free_bytes_available = fs::space(dir).available;
|
||||
return free_bytes_available >= min_disk_space + additional_bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +72,7 @@ bool RenameOver(fs::path src, fs::path dest);
|
||||
bool LockDirectory(const fs::path& directory, const std::string lockfile_name, bool probe_only=false);
|
||||
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
||||
bool DirIsWritable(const fs::path& directory);
|
||||
bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes = 0);
|
||||
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
|
||||
|
||||
/** Release all directory locks. This is used for unit testing only, at runtime
|
||||
* the global destructor will take care of the locks.
|
||||
|
Loading…
Reference in New Issue
Block a user