A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.
Rust
Keep a snapshot-booted root's subvolumes, and stat directories on macOS
Tobi Lütkefcb627634fb6
diff --git a/crates/disktree-core/src/macos.rs b/crates/disktree-core/src/macos.rsindex 1651766..6cdac06 100644--- a/crates/disktree-core/src/macos.rs+++ b/crates/disktree-core/src/macos.rs@@ -460,9 +460,13 @@ impl<'a> Cursor<'a> {self.at += 8;let flags = self.u32()?;let inode = self.u64()?;- // A directory's own size is never measured; its entries are.+ // A directory is stated the ordinary way. A mount point is listed+ // with the attributes of the directory it covers, so its DEVID is+ // the parent volume's, and the walk would cross into every disk,+ // share and system volume mounted below the root. `statat` reads+ // the mounted root, as `lstat` did; directories are few beside files.let (links, allocated, apparent) = if kind == Kind::Directory {- (1, 0, 0)+ return Ok(None);} else if file & FILE_ATTRIBUTES == FILE_ATTRIBUTES {(self.u32()?, self.u64()?, self.u64()?)} else {diff --git a/crates/disktree-core/src/space.rs b/crates/disktree-core/src/space.rsindex e4abf77..8a2bc4e 100644--- a/crates/disktree-core/src/space.rs+++ b/crates/disktree-core/src/space.rs@@ -269,14 +269,16 @@ fn covering<'a>(mounts: &'a [Mount], path: &Path) -> Option<&'a Mount> {/// source: its files share their blocks with the live ones, so removing them/// gives back almost nothing, and the scan keeps out of it for the same/// reason. The mount the scan itself asked for is kept at all events, since-/// removing something there empties the very space the meter reads.+/// removing something there empties the very space the meter reads. Only+/// the other mount is tested, as [`foreign_mounts`] does: a system booted+/// from a snapshot (openSUSE's Snapper default) has one at `/`, and its+/// `/var` and `/home` are still the scan's own.fn same_volume(own: &Mount, other: &Mount) -> bool {if own.point == other.point {return true;}own.source == other.source&& own.fstype == other.fstype- && !is_snapshot(own)&& !is_snapshot(other)}@@ -1133,6 +1135,25 @@ portal /run/user/1000/doc fuse.portal rw 0 0);}+ /// openSUSE boots from a Snapper snapshot, so `/` itself is one; the+ /// scan still walks `/var` and `/home`, and so does the projection.+ #[test]+ fn a_root_booted_from_a_snapshot_keeps_its_subvolumes() {+ let mounts = parse_mounts(+ "/dev/vda2 / btrfs rw,subvol=/@/.snapshots/1/snapshot 0 0\n\+ /dev/vda2 /var btrfs rw,subvol=/@/var 0 0\n\+ /dev/vda2 /home btrfs rw,subvol=/@/home 0 0\n",+ );+ assert!(foreign_mounts(&mounts, Path::new("/")).is_empty());+ for path in ["/var/cache/x", "/home/me/x", "/usr/x"] {+ assert_eq!(+ attribution(Some(&mounts), Path::new("/"), Path::new(path)),+ Attribution::Scanned,+ "{path}"+ );+ }+ }+#[test]fn a_table_that_does_not_place_a_path_claims_nothing() {let partial = parse_mounts("/dev/sdb1 /data ext4 rw 0 0\n");