A treemap for finding and removing what fills your disk, for Omarchy. Rust + GPUI.
Rust
build: embed static Linux scanners and deploy them on demand
Tobi Lutke2c22ed4d0090
diff --git a/.github/workflows/release.yml b/.github/workflows/release.ymlindex 04712f5..9ca399c 100644--- a/.github/workflows/release.yml+++ b/.github/workflows/release.yml@@ -91,7 +91,9 @@ jobs:run: cargo xtask test- name: Build- run: cargo build --release --locked -p disktree-app+ run: |+ rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl+ cargo xtask portable- name: Packageid: package@@ -101,8 +103,8 @@ jobs:run: |name="disktree-$VERSION-$ARCH-linux"mkdir -p "dist/$name"- cp target/release/disktree "dist/$name/"- strip "dist/$name/disktree"+ # portable strips before appending; stripping again loses helpers.+ cp target/portable/disktree "dist/$name/"cp packaging/install.sh packaging/disktree.desktop.in \assets/disktree.svg README.md LICENSE "dist/$name/"echo "$VERSION" > "dist/$name/VERSION"diff --git a/Makefile b/Makefileindex b3c8fcc..5b7a410 100644--- a/Makefile+++ b/Makefile@@ -23,22 +23,45 @@ UNAME := $(shell uname -s)MANIFEST = Cargo.tomlCARGO ?= cargoTARGET = target/release/disktree+ifeq ($(UNAME),Linux)+TARGET = target/portable/disktree+endifICON = assets/disktree.svgDESKTOP = packaging/disktree.desktop.in-.PHONY: help build run install uninstall bundle lint test ci fmt clean+# Being on PATH is not enough: an older package can win earlier in it.+define check_install_path+ @resolved=$$(command -v $(1) 2>/dev/null || true); \+ if [ -n "$$resolved" ] && [ "$$resolved" -ef "$(BINDIR)/$(1)" ]; then \+ :; \+ else \+ echo; \+ if [ -n "$$resolved" ]; then \+ echo "warning: $(1) still resolves to $$resolved"; \+ echo " that hides the build in $(BINDIR)"; \+ else \+ echo "warning: $(BINDIR) is not on PATH"; \+ fi; \+ printf 'Run in your shell: export PATH="%s:$$PATH"\n' "$(BINDIR)"; \+ echo "Then add that PATH setting to your shell configuration."; \+ fi+endef++.PHONY: help build run install install-scan uninstall bundle lint test test-ssh ci fmt cleanhelp:@echo "disktree"@echo@echo " make build release build"@echo " make run build and run, scanning $$HOME"+ @echo " make install-scan build/install the headless SSH helper only"@echo " make install install to $(PREFIX): binary, desktop entry, icon"@echo " (macOS: disktree.app into $(APPS))"@echo " make bundle macOS: build target/bundle/disktree.app and its zip"@echo " make uninstall remove what install put there"@echo " make lint rustfmt --check and clippy -D warnings"@echo " make test core and window-harness tests"+ @echo " make test-ssh real localhost SSH tests (Linux: bun, openssh)"@echo " make ci lint, then test"@echo " make fmt format in place"@echo " make clean cargo clean"@@ -47,7 +70,18 @@ help:# make file-target would only compare the binary against the manifest and# happily install a stale build.build:+ifeq ($(UNAME),Linux)+ $(CARGO) xtask portable+else$(CARGO) build --release+endif++# For servers: no desktop, GPU, GPUI build, or elevated permissions needed.+install-scan:+ $(CARGO) build --release -p disktree-scan+ install -d "$(BINDIR)"+ install -m755 target/release/disktree-scan "$(BINDIR)/disktree-scan"+ $(call check_install_path,disktree-scan)run: build$(TARGET)@@ -58,6 +92,10 @@ lint:test:$(CARGO) xtask test+# Isolated keys and high localhost port; never uses a real server or root.+test-ssh:+ bun scripts/test-ssh.ts+ci: lint testfmt:@@ -76,8 +114,7 @@ install:@echo "installed:"@echo " $(APPS)/disktree.app"@echo " $(BINDIR)/disktree -> the app's binary"- @case ":$$PATH:" in *":$(BINDIR):"*) ;; *) \- echo; echo "note: $(BINDIR) is not on PATH in this shell";; esac+ $(call check_install_path,disktree)uninstall:rm -rf "$(APPS)/disktree.app"@@ -103,8 +140,7 @@ install: build@if command -v desktop-file-validate >/dev/null 2>&1; then \desktop-file-validate $(APPDIR)/disktree.desktop || true; \fi- @case ":$$PATH:" in *":$(BINDIR):"*) ;; *) \- echo; echo "note: $(BINDIR) is not on PATH in this shell";; esac+ $(call check_install_path,disktree)uninstall:rm -f $(BINDIR)/disktree $(APPDIR)/disktree.desktop $(ICONDIR)/disktree.svgdiff --git a/README.md b/README.mdindex 8044269..5dc8df5 100644--- a/README.md+++ b/README.md@@ -50,6 +50,17 @@ the release binary:yay -S disktree-bin```+If another installed version wins on `PATH`, the installer warns which one.+Run `export PATH="$HOME/.local/bin:$PATH"` and add that setting to your shell+configuration so the locally installed build takes precedence.++For Linux builds with embedded SSH helpers, also install the two Rust+standard-library targets (no external C cross-compiler is needed):++```sh+rustup target add x86_64-unknown-linux-musl aarch64-unknown-linux-musl+```+You need Rust 1.97 or newer and a Wayland or X11 session with a GPU that GPUIcan drive (Vulkan). Distributions often package an older Rust;[rustup](https://rustup.rs) installs a current one. The repo pins 1.97 in@@ -133,6 +144,104 @@ disktree ~/src # or any directorydisktree --help # options: apparent size, follow links, skip hidden, …```+### Servers over SSH (read-only)++```sh+disktree ssh dev # remote home; dev is an SSH config alias+disktree ssh user@server /var # an explicit remote path+disktree ssh dev --disk # the disk containing the remote home+disktree ssh dev -a /srv # apparent size instead of allocated blocks+```++Linux builds made with `make build` / `cargo xtask portable` include static+**x86-64 and ARM64 Linux scanners appended to the executable**. SSH detects+the server's OS/CPU and uploads the matching scanner only when its checked+cache is missing or damaged. The cache is private and content-addressed under+`~/.cache/disktree/ssh/<sha256>/` (or the server's `XDG_CACHE_HOME`).+Uploads are checksum-verified and atomically installed; there is no sudo,+system-package change or dependency on the server's glibc version.++This uses stable Rust's musl targets rather than Cosmopolitan: the existing+Rust/rayon/rustix scanner has no supported stable Cosmopolitan target. These+are Linux binaries, not a single executable for every OS; ARM64 is built and+ELF-validated, while x86-64 was also executed against a real server.++You can extract a helper without opening a window, or test the entire+SSH/deployment/scan path headlessly:++```sh+disktree extract-scanner x86_64 ./disktree-scan+disktree extract-scanner aarch64 ./disktree-scan-arm64+disktree ssh dev --check /var/log+```++The appended manifest stores architecture, byte ranges and SHA-256 hashes.+Do not run `strip` after packaging: it discards the trailer. The Linux release+pipeline strips first, embeds last, and ships that single file. Appending to+signed macOS/Windows executables needs platform-specific signature handling;+those builds do not yet embed helpers.++For a development or non-Linux desktop build without the trailer, install+the small **disktree-scan** helper on the server first:++```sh+# On the server, inside the checkout:+make install-scan # ~/.local/bin/disktree-scan; no GUI deps+# Or:+cargo install --path crates/disktree-scan --locked+```++The helper can be on the server's **non-interactive SSH PATH** or at+`~/.local/bin/disktree-scan` (the default install location); disktree tries+both. A binary copied from another machine must match the server's OS,+architecture and runtime. The manually built native helper may need the+server's libc; the embedded Linux helpers are static. Disktree never runs+sudo or changes the server's configuration.+SSH keeps your normal authentication settings. When launched from a+terminal, it can ask for a password or key passphrase there; GUI launches+need key/agent access or a working SSH askpass helper. Connect once with+`ssh dev` to verify access and accept its host key.++The headless helper reuses the parallel scanner: allocated blocks, hardlink+deduplication, hidden entries and mount boundaries have the same semantics as+a local scan. One compressed SSH connection carries a versioned JSON request+on stdin and compact postorder records on stdout. File contents never cross+the connection, and paths are never interpolated into a remote shell command.+The complete tree is retained for offline navigation; very large trees still+require memory proportional to their entry count.++Remote mode is **export-only**. Mark with Space, open review with `c`, then:++- **Copy as prompt** (`a`): includes the SSH host, remote OS, scan root,+ selected paths, sizes and cleanup precautions. It requires verifying the+ actual scanned hostname and machine ID before any destructive operation,+ and stopping if either check fails or cannot be performed.+- **Save list…** (`s`): remote paths, one per line, saved locally.+- **Copy delete script** (`y`), or **Save delete script…** (`e`): a+ GNU/Linux shell script, copied to the clipboard or saved locally.+ Running it without arguments only previews the selection. After reviewing+ it, `sh disktree-delete.sh --delete` connects to the named SSH host and+ runs the exported commands there, never against the local paths.++There are no trash/delete buttons or removal-mode choices in remote review.+Deletion shortcuts and removal entry points are disabled too. Git inspection,+local folder selection and file-manager reveal are disabled so remote names+cannot accidentally act on this computer. Free space is sampled when the+scan completes, **not live**; press `r` to refresh.++Before deleting, scripts compare the server's actual kernel hostname and+machine ID against the identity captured in the scan—not the SSH alias.+Missing identity or any mismatch aborts. The check runs on the SSH target,+not the computer launching the wrapper. Pasting the script previews it by+default and runs in a subshell, so its exit cannot close your terminal.++Exports are not an automatic cleanup recommendation. Scripts refuse system+paths, the scan root, home or its ancestors, symlinked/changed canonical paths,+and paths containing mount points. Control-character names are omitted.+These checks do not eliminate filesystem races or tell you whether git work+is backed up; review the script and prefer a tool's own cleanup command for+tool-owned data. The remote helper itself has no delete operation.+### The screen- **Top:** the trail from `/`, then what is measured — **Size**, **Files** or@@ -389,6 +498,7 @@ windowrule = size 1400 900, class:^(disktree)$make run # release build, scanning $HOMEmake lint # rustfmt --check, then clippy with every warning an errormake test # scanner, layout and removal tests, plus window-harness tests+make test-ssh # real localhost SSH scans/errors; Linux, bun + openssh requiredmake ci # lint, then test```diff --git a/crates/disktree-app/src/main.rs b/crates/disktree-app/src/main.rsindex 0811001..cd9fe66 100644--- a/crates/disktree-app/src/main.rs+++ b/crates/disktree-app/src/main.rs@@ -312,7 +312,8 @@ fn parse_args_with_power(let mut args = args.peekable();let remote = if args.peek().is_some_and(|arg| arg == "ssh") {args.next();- let host = text(args.next(), "ssh needs a host, e.g. disktree ssh dev")?;+ let host =+ text(args.next(), "ssh needs a host, e.g. disktree ssh dev")?;disktree_core::remote::validate_host(&host)?;Some(host)} else {diff --git a/crates/disktree-app/src/views.rs b/crates/disktree-app/src/views.rsindex bf3fc34..db7214a 100644--- a/crates/disktree-app/src/views.rs+++ b/crates/disktree-app/src/views.rs@@ -2294,7 +2294,9 @@ fn key_bar(app: &Disktree, theme: &Theme, cx: &App) -> Div {/// What the viewport shows while the first scan is running.fn scanning_panel(- app: &Disktree, theme: &Theme, cx: &Context<'_, Disktree>,+ app: &Disktree,+ theme: &Theme,+ cx: &Context<'_, Disktree>,) -> Div {if let Some(error) = &app.scan_error {return div()@@ -2331,7 +2333,8 @@ fn scanning_panel(.child(widgets::hint("r", "retry scan", cx));}let progress = &app.progress;- let cancelled = app.scan.is_none() && app.remote_scan.is_none() && progress.cancelled;+ let cancelled =+ app.scan.is_none() && app.remote_scan.is_none() && progress.cancelled;div().debug_selector(|| "scan-reading".into()).flex()diff --git a/packaging/install.sh b/packaging/install.shindex 25d8464..92e1a4d 100755--- a/packaging/install.sh+++ b/packaging/install.sh@@ -29,7 +29,15 @@ echo "installed disktree $VERSION:"echo " $BINDIR/disktree"echo " $APPDIR/disktree.desktop"echo " $ICONDIR/disktree.svg"-case ":$PATH:" in- *":$BINDIR:"*) ;;- *) echo; echo "note: $BINDIR is not on PATH in this shell" ;;-esac+resolved=$(command -v disktree 2>/dev/null || true)+if [ -z "$resolved" ] || ! [ "$resolved" -ef "$BINDIR/disktree" ]; then+ echo+ if [ -n "$resolved" ]; then+ echo "warning: disktree still resolves to $resolved"+ echo " that hides the build in $BINDIR"+ else+ echo "warning: $BINDIR is not on PATH"+ fi+ printf '%s\n' "Run in your shell: export PATH=\"$BINDIR:\$PATH\""+ echo "Then add that PATH setting to your shell configuration."+fidiff --git a/scripts/test-ssh.ts b/scripts/test-ssh.tsnew file mode 100644index 0000000..9326758--- /dev/null+++ b/scripts/test-ssh.ts@@ -0,0 +1,52 @@+// Optional Linux integration test: isolated unprivileged OpenSSH server.+// No user SSH keys/configuration or remote hosts are used or changed.+// Run with: bun scripts/test-ssh.ts+import {mkdtempSync, readFileSync, writeFileSync, rmSync} from 'node:fs';+import {spawn, spawnSync} from 'node:child_process';+import {tmpdir, userInfo} from 'node:os';+import {join} from 'node:path';+import {createServer} from 'node:net';++const dir = mkdtempSync(join(tmpdir(), 'disktree-ssh-test-'));+let server;+function run(cmd, args, env = process.env) {+ const result = spawnSync(cmd, args, {env, encoding:'utf8'});+ if (result.stdout) process.stdout.write(result.stdout);+ if (result.stderr) process.stderr.write(result.stderr);+ if (result.status !== 0) throw new Error(`${cmd} exited ${result.status}`);+}+try {+ run('cargo', ['xtask', 'portable']);+ const socket = createServer();+ await new Promise(resolve => socket.listen(0, '127.0.0.1', resolve));+ const port = socket.address().port;+ await new Promise(resolve => socket.close(resolve));+ for (const key of ['host', 'client']) {+ run('ssh-keygen', ['-q','-t','ed25519','-N','','-f',join(dir,key)]);+ }+ const config = join(dir, 'sshd_config');+ writeFileSync(config, `Port ${port}\nListenAddress 127.0.0.1\nHostKey ${dir}/host\nAuthorizedKeysFile ${dir}/client.pub\nStrictModes no\nUsePAM no\nPasswordAuthentication no\nKbdInteractiveAuthentication no\nPidFile ${dir}/pid\nLogLevel VERBOSE\n`);+ const client = join(dir,'ssh_config');+ writeFileSync(join(dir,'known_hosts'), `[127.0.0.1]:${port} ${readFileSync(join(dir,'host.pub'),'utf8')}`);+ writeFileSync(client, `Host fixture\n HostName 127.0.0.1\n Port ${port}\n User ${userInfo().username}\n IdentityFile ${dir}/client\n IdentitiesOnly yes\n BatchMode yes\n UserKnownHostsFile ${dir}/known_hosts\n StrictHostKeyChecking yes\n ConnectTimeout 5\n`);+ server = spawn('/usr/bin/sshd', ['-D','-e','-f',config], {stdio:['ignore','ignore','pipe']});+ let log='';+ await new Promise((resolve,reject) => {+ const timer = setTimeout(()=>reject(new Error('sshd startup timed out: '+log)),5000);+ server.stderr.on('data', data => {+ log += data;+ if(log.includes('Server listening')) {clearTimeout(timer); resolve();}+ });+ server.on('exit',code=>{clearTimeout(timer); reject(new Error(`sshd exited ${code}: ${log}`));});+ });+ console.log(`Testing a real SSH connection to isolated sshd on localhost:${port}`);+ run('ssh',['-F',client,'fixture','true']);+ run('cargo',['test','-p','disktree-core','real_ssh_transport_','--','--ignored','--nocapture'], {...process.env,DISKTREE_TEST_SSH_CONFIG:client,DISKTREE_TEST_HELPER:join(process.cwd(),`target/${process.arch === 'arm64' ? 'aarch64' : 'x86_64'}-unknown-linux-musl/release/disktree-scan`),DISKTREE_TEST_ARCHIVE:join(process.cwd(),'target/portable/disktree')});+ console.log('REAL SSH SCAN PASSED. Temporary host key, client key and server will be removed.');+} finally {+ if (server && server.exitCode === null) {+ server.kill('SIGTERM');+ await new Promise(resolve=>server.once('exit',resolve));+ }+ rmSync(dir, {recursive:true, force:true});+}diff --git a/xtask/src/main.rs b/xtask/src/main.rsindex ce225e5..53cd092 100644--- a/xtask/src/main.rs+++ b/xtask/src/main.rs@@ -7,6 +7,7 @@//! signal CI gives.mod bundle;+mod portable;use std::process::{Command, ExitCode, Stdio};@@ -20,7 +21,7 @@ tasks:clippy clippy --workspace --all-targets -- -D warningstest cargo test --workspaceci lint, then test- bundle macOS: target/bundle/disktree.app and its zip+ portable Linux: desktop executable with static x86_64/ARM64 scanners\n bundle macOS: target/bundle/disktree.app and its zip--sign IDENTITY sign with a Developer ID (default: ad hoc)--notarize notarize and staple; needs NOTARY_PROFILE, orNOTARY_KEY, NOTARY_KEY_ID and NOTARY_ISSUER@@ -38,6 +39,7 @@ fn main() -> ExitCode {"test" => test(),"ci" => fmt(false).and_then(|()| clippy()).and_then(|()| test()),"bundle" => bundle::bundle(&args[1..]),+ "portable" => portable::build(),"help" | "-h" | "--help" => {println!("{USAGE}");return ExitCode::SUCCESS;diff --git a/xtask/src/portable.rs b/xtask/src/portable.rsnew file mode 100644index 0000000..b101dfb--- /dev/null+++ b/xtask/src/portable.rs@@ -0,0 +1,81 @@+//! Static Linux helpers and an appended, verifiable executable trailer.+use std::path::{Path, PathBuf};+use std::process::Command;++pub fn build() -> Result<(), String> {+ if !cfg!(target_os = "linux") {+ return Err("portable packaging currently runs on Linux".into());+ }+ super::run(&["build", "--release", "--locked", "-p", "disktree-app"])?;+ let root = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();+ let target = std::env::var_os("CARGO_TARGET_DIR")+ .map_or_else(|| root.join("target"), PathBuf::from);+ let rustc = |args: &[&str]| -> Result<String, String> {+ let output = Command::new("rustc")+ .args(args)+ .output()+ .map_err(|e| e.to_string())?;+ if !output.status.success() {+ return Err(String::from_utf8_lossy(&output.stderr).into_owned());+ }+ Ok(String::from_utf8_lossy(&output.stdout).trim().into())+ };+ let sysroot = rustc(&["--print", "sysroot"])?;+ let version = rustc(&["-vV"])?;+ let host = version+ .lines()+ .find_map(|line| line.strip_prefix("host: "))+ .ok_or("rustc did not report a host triple")?;+ let linker = Path::new(&sysroot)+ .join("lib/rustlib")+ .join(host)+ .join("bin/rust-lld");+ let mut helpers = Vec::new();+ for arch in ["x86_64", "aarch64"] {+ let triple = format!("{arch}-unknown-linux-musl");+ let key = format!(+ "CARGO_TARGET_{}_LINKER",+ triple.to_uppercase().replace('-', "_")+ );+ let status = Command::new("cargo")+ .args([+ "build",+ "--release",+ "--locked",+ "-p",+ "disktree-scan",+ "--target",+ &triple,+ ])+ .env(key, &linker)+ .status()+ .map_err(|e| e.to_string())?;+ if !status.success() {+ return Err("static helper build failed; install targets with: \+ rustup target add x86_64-unknown-linux-musl \+ aarch64-unknown-linux-musl"+ .into());+ }+ helpers.push((+ arch.into(),+ target.join(triple).join("release/disktree-scan"),+ ));+ }+ let output = target.join("portable/disktree");+ std::fs::create_dir_all(output.parent().unwrap())+ .map_err(|e| e.to_string())?;+ std::fs::copy(target.join("release/disktree"), &output)+ .map_err(|e| e.to_string())?;+ // strip rewrites ELF and discards overlays, so it must precede embedding.+ let status = Command::new("strip")+ .arg(&output)+ .status()+ .map_err(|e| e.to_string())?;+ if !status.success() {+ return Err("strip failed".into());+ }+ disktree_core::payload::append(&output, &helpers)+ .map_err(|e| e.to_string())?;+ println!("Portable app: {}", output.display());+ Ok(())+}