Add progress indicator to hardlink counting + fix import/mem UI updating

This commit is contained in:
Yorhel 2024-07-28 10:54:55 +02:00
parent 0a6bcee32b
commit 87d336baeb
4 changed files with 31 additions and 6 deletions

View file

@ -456,7 +456,7 @@ fn item(ctx: *Ctx, parent: ?*sink.Dir, dev: u64) void {
parent.?.addStat(ctx.sink, name, &ctx.stat); parent.?.addStat(ctx.sink, name, &ctx.stat);
} }
if ((ctx.sink.files_seen.load(.monotonic) & 1024) == 0) if ((ctx.sink.files_seen.load(.monotonic) & 65) == 0)
main.handleEvent(false, false); main.handleEvent(false, false);
} }

View file

@ -35,7 +35,7 @@ const Ctx = struct {
fn rec(ctx: *Ctx, dir: *sink.Dir, entry: *model.Entry) void { fn rec(ctx: *Ctx, dir: *sink.Dir, entry: *model.Entry) void {
if ((ctx.sink.files_seen.load(.monotonic) & 1024) == 0) if ((ctx.sink.files_seen.load(.monotonic) & 65) == 0)
main.handleEvent(false, false); main.handleEvent(false, false);
ctx.stat = toStat(entry); ctx.stat = toStat(entry);

View file

@ -417,13 +417,29 @@ pub const inodes = struct {
} }
} }
// counters to track progress for addAllStats()
pub var add_total: usize = 0;
pub var add_done: usize = 0;
pub fn addAllStats() void { pub fn addAllStats() void {
if (uncounted_full) { if (uncounted_full) {
add_total = map.count();
add_done = 0;
var it = map.keyIterator(); var it = map.keyIterator();
while (it.next()) |e| setStats(e.*, true); while (it.next()) |e| {
setStats(e.*, true);
add_done += 1;
if ((add_done & 65) == 0) main.handleEvent(false, false);
}
} else { } else {
add_total = uncounted.count();
add_done = 0;
var it = uncounted.keyIterator(); var it = uncounted.keyIterator();
while (it.next()) |u| if (map.getKey(u.*)) |e| setStats(e, true); while (it.next()) |u| {
if (map.getKey(u.*)) |e| setStats(e, true);
add_done += 1;
if ((add_done & 65) == 0) main.handleEvent(false, false);
}
} }
uncounted_full = false; uncounted_full = false;
if (uncounted.count() > 0) if (uncounted.count() > 0)

View file

@ -295,7 +295,11 @@ fn drawConsole() void {
} }
if (global.state == .hlcnt) { if (global.state == .hlcnt) {
wr.writeAll("Counting hardlinks...\n") catch {}; wr.writeAll("Counting hardlinks...") catch {};
if (model.inodes.add_total > 0)
wr.print(" {} / {}", .{ model.inodes.add_done, model.inodes.add_total }) catch {};
wr.writeByte('\n') catch {};
st.lines_written += 1;
} else if (global.state == .running) { } else if (global.state == .running) {
var bytes: u64 = 0; var bytes: u64 = 0;
@ -445,7 +449,12 @@ pub fn draw() void {
.hlcnt => { .hlcnt => {
const box = ui.Box.create(4, ui.cols -| 5, "Finalizing"); const box = ui.Box.create(4, ui.cols -| 5, "Finalizing");
box.move(2, 2); box.move(2, 2);
ui.addstr("Counting hardlinks..."); ui.addstr("Counting hardlinks... ");
if (model.inodes.add_total > 0) {
ui.addnum(.default, model.inodes.add_done);
ui.addstr(" / ");
ui.addnum(.default, model.inodes.add_total);
}
}, },
.running => drawProgress(), .running => drawProgress(),
}, },