From b547ff2502b8740709f11a87dd2d51ff6f54f45b Mon Sep 17 00:00:00 2001 From: Marcus Holland-Moritz Date: Tue, 24 Nov 2020 22:20:11 +0100 Subject: [PATCH] Show current dir/file being scanned/written --- include/dwarfs/progress.h | 9 +++++++++ src/dwarfs/console_writer.cpp | 35 +++++++++++++++++++++++++++++++++-- src/dwarfs/scanner.cpp | 4 ++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/include/dwarfs/progress.h b/include/dwarfs/progress.h index f908a539..74cb3574 100644 --- a/include/dwarfs/progress.h +++ b/include/dwarfs/progress.h @@ -32,11 +32,20 @@ namespace dwarfs { +class file_interface; + class progress { public: progress(folly::Function&& func); ~progress() noexcept; + template + void sync(T&& func) { + std::unique_lock lock(mx_); + func(); + } + + std::atomic current{nullptr}; std::atomic files_found{0}; std::atomic files_scanned{0}; std::atomic dirs_found{0}; diff --git a/src/dwarfs/console_writer.cpp b/src/dwarfs/console_writer.cpp index 8909f74b..bb0784aa 100644 --- a/src/dwarfs/console_writer.cpp +++ b/src/dwarfs/console_writer.cpp @@ -24,6 +24,8 @@ #include #include "dwarfs/console_writer.h" +#include "dwarfs/entry.h" +#include "dwarfs/inode.h" namespace dwarfs { @@ -45,7 +47,7 @@ console_writer::console_writer(std::ostream& os, bool show_progress, void console_writer::rewind() { if (!statebuf_.empty()) { - os_ << "\x1b[A\r\x1b[A\x1b[A\x1b[A\x1b[A\x1b[A"; + os_ << "\x1b[A\r\x1b[A\x1b[A\x1b[A\x1b[A\x1b[A\x1b[A"; } } @@ -98,7 +100,36 @@ void console_writer::update(const progress& p, bool last) { oss << "\n"; } - oss << "found/scanned: " << p.dirs_scanned << "/" << p.dirs_found << " dirs, " + auto cp = p.current.load(); + std::string label, path; + + if (cp) { + if (auto e = dynamic_cast(cp)) { + label = "scanning: "; + path = e->path(); + } else if (auto i = dynamic_cast(cp)) { + label = "writing: "; + path = i->any()->path(); + } + auto max_len = width_ - label.size(); + auto len = path.size(); + if (len > max_len) { + // TODO: get this correct for UTF8 multibyte chars :-) + size_t start = 0; + max_len -= 1; + while (start != std::string::npos && (len - start) > max_len) { + start = path.find('/', start + 1); + } + if (start == std::string::npos) { + start = max_len - len; + } + path.replace(0, start, "…"); + } + } + + oss << label << path << newline + + << "scanned/found: " << p.dirs_scanned << "/" << p.dirs_found << " dirs, " << p.links_scanned << "/" << p.links_found << " links, " << p.files_scanned << "/" << p.files_found << " files" << newline diff --git a/src/dwarfs/scanner.cpp b/src/dwarfs/scanner.cpp index b1a7e7a9..c5137348 100644 --- a/src/dwarfs/scanner.cpp +++ b/src/dwarfs/scanner.cpp @@ -326,6 +326,7 @@ void scanner_::scan(filesystem_writer& fsw, switch (pe->type()) { case entry::E_DIR: + prog.current.store(pe.get()); prog.dirs_found++; pe->scan(*os_, prog); queue.push_back(pe); @@ -488,10 +489,13 @@ void scanner_::scan(filesystem_writer& fsw, block_manager bm(lgr_, prog, cfg_, os_, fsw); im->for_each_inode([&](std::shared_ptr const& ino) { + prog.current.store(ino.get()); bm.add_inode(ino); prog.inodes_written++; }); + prog.sync([&] { prog.current.store(nullptr); }); + log_.debug() << "waiting for block compression to finish..."; bm.finish_blocks();