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) => {
|
Message::PendingPauseAll(pause) => {
|
||||||
for (id, (_, _, controller)) in self.pending_operations.iter() {
|
for (_id, (_, _, controller)) in self.pending_operations.iter() {
|
||||||
if pause {
|
if pause {
|
||||||
controller.pause();
|
controller.pause();
|
||||||
} else {
|
} 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() {
|
for entity in self.tab_model.iter() {
|
||||||
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
|
if let Some(tab) = self.tab_model.data::<Tab>(entity) {
|
||||||
subscriptions.push(
|
subscriptions.push(
|
||||||
tab.subscription()
|
tab.subscription(selected_preview == Some(entity))
|
||||||
.with(entity)
|
.with(entity)
|
||||||
.map(|(entity, tab_msg)| Message::TabMessage(Some(entity), tab_msg)),
|
.map(|(entity, tab_msg)| Message::TabMessage(Some(entity), tab_msg)),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1677,7 +1677,15 @@ impl Application for App {
|
||||||
std::future::pending().await
|
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() {
|
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()
|
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 {
|
let Some(items) = &self.items_opt else {
|
||||||
return Subscription::none();
|
return Subscription::none();
|
||||||
};
|
};
|
||||||
|
|
@ -4470,39 +4470,56 @@ impl Tab {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load directory size for selected items
|
if preview {
|
||||||
for item in items
|
// Load directory size for selected items
|
||||||
.iter()
|
for item in items
|
||||||
.filter(|item| {
|
.iter()
|
||||||
// Item must be a selected directory
|
.filter(|item| {
|
||||||
item.selected && item.metadata.is_dir()
|
// Item must be a selected directory
|
||||||
})
|
item.selected && item.metadata.is_dir()
|
||||||
.chain(&self.parent_item_opt)
|
})
|
||||||
{
|
.chain(&self.parent_item_opt)
|
||||||
// Item must have a path
|
{
|
||||||
let Some(path) = item.path_opt().map(|path| path.to_path_buf()) else {
|
// Item must have a path
|
||||||
continue;
|
let Some(path) = item.path_opt().map(|path| path.to_path_buf()) else {
|
||||||
};
|
continue;
|
||||||
subscriptions.push(Subscription::run_with_id(
|
};
|
||||||
("dir_size", path.clone()),
|
subscriptions.push(Subscription::run_with_id(
|
||||||
stream::channel(1, |mut output| async move {
|
("dir_size", path.clone()),
|
||||||
let total_size = calculate_dir_size(&path);
|
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
|
match output.send(message).await {
|
||||||
.send(Message::DirectorySize(path.clone(), total_size))
|
Ok(()) => {}
|
||||||
.await
|
Err(err) => {
|
||||||
{
|
log::warn!(
|
||||||
Ok(()) => {}
|
"failed to send directory size for {:?}: {}",
|
||||||
Err(err) => {
|
&path,
|
||||||
log::warn!("failed to send dirsize for {:?}: {}", &path, err);
|
err
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
std::future::pending().await
|
std::future::pending().await
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
// Only calculate size for one directory
|
// Only calculate size for one directory
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load search items incrementally
|
// Load search items incrementally
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue