}
struct stat st;
- size_t old_size = 0; // in bytes
+ uint64_t old_size = 0; // in bytes
if (stat(manifest_path, &st) == 0) {
- old_size = file_size(&st);
+ old_size = file_size_on_disk(&st);
}
MTR_BEGIN("manifest", "manifest_put");
if (!manifest_put(manifest_path, *cached_result_name, g_included_files)) {
cc_log("Failed to add result name to %s", manifest_path);
} else if (x_stat(manifest_path, &st) == 0) {
- stats_update_size(
- manifest_stats_file, file_size(&st) - old_size, old_size == 0 ? 1 : 0);
+ stats_update_size(manifest_stats_file,
+ file_size_on_disk(&st) - old_size,
+ old_size == 0 ? 1 : 0);
}
MTR_END("manifest", "manifest_put");
}
stats_update(STATS_ERROR);
failed();
}
- stats_update_size(stats_file,
- file_size(&st)
- - (orig_dest_existed ? file_size(&orig_dest_st) : 0),
- orig_dest_existed ? 0 : 1);
+ stats_update_size(
+ stats_file,
+ file_size_on_disk(&st)
+ - (orig_dest_existed ? file_size_on_disk(&orig_dest_st) : 0),
+ orig_dest_existed ? 0 : 1);
MTR_END("file", "file_put");
char* x_dirname(const char* path);
const char* get_extension(const char* path);
char* remove_extension(const char* path);
-size_t file_size(const struct stat* st);
+uint64_t file_size_on_disk(const struct stat* st);
char* format_human_readable_size(uint64_t size);
char* format_parsable_size_with_suffix(uint64_t size);
bool parse_size_with_suffix(const char* str, uint64_t* size);
static void
delete_file(const std::string& path,
- size_t size,
+ uint64_t size,
uint64_t* cache_size,
uint32_t* files_in_cache)
{
continue;
}
- cache_size += file_size(&file->stat());
+ cache_size += file_size_on_disk(&file->stat());
files_in_cache += 1;
}
delete_file(o_file, 0, nullptr, nullptr);
}
- delete_file(
- file->path(), file_size(&file->stat()), &cache_size, &files_in_cache);
+ delete_file(file->path(),
+ file_size_on_disk(&file->stat()),
+ &cache_size,
+ &files_in_cache);
cleaned = true;
}
for (size_t i = 0; i < files.size(); ++i) {
const auto& file = files[i];
- on_disk_size += file_size(&file->stat());
+ on_disk_size += file_size_on_disk(&file->stat());
uint64_t content_size = 0;
bool is_compressible;
}
// Return size on disk of a file.
-size_t
-file_size(const struct stat* st)
+uint64_t
+file_size_on_disk(const struct stat* st)
{
#ifdef _WIN32
return (st->st_size + 1023) & ~1023;
throw Error(fmt::format("Failed to open {} for reading", source_path));
}
- size_t remain = source_file_size;
+ uint64_t remain = source_file_size;
while (remain > 0) {
uint8_t buf[READ_BUFFER_SIZE];
- size_t n = std::min(remain, sizeof(buf));
+ size_t n = std::min(remain, static_cast<uint64_t>(sizeof(buf)));
if (fread(buf, n, 1, file.get()) != 1) {
throw Error(fmt::format("Error reading from {}", source_path));
}
fmt::format("Failed to stat {}: {}", source_path, strerror(errno)));
}
- size_t old_size;
- size_t new_size;
+ uint64_t old_size;
+ uint64_t new_size;
cc_log("Storing raw file #%u %s (%llu bytes) from %s",
entry_number,
struct stat new_stat;
bool new_exists = stat(raw_file.c_str(), &new_stat) == 0;
- old_size = old_existed ? file_size(&old_stat) : 0;
- new_size = new_exists ? file_size(&new_stat) : 0;
+ old_size = old_existed ? file_size_on_disk(&old_stat) : 0;
+ new_size = new_exists ? file_size_on_disk(&new_stat) : 0;
stats_update_size(stats_file,
new_size - old_size,
(new_exists ? 1 : 0) - (old_existed ? 1 : 0));