From 03fab6e246a708dfee26c0fbbffc5ce0f0cbd6bd Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 22 Aug 2023 21:53:11 +0200 Subject: [PATCH] Show progress for file hashing --- src/dwarfs/entry.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/dwarfs/entry.cpp b/src/dwarfs/entry.cpp index 7d310f0d..2be82490 100644 --- a/src/dwarfs/entry.cpp +++ b/src/dwarfs/entry.cpp @@ -36,12 +36,20 @@ #include "dwarfs/options.h" #include "dwarfs/os_access.h" #include "dwarfs/progress.h" +#include "dwarfs/scanner_progress.h" #include "dwarfs/util.h" #include "dwarfs/gen-cpp2/metadata_types.h" namespace dwarfs { +namespace { + +constexpr size_t const kMinHasherProgressFileSize{64 * 1024 * 1024}; +constexpr std::string_view const kHashContext{"[hashing] "}; + +} // namespace + entry::entry(std::filesystem::path const& path, std::shared_ptr parent, file_stat const& st) : name_{u8string_to_string(parent ? path.filename().u8string() @@ -226,7 +234,14 @@ void file::scan(mmif* mm, progress& prog, checksum cs(*hash_alg); if (s > 0) { - constexpr size_t chunk_size = 32 << 20; + std::shared_ptr pctx; + + if (s >= kMinHasherProgressFileSize) { + pctx = prog.create_context( + termcolor::MAGENTA, kHashContext, path_as_string(), s); + } + + constexpr size_t chunk_size = 16 << 20; size_t offset = 0; assert(mm); @@ -236,6 +251,9 @@ void file::scan(mmif* mm, progress& prog, mm->release_until(offset); offset += chunk_size; s -= chunk_size; + if (pctx) { + pctx->bytes_processed += chunk_size; + } } cs.update(mm->as(offset), s);