Skip to content

Commit

Permalink
Style cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo authored and furszy committed May 11, 2021
1 parent 78de49d commit fb800e1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 23 deletions.
19 changes: 9 additions & 10 deletions src/flatfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 6 additions & 8 deletions src/flatfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -72,7 +70,7 @@ class FlatFileSeq
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
Expand Down
8 changes: 4 additions & 4 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ ArgsManager gArgs;
bool fDaemon = false;
CTranslationInterface translationInterface;

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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ bool FileCommit(FILE* file);
bool TruncateFile(FILE* file, unsigned int length);
int RaiseFileDescriptorLimit(int nMinFD);
void AllocateFileRange(FILE* file, unsigned int offset, unsigned int length);
bool CheckDiskSpace(const fs::path& dir, uint64_t nAdditionalBytes = 0);
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
bool RenameOver(fs::path src, fs::path dest);
bool TryCreateDirectories(const fs::path& p);
fs::path GetDefaultDataDir();
Expand Down

0 comments on commit fb800e1

Please sign in to comment.