aboutsummaryrefslogtreecommitdiffstats
path: root/src/compress.cpp
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2019-10-19 12:43:39 +0200
committerJoel Rosdahl <joel@rosdahl.net>2019-10-19 12:50:46 +0200
commit8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464 (patch)
tree28854fff9e441b7f2300ae2e44c229508af5fde1 /src/compress.cpp
parentb5b234ea33849358ad0605ba5d9127e6e8adba84 (diff)
downloadccache-8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464.tar.gz
ccache-8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464.tar.bz2
ccache-8bf69a1dd9dec1d3f8bcd161b50c86924b9bc464.zip
Improve functions related to (l)stat-ing
Introduced a Stat class that represents a “struct stat”. The class replaces the utility functions x_lstat, x_stat, file_size_on_disk and is_symlink, and it provides an easier to use interface than the macros associated with stat structs.
Diffstat (limited to 'src/compress.cpp')
-rw-r--r--src/compress.cpp18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/compress.cpp b/src/compress.cpp
index 240d7ed9..dd493e9f 100644
--- a/src/compress.cpp
+++ b/src/compress.cpp
@@ -24,7 +24,6 @@
#include "File.hpp"
#include "StdMakeUnique.hpp"
#include "ThreadPool.hpp"
-#include "ccache.hpp"
#include "manifest.hpp"
#include "result.hpp"
@@ -116,14 +115,11 @@ recompress_file(const std::string& stats_file,
reader->finalize();
writer->finalize();
- struct stat st;
- x_stat(cache_file.path().c_str(), &st);
- uint64_t old_size = file_size_on_disk(&st);
-
+ uint64_t old_size =
+ Stat::stat(cache_file.path(), Stat::OnError::log).size_on_disk();
atomic_new_file.commit();
-
- x_stat(cache_file.path().c_str(), &st);
- uint64_t new_size = file_size_on_disk(&st);
+ uint64_t new_size =
+ Stat::stat(cache_file.path(), Stat::OnError::log).size_on_disk();
stats_update_size(stats_file.c_str(), new_size - old_size, 0);
}
@@ -149,15 +145,15 @@ compress_stats(const Config& config,
for (size_t i = 0; i < files.size(); ++i) {
const auto& cache_file = files[i];
- on_disk_size += file_size_on_disk(&cache_file->stat());
+ on_disk_size += cache_file->lstat().size_on_disk();
try {
auto file = open_file(cache_file->path(), "rb");
auto reader = create_reader(*cache_file, file.get());
- compr_size += cache_file->stat().st_size;
+ compr_size += cache_file->lstat().size();
compr_orig_size += reader->content_size();
} catch (Error&) {
- incompr_size += cache_file->stat().st_size;
+ incompr_size += cache_file->lstat().size();
}
sub_progress_receiver(1.0 / 2 + 1.0 * i / files.size() / 2);