Skip to content

Commit 86e22d2

Browse files
committed
[util] GetFileSize
1 parent 6ab3aad commit 86e22d2

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/util/system.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes)
141141
return free_bytes_available >= min_disk_space + additional_bytes;
142142
}
143143

144+
std::streampos GetFileSize(const char* path, std::streamsize max) {
145+
std::ifstream file(path, std::ios::binary);
146+
file.ignore(max);
147+
return file.gcount();
148+
}
149+
144150
/**
145151
* Interpret a string argument as a boolean.
146152
*

src/util/system.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ void UnlockDirectory(const fs::path& directory, const std::string& lockfile_name
6363
bool DirIsWritable(const fs::path& directory);
6464
bool CheckDiskSpace(const fs::path& dir, uint64_t additional_bytes = 0);
6565

66+
/** Get the size of a file by scanning it.
67+
*
68+
* @param[in] path The file path
69+
* @param[in] max Stop seeking beyond this limit
70+
* @return The file size or max
71+
*/
72+
std::streampos GetFileSize(const char* path, std::streamsize max = std::numeric_limits<std::streamsize>::max());
73+
6674
/** Release all directory locks. This is used for unit testing only, at runtime
6775
* the global destructor will take care of the locks.
6876
*/

0 commit comments

Comments
 (0)