Style cleanup.
This commit is contained in:
parent
4c01e4e159
commit
04cca33094
4 changed files with 20 additions and 23 deletions
|
@ -30,26 +30,25 @@ fs::path FlatFileSeq::FileName(const FlatFilePos& pos) const
|
||||||
return m_dir / strprintf("%s%05u.dat", m_prefix, pos.nFile);
|
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;
|
return nullptr;
|
||||||
|
}
|
||||||
fs::path path = FileName(pos);
|
fs::path path = FileName(pos);
|
||||||
fs::create_directories(path.parent_path());
|
fs::create_directories(path.parent_path());
|
||||||
FILE* file = fsbridge::fopen(path, fReadOnly ? "rb": "rb+");
|
FILE* file = fsbridge::fopen(path, read_only ? "rb": "rb+");
|
||||||
if (!file && !fReadOnly)
|
if (!file && !read_only)
|
||||||
file = fsbridge::fopen(path, "wb+");
|
file = fsbridge::fopen(path, "wb+");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
LogPrintf("Unable to open file %s\n", path.string());
|
LogPrintf("Unable to open file %s\n", path.string());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
if (pos.nPos) {
|
if (pos.nPos && fseek(file, pos.nPos, SEEK_SET)) {
|
||||||
if (fseek(file, pos.nPos, SEEK_SET)) {
|
|
||||||
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
LogPrintf("Unable to seek to position %u of %s\n", pos.nPos, path.string());
|
||||||
fclose(file);
|
fclose(file);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,14 +24,12 @@ struct FlatFilePos
|
||||||
READWRITE(VARINT(nPos));
|
READWRITE(VARINT(nPos));
|
||||||
}
|
}
|
||||||
|
|
||||||
FlatFilePos() {
|
FlatFilePos() : nFile(-1), nPos(0) {}
|
||||||
SetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
FlatFilePos(int nFileIn, unsigned int nPosIn) {
|
FlatFilePos(int nFileIn, unsigned int nPosIn) :
|
||||||
nFile = nFileIn;
|
nFile(nFileIn),
|
||||||
nPos = nPosIn;
|
nPos(nPosIn)
|
||||||
}
|
{}
|
||||||
|
|
||||||
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
|
friend bool operator==(const FlatFilePos &a, const FlatFilePos &b) {
|
||||||
return (a.nFile == b.nFile && a.nPos == b.nPos);
|
return (a.nFile == b.nFile && a.nPos == b.nPos);
|
||||||
|
@ -72,7 +70,7 @@ public:
|
||||||
fs::path FileName(const FlatFilePos& pos) const;
|
fs::path FileName(const FlatFilePos& pos) const;
|
||||||
|
|
||||||
/** Open a handle to the file at the given position. */
|
/** 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
|
* 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;
|
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;
|
uint64_t free_bytes_available = fs::space(dir).available;
|
||||||
return nFreeBytesAvailable >= nMinDiskSpace + nAdditionalBytes;
|
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);
|
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);
|
void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name);
|
||||||
bool DirIsWritable(const fs::path& directory);
|
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
|
/** Release all directory locks. This is used for unit testing only, at runtime
|
||||||
* the global destructor will take care of the locks.
|
* the global destructor will take care of the locks.
|
||||||
|
|
Loading…
Add table
Reference in a new issue