Skip to content

Commit

Permalink
Fix traversal stats
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrwach committed Jan 14, 2024
1 parent 969e64b commit 96ef242
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/interactive/app/eventloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl AppState {
let props = MainWindowProps {
current_path: tree_view.current_path(self.navigation().view_root),
entries_traversed: self.stats.entries_traversed,
total_bytes: self.stats.total_bytes,
total_bytes: tree_view.total_size(),
start: self.stats.start,
elapsed: self.stats.elapsed,
display,
Expand Down Expand Up @@ -152,6 +152,7 @@ impl AppState {
};

if let Some(is_finished) = active_traversal.integrate_traversal_event(traversal, event) {
self.stats = active_traversal.stats;
if is_finished {
let root_index = active_traversal.root_idx;
self.recompute_sizes_recursively(traversal, root_index);
Expand Down Expand Up @@ -327,12 +328,9 @@ impl AppState {
if path.to_str().unwrap() == "" {
path = PathBuf::from(".");
}
log::info!("Refreshing {:?}", path);

let entries_deleted = tree.remove_entries(self.navigation().view_root, false);
log::info!("Deleted {entries_deleted} entries");

tree.remove_entries(self.navigation().view_root, false);
tree.recompute_sizes_recursively(self.navigation().view_root);

self.entries = tree.sorted_entries(self.navigation().view_root, self.sorting);
self.navigation_mut().selected = self.entries.first().map(|e| e.index);

Expand All @@ -343,6 +341,7 @@ impl AppState {
true,
)?);

// TODO: fix
self.received_events = false;
}
Refresh::AllInView => {
Expand Down
14 changes: 7 additions & 7 deletions src/interactive/app/tree_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ impl TreeView<'_> {
continue;
}
self.tree_mut().remove_node(nx);
// TODO: don't need this right?
// self.traversal.entries_traversed -= 1;
entries_deleted += 1;
}
entries_deleted
Expand All @@ -79,6 +77,13 @@ impl TreeView<'_> {
self.tree().node_weight(idx).is_some()
}

pub fn total_size(&self) -> u128 {
self.tree()
.neighbors_directed(self.traversal.root_index, Direction::Outgoing)
.filter_map(|idx| self.tree().node_weight(idx).map(|w| w.size))
.sum()
}

pub fn recompute_sizes_recursively(&mut self, mut index: TreeIndex) {
loop {
let size_of_children = self
Expand All @@ -97,11 +102,6 @@ impl TreeView<'_> {
Some(parent) => index = parent,
}
}
// TODO: don't need this right?
// self.traversal.total_bytes = self
// .tree()
// .node_weight(self.traversal.root_index)
// .map(|w| w.size);
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/interactive/widgets/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::interactive::SortMode;
pub struct Footer;

pub struct FooterProps {
pub total_bytes: Option<u128>,
pub total_bytes: u128,
pub entries_traversed: u64,
pub traversal_start: std::time::Instant,
pub elapsed: Option<std::time::Duration>,
Expand All @@ -37,7 +37,7 @@ impl Footer {

let spans = vec![
Span::from(format!(
"Sort mode: {} Total disk usage: {} Items: {} {progress} ",
"Sort mode: {} Total disk usage: {} Processed {} items {progress} ",
match sort_mode {
SortMode::SizeAscending => "size ascending",
SortMode::SizeDescending => "size descending",
Expand All @@ -46,10 +46,7 @@ impl Footer {
SortMode::CountAscending => "items ascending",
SortMode::CountDescending => "items descending",
},
match total_bytes {
Some(b) => format!("{}", format.display(*b)),
None => "-".to_owned(),
},
format!("{}", format.display(*total_bytes)),
entries_traversed,
progress = match elapsed {
Some(elapsed) => format!("in {:.02}s", elapsed.as_secs_f32()),
Expand Down
2 changes: 1 addition & 1 deletion src/interactive/widgets/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use FocussedPane::*;
pub struct MainWindowProps<'a> {
pub current_path: String,
pub entries_traversed: u64,
pub total_bytes: Option<u128>,
pub total_bytes: u128,
pub start: std::time::Instant,
pub elapsed: Option<std::time::Duration>,
pub display: DisplayOptions,
Expand Down
1 change: 1 addition & 0 deletions src/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ impl Traversal {
}
}

#[derive(Clone, Copy)]
pub struct TraversalStats {
/// Amount of files or directories we have seen during the filesystem traversal
pub entries_traversed: u64,
Expand Down

0 comments on commit 96ef242

Please sign in to comment.