Files
disktree/xtask/src/main.rs
T
Sebastian Sieber cbdfe1c332 macOS support: native Trash, APFS-aware scans, a signed app bundle
disktree built and drew on macOS already, through GPUI's Metal backend,
but the Linux plumbing underneath did not carry over. This makes it work
well there, without unsafe code, and tightens removal safety for every
platform on the way.

Trash and removal
- On macOS always the system Trash, through NSFileManager (the trash
  crate): the same move as Finder's, into the item's own disk's Trash.
  gio/trash-put/XDG would put files in ~/.local/share/Trash, which Finder
  never shows.
- Refuse a directory holding the home directory (/Users is on the same
  volume as / on macOS) or a system tree (/opt holds /opt/homebrew); add
  /System, /Library, /private, /opt/homebrew, /cores, /Network.
- Refuse a directory with a mount inside it; on macOS the mount list comes
  from /sbin/mount, read on a background thread.
- Permanent deletion walks the tree itself and stops at a mount boundary,
  like rm -rf --one-file-system (the walker is from #10).
- Guards see through /System/Volumes/Data spellings and, on macOS, case.

Scanning
- Skip /System/Volumes/Data when scanning /: it is /Users, /Applications
  and the rest again under firmlinks, so / was counted twice.
- Whole disk (g, --disk) works: the disk root and device come from statfs.
- Never list cloud-only (dataless) iCloud/File Provider folders, which
  would download them.
- Keep a file's identity only when it has more than one name.

App
- Explain unreadable items when Full Disk Access is missing, with a button
  to the privacy settings.
- A menu bar: Open Folder… (⌘O), Show in Finder (o, ⌘⇧R), Rescan (⌘R),
  Hide, Quit; closing the window quits; other ⌘ chords are not read as
  plain letters; help shows ⌘.
- Follow the system light/dark appearance when no Omarchy theme exists.
- Worth a look knows Xcode DerivedData, DeviceSupport and ~/Library/Logs.
- git: skipped without the developer tools (its stub opens a dialog), and
  never runs a checkout's programs: fsmonitor, hooks and pager off, and no
  status for a checkout that defines its own filter drivers.

Packaging
- cargo xtask bundle builds disktree.app and a zip: Info.plist (bundle id
  io.github.tobi.disktree, macOS 11+), an icon drawn from an SVG on the
  macOS grid, ad-hoc or Developer ID signing, and --notarize.
- make install on macOS puts the app in ~/Applications and links
  ~/.local/bin/disktree to it.
- CI lints, tests and bundles on macOS; the release adds an arm64 macOS
  zip, signed and notarized when the repository has the Apple secrets.
2026-09-25 17:29:55 +08:00

97 lines
2.8 KiB
Rust

//! Check and packaging entry points for disktree.
//!
//! Each gate is reachable on its own (`cargo xtask fmt`) and through the
//! aggregate CI runs (`cargo xtask lint`), mirroring how omatrack exposes every
//! linter both as a build target and as a labelled test. `lint` never fixes
//! anything: it reports the diff and fails, so a red local run is the same
//! signal CI gives.
mod bundle;
use std::process::{Command, ExitCode, Stdio};
const USAGE: &str = "\
usage: cargo xtask <task>
tasks:
lint fmt --check, then clippy over the workspace with -D warnings
fmt rustfmt --check over the workspace
fmt-fix rustfmt in place
clippy clippy --workspace --all-targets -- -D warnings
test cargo test --workspace
ci lint, then test
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, or
NOTARY_KEY, NOTARY_KEY_ID and NOTARY_ISSUER
";
fn main() -> ExitCode {
let args: Vec<String> = std::env::args().skip(1).collect();
let task = args.first().map_or("lint", String::as_str);
let outcome = match task {
"lint" => fmt(false).and_then(|()| clippy()),
"fmt" => fmt(false),
"fmt-fix" => fmt(true),
"clippy" => clippy(),
"test" => test(),
"ci" => fmt(false).and_then(|()| clippy()).and_then(|()| test()),
"bundle" => bundle::bundle(&args[1..]),
"help" | "-h" | "--help" => {
println!("{USAGE}");
return ExitCode::SUCCESS;
}
other => {
eprintln!("unknown task: {other}\n\n{USAGE}");
return ExitCode::FAILURE;
}
};
match outcome {
Ok(()) => ExitCode::SUCCESS,
Err(message) => {
eprintln!("xtask {task}: {message}");
ExitCode::FAILURE
}
}
}
fn fmt(fix: bool) -> Result<(), String> {
let mut args = vec!["fmt", "--all"];
args.push(if fix { "" } else { "--check" });
let args: Vec<&str> = args.into_iter().filter(|a| !a.is_empty()).collect();
run(&args)
}
fn clippy() -> Result<(), String> {
run(&[
"clippy",
"--workspace",
"--all-targets",
"--all-features",
"--",
"-D",
"warnings",
])
}
fn test() -> Result<(), String> {
run(&["test", "--workspace"])
}
fn run(args: &[&str]) -> Result<(), String> {
let cargo = option_env!("CARGO").unwrap_or("cargo");
let display = format!("{cargo} {}", args.join(" "));
let status = Command::new(cargo)
.args(args)
.stdin(Stdio::null())
.status()
.map_err(|err| format!("could not start `{display}`: {err}"))?;
if status.success() {
Ok(())
} else {
Err(format!("`{display}` failed"))
}
}