A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.
Rust
removal: Homebrew on Linux, Guix and the extra lib dirs are system trees; so are Windows' page and hibernation files
Tobi Lütke670407f37ed7
diff --git a/README.md b/README.mdindex 2476158..c42c800 100644--- a/README.md+++ b/README.md@@ -275,7 +275,8 @@ The same program, with Windows' answers to the questions above:before destroying anything it cannot recycle.- **Refused besides the rules below:** Windows, Program Files andProgramData, what Windows keeps at the top of its drive (System Volume- Information, Recovery, Boot), and any folder holding your profile, such as+ Information, Recovery, Boot, and the page and hibernation files, which+ Settings turns off), and any folder holding your profile, such as`C:\Users`. Names compare without regard to case, as Windows comparesthem.- **Hidden** means a name starting with a dot, or the hidden attribute, so@@ -298,7 +299,8 @@ tested:- a directory holding your home directory or a system tree is refused (onmacOS `/Users` is on the same volume as `/`, and `/opt` holds`/opt/homebrew`);-- system trees (`/usr`, `/etc`, `/boot`, `/var/lib`, `/nix/store`, …) are+- system trees (`/usr`, `/etc`, `/boot`, `/var/lib`, `/nix/store`,+ `/gnu/store`, Homebrew's prefix on macOS and Linux, …) arerefused even where permissions would allow it: packages own them, andpacman, paccache or `journalctl --vacuum` are the tools;- a symlink is unlinked, never followed;diff --git a/crates/disktree-core/src/removal.rs b/crates/disktree-core/src/removal.rsindex aa80e5e..c41843d 100644--- a/crates/disktree-core/src/removal.rs+++ b/crates/disktree-core/src/removal.rs@@ -160,14 +160,17 @@ pub fn plan(targets: &[Target], root: &Path) -> Plan {/// an app to the Trash is how macOS uninstalls it, and the apps macOS ships/// live on the read-only system volume anyway.#[cfg(not(windows))]-const SYSTEM_TREES: [&str; 20] = [+const SYSTEM_TREES: [&str; 24] = ["/bin","/boot","/dev","/etc","/lib","/lib64",+ "/lib32",+ "/libx32","/nix/store",+ "/gnu/store","/proc","/run","/sbin",@@ -175,6 +178,8 @@ const SYSTEM_TREES: [&str; 20] = ["/usr","/var/lib","/efi",+ // Homebrew on Linux, where it lives outside every user's home.+ "/home/linuxbrew/.linuxbrew",// macOS."/System","/Library",@@ -282,6 +287,11 @@ fn system_trees() -> Vec<PathBuf> {"Recovery","Boot","bootmgr",+ // Windows' memory: turned off in Settings (`powercfg /h off` for+ // hibernation), never deleted by hand.+ "pagefile.sys",+ "hiberfil.sys",+ "swapfile.sys",].map(|name| drive.join(name)),);@@ -2126,6 +2136,8 @@ mod tests {assert!(system(r"Program Files (x86)\App").is_some());assert!(system(r"ProgramData\Vendor\state.db").is_some());assert!(system("System Volume Information").is_some());+ assert!(system("pagefile.sys").is_some());+ assert!(system("HIBERFIL.SYS").is_some());assert_eq!(system("Windows.old"), None, "components, not prefixes");assert_eq!(system(r"Users\tobi\AppData\Local\Temp"), None);assert_eq!(system("Games"), None);@@ -2198,6 +2210,14 @@ mod tests {);assert_eq!(tree_of(Path::new("/var/cache/pacman/pkg"), home), None);assert_eq!(tree_of(Path::new("/opt/thing"), home), None);+ assert_eq!(+ tree_of(Path::new("/home/linuxbrew/.linuxbrew/Cellar"), home),+ Some("/home/linuxbrew/.linuxbrew")+ );+ assert_eq!(+ tree_of(Path::new("/gnu/store/abc-hello"), home),+ Some("/gnu/store")+ );assert_eq!(tree_of(Path::new("/usrlocal"), home),None,