14 m_dir(
std::move(dir)),
16 m_chunk_size(chunk_size)
18 if (chunk_size == 0) {
19 throw std::invalid_argument(
"chunk_size must be positive");
41 if (!file && !read_only)
47 if (pos.
nPos && fseek(file, pos.
nPos, SEEK_SET)) {
61 if (n_new_chunks > n_old_chunks) {
62 size_t old_size = pos.
nPos;
64 size_t inc_size = new_size - old_size;
67 FILE *file =
Open(pos);
85 LogError(
"%s: failed to open file %d\n", __func__, pos.
nFile);
90 LogError(
"%s: failed to truncate file %d\n", __func__, pos.
nFile);
95 LogError(
"%s: failed to commit file %d\n", __func__, pos.
nFile);
FILE * Open(const FlatFilePos &pos, bool read_only=false) const
Open a handle to the file at the given position.
fs::path FileName(const FlatFilePos &pos) const
Get the name of the file at the given position.
bool Flush(const FlatFilePos &pos, bool finalize=false) const
Commit a file to disk, and optionally truncate off extra pre-allocated bytes if final.
size_t Allocate(const FlatFilePos &pos, size_t add_size, bool &out_of_space) const
Allocate additional space in a file after the given starting position.
const size_t m_chunk_size
const char *const m_prefix
FlatFileSeq(fs::path dir, const char *prefix, size_t chunk_size)
Constructor.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
void DirectoryCommit(const fs::path &dirname)
Sync directory contents.
void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length)
this function tries to make a particular range of a file allocated (corresponding to disk space) it i...
bool CheckDiskSpace(const fs::path &dir, uint64_t additional_bytes)
bool TruncateFile(FILE *file, unsigned int length)
bool FileCommit(FILE *file)
Ensure file contents are fully committed to disk, using a platform-specific feature analogous to fsyn...
#define LogDebug(category,...)
static path u8path(const std::string &utf8_str)
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
static std::string PathToString(const path &path)
Convert path object to a byte string.
FILE * fopen(const fs::path &p, const char *mode)
std::string ToString() const