Show current dir/file being scanned/written

This commit is contained in:
Marcus Holland-Moritz 2020-11-24 22:20:11 +01:00
parent 53589de8c8
commit b547ff2502
3 changed files with 46 additions and 2 deletions

View File

@ -32,11 +32,20 @@
namespace dwarfs { namespace dwarfs {
class file_interface;
class progress { class progress {
public: public:
progress(folly::Function<void(const progress&, bool)>&& func); progress(folly::Function<void(const progress&, bool)>&& func);
~progress() noexcept; ~progress() noexcept;
template <typename T>
void sync(T&& func) {
std::unique_lock<std::mutex> lock(mx_);
func();
}
std::atomic<file_interface const*> current{nullptr};
std::atomic<size_t> files_found{0}; std::atomic<size_t> files_found{0};
std::atomic<size_t> files_scanned{0}; std::atomic<size_t> files_scanned{0};
std::atomic<size_t> dirs_found{0}; std::atomic<size_t> dirs_found{0};

View File

@ -24,6 +24,8 @@
#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/date_time/posix_time/posix_time.hpp>
#include "dwarfs/console_writer.h" #include "dwarfs/console_writer.h"
#include "dwarfs/entry.h"
#include "dwarfs/inode.h"
namespace dwarfs { namespace dwarfs {
@ -45,7 +47,7 @@ console_writer::console_writer(std::ostream& os, bool show_progress,
void console_writer::rewind() { void console_writer::rewind() {
if (!statebuf_.empty()) { 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 << "\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<entry const*>(cp)) {
label = "scanning: ";
path = e->path();
} else if (auto i = dynamic_cast<inode const*>(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.links_scanned << "/" << p.links_found << " links, "
<< p.files_scanned << "/" << p.files_found << " files" << newline << p.files_scanned << "/" << p.files_found << " files" << newline

View File

@ -326,6 +326,7 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
switch (pe->type()) { switch (pe->type()) {
case entry::E_DIR: case entry::E_DIR:
prog.current.store(pe.get());
prog.dirs_found++; prog.dirs_found++;
pe->scan(*os_, prog); pe->scan(*os_, prog);
queue.push_back(pe); queue.push_back(pe);
@ -488,10 +489,13 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
block_manager bm(lgr_, prog, cfg_, os_, fsw); block_manager bm(lgr_, prog, cfg_, os_, fsw);
im->for_each_inode([&](std::shared_ptr<inode> const& ino) { im->for_each_inode([&](std::shared_ptr<inode> const& ino) {
prog.current.store(ino.get());
bm.add_inode(ino); bm.add_inode(ino);
prog.inodes_written++; prog.inodes_written++;
}); });
prog.sync([&] { prog.current.store(nullptr); });
log_.debug() << "waiting for block compression to finish..."; log_.debug() << "waiting for block compression to finish...";
bm.finish_blocks(); bm.finish_blocks();