Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ and removes duplicate hardlinks.

Press `v` (or click **Volumes** beside the disk name in the side panel) to
bring up the volume picker. It lists every candidate volume mounted on the
system together with its free space, ordered fullest first, filtering out
system together with its free space, by name, filtering out
pseudo-filesystems and duplicate btrfs/APFS mount points. Selecting any
entry resets the scan root directly to that volume.

Expand Down
11 changes: 11 additions & 0 deletions crates/disktree-app/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ impl Disktree {
});
}
volumes.retain(|volume| volume.point != root_path);
by_name(&mut volumes);
volumes
});
cx.spawn(async move |this, cx| {
Expand Down Expand Up @@ -3147,6 +3148,16 @@ pub fn now_seconds() -> i64 {
})
}

/// Order the picker's volumes by name, as a file manager lists drives: a
/// volume is found where its letter or name says, however full it happens
/// to be. Without regard to case, so `/Volumes/archive` is not sent below
/// every capital.
pub fn by_name(volumes: &mut [disktree_core::space::Volume]) {
volumes.sort_by_cached_key(|volume| {
volume.point.to_string_lossy().to_lowercase()
});
}

/// Let go of a tree off the UI thread: freeing a disk's millions of nodes
/// takes a good part of a second, and nothing waits on it.
fn discard(tree: Option<Arc<Node>>) {
Expand Down
16 changes: 16 additions & 0 deletions crates/disktree-app/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,3 +1844,19 @@ fn the_power_menu_offers_only_what_the_cpus_can_tell_apart(
draw(cx);
assert!(read(&view, cx, |app| app.power_menu.is_none()));
}

#[test]
fn the_volume_picker_lists_volumes_by_name() {
let volume = |point: &str| Volume {
point: PathBuf::from(point),
device: None,
space: None,
};
let mut volumes = vec![volume("E:\\"), volume("c:\\"), volume("D:\\")];
crate::state::by_name(&mut volumes);
let order: Vec<_> = volumes
.iter()
.map(|volume| volume.point.to_string_lossy().into_owned())
.collect();
assert_eq!(order, ["c:\\", "D:\\", "E:\\"]);
}