Fix more bugs in directory size calculation
This commit is contained in:
parent
5f944a3059
commit
0c43b0b342
3 changed files with 65 additions and 34 deletions
10
src/app.rs
10
src/app.rs
|
|
@ -2453,7 +2453,7 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
Message::PendingPauseAll(pause) => {
|
||||
for (id, (_, _, controller)) in self.pending_operations.iter() {
|
||||
for (_id, (_, _, controller)) in self.pending_operations.iter() {
|
||||
if pause {
|
||||
controller.pause();
|
||||
} else {
|
||||
|
|
@ -4437,10 +4437,16 @@ impl Application for App {
|
|||
));
|
||||
}
|
||||
|
||||
let mut selected_preview = None;
|
||||
if self.core.window.show_context {
|
||||
if let ContextPage::Preview(entity_opt, PreviewKind::Selected) = self.context_page {
|
||||
selected_preview = Some(entity_opt.unwrap_or_else(|| self.tab_model.active()));
|
||||
}
|
||||
}
|
||||
for entity in self.tab_model.iter() {
|
||||
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
|
||||
subscriptions.push(
|
||||
tab.subscription()
|
||||
tab.subscription(selected_preview == Some(entity))
|
||||
.with(entity)
|
||||
.map(|(entity, tab_msg)| Message::TabMessage(Some(entity), tab_msg)),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1677,7 +1677,15 @@ impl Application for App {
|
|||
std::future::pending().await
|
||||
}),
|
||||
),
|
||||
self.tab.subscription().map(Message::TabMessage),
|
||||
self.tab
|
||||
.subscription(
|
||||
self.core.window.show_context
|
||||
&& matches!(
|
||||
self.context_page,
|
||||
ContextPage::Preview(_, PreviewKind::Selected)
|
||||
),
|
||||
)
|
||||
.map(Message::TabMessage),
|
||||
];
|
||||
|
||||
for (key, mounter) in MOUNTERS.iter() {
|
||||
|
|
|
|||
79
src/tab.rs
79
src/tab.rs
|
|
@ -4386,7 +4386,7 @@ impl Tab {
|
|||
widget::responsive(|size| self.view_responsive(key_binds, size)).into()
|
||||
}
|
||||
|
||||
pub fn subscription(&self) -> Subscription<Message> {
|
||||
pub fn subscription(&self, preview: bool) -> Subscription<Message> {
|
||||
let Some(items) = &self.items_opt else {
|
||||
return Subscription::none();
|
||||
};
|
||||
|
|
@ -4470,39 +4470,56 @@ impl Tab {
|
|||
}
|
||||
}
|
||||
|
||||
// Load directory size for selected items
|
||||
for item in items
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
// Item must be a selected directory
|
||||
item.selected && item.metadata.is_dir()
|
||||
})
|
||||
.chain(&self.parent_item_opt)
|
||||
{
|
||||
// Item must have a path
|
||||
let Some(path) = item.path_opt().map(|path| path.to_path_buf()) else {
|
||||
continue;
|
||||
};
|
||||
subscriptions.push(Subscription::run_with_id(
|
||||
("dir_size", path.clone()),
|
||||
stream::channel(1, |mut output| async move {
|
||||
let total_size = calculate_dir_size(&path);
|
||||
if preview {
|
||||
// Load directory size for selected items
|
||||
for item in items
|
||||
.iter()
|
||||
.filter(|item| {
|
||||
// Item must be a selected directory
|
||||
item.selected && item.metadata.is_dir()
|
||||
})
|
||||
.chain(&self.parent_item_opt)
|
||||
{
|
||||
// Item must have a path
|
||||
let Some(path) = item.path_opt().map(|path| path.to_path_buf()) else {
|
||||
continue;
|
||||
};
|
||||
subscriptions.push(Subscription::run_with_id(
|
||||
("dir_size", path.clone()),
|
||||
stream::channel(1, |mut output| async move {
|
||||
let message = {
|
||||
let path = path.clone();
|
||||
tokio::task::spawn_blocking(move || {
|
||||
let start = Instant::now();
|
||||
let total_size = calculate_dir_size(&path);
|
||||
log::debug!(
|
||||
"calculated directory size of {:?} in {:?}",
|
||||
path,
|
||||
start.elapsed()
|
||||
);
|
||||
Message::DirectorySize(path.clone(), total_size)
|
||||
})
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
match output
|
||||
.send(Message::DirectorySize(path.clone(), total_size))
|
||||
.await
|
||||
{
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
log::warn!("failed to send dirsize for {:?}: {}", &path, err);
|
||||
match output.send(message).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => {
|
||||
log::warn!(
|
||||
"failed to send directory size for {:?}: {}",
|
||||
&path,
|
||||
err
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::future::pending().await
|
||||
}),
|
||||
));
|
||||
// Only calculate size for one directory
|
||||
break;
|
||||
std::future::pending().await
|
||||
}),
|
||||
));
|
||||
// Only calculate size for one directory
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Load search items incrementally
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue