From a5cfd981acb3e91bed7bd30f7c1e2df88cc3629b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 18 Mar 2021 16:00:35 +0200 Subject: Use fdstat() in file cache --- libbuild2/file-cache.cxx | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'libbuild2') 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 #include -#include // entry_stat, path_entry() #include // exists(), try_rmfile() #include @@ -96,32 +95,25 @@ namespace build2 { tracer trace ("file_cache::entry::compress"); - pair 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) { -- cgit v1.1