mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-12 13:59:46 -04:00
Show progress for file hashing
This commit is contained in:
parent
8e84faf0a1
commit
03fab6e246
@ -36,12 +36,20 @@
|
|||||||
#include "dwarfs/options.h"
|
#include "dwarfs/options.h"
|
||||||
#include "dwarfs/os_access.h"
|
#include "dwarfs/os_access.h"
|
||||||
#include "dwarfs/progress.h"
|
#include "dwarfs/progress.h"
|
||||||
|
#include "dwarfs/scanner_progress.h"
|
||||||
#include "dwarfs/util.h"
|
#include "dwarfs/util.h"
|
||||||
|
|
||||||
#include "dwarfs/gen-cpp2/metadata_types.h"
|
#include "dwarfs/gen-cpp2/metadata_types.h"
|
||||||
|
|
||||||
namespace dwarfs {
|
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<entry> parent,
|
entry::entry(std::filesystem::path const& path, std::shared_ptr<entry> parent,
|
||||||
file_stat const& st)
|
file_stat const& st)
|
||||||
: name_{u8string_to_string(parent ? path.filename().u8string()
|
: name_{u8string_to_string(parent ? path.filename().u8string()
|
||||||
@ -226,7 +234,14 @@ void file::scan(mmif* mm, progress& prog,
|
|||||||
checksum cs(*hash_alg);
|
checksum cs(*hash_alg);
|
||||||
|
|
||||||
if (s > 0) {
|
if (s > 0) {
|
||||||
constexpr size_t chunk_size = 32 << 20;
|
std::shared_ptr<scanner_progress> pctx;
|
||||||
|
|
||||||
|
if (s >= kMinHasherProgressFileSize) {
|
||||||
|
pctx = prog.create_context<scanner_progress>(
|
||||||
|
termcolor::MAGENTA, kHashContext, path_as_string(), s);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr size_t chunk_size = 16 << 20;
|
||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
|
|
||||||
assert(mm);
|
assert(mm);
|
||||||
@ -236,6 +251,9 @@ void file::scan(mmif* mm, progress& prog,
|
|||||||
mm->release_until(offset);
|
mm->release_until(offset);
|
||||||
offset += chunk_size;
|
offset += chunk_size;
|
||||||
s -= chunk_size;
|
s -= chunk_size;
|
||||||
|
if (pctx) {
|
||||||
|
pctx->bytes_processed += chunk_size;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cs.update(mm->as<void>(offset), s);
|
cs.update(mm->as<void>(offset), s);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user