aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-03-18 16:00:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-03-18 16:00:35 +0200
commita5cfd981acb3e91bed7bd30f7c1e2df88cc3629b (patch)
tree86402d90ebffd190a0794b5c31716799589de4dd /libbuild2
parent6b9bdad3b68b12ff8e2075d54c1f7f005bb2f768 (diff)
Use fdstat() in file cache
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/file-cache.cxx22
1 files changed, 7 insertions, 15 deletions
diff --git a/libbuild2/file-cache.cxx b/libbuild2/file-cache.cxx
index 0c2fcbb..95e9536 100644
--- a/libbuild2/file-cache.cxx
+++ b/libbuild2/file-cache.cxx
@@ -4,7 +4,6 @@
#include <libbuild2/file-cache.hxx>
#include <libbutl/lz4.hxx>
-#include <libbutl/filesystem.mxx> // entry_stat, path_entry()
#include <libbuild2/filesystem.hxx> // exists(), try_rmfile()
#include <libbuild2/diagnostics.hxx>
@@ -96,32 +95,25 @@ namespace build2
{
tracer trace ("file_cache::entry::compress");
- pair<bool, entry_stat> st (
- path_entry (path_,
- true /* follow_symlinks */,
- true /* ignore_error */));
-
- if (!st.first)
- return false;
-
try
{
ifdstream ifs (path_, fdopen_mode::binary, ifdstream::badbit);
ofdstream ofs (comp_path_, fdopen_mode::binary);
+ uint64_t n (fdstat (ifs.fd ()).size);
+
// Experience shows that for the type of content we typically cache
// using 1MB blocks results in almost the same comression as for 4MB.
//
- uint64_t comp_size (
- lz4::compress (ofs, ifs,
- 1 /* compression_level (fastest) */,
- 6 /* block_size_id (1MB) */,
- st.second.size));
+ uint64_t cn (lz4::compress (ofs, ifs,
+ 1 /* compression_level (fastest) */,
+ 6 /* block_size_id (1MB) */,
+ n));
ofs.close ();
l6 ([&]{trace << "compressed " << path_ << " to "
- << (comp_size * 100 / st.second.size) << '%';});
+ << (cn * 100 / n) << '%';});
}
catch (const std::exception& e)
{