From 57f3ef8db33dfadb61df8c649e292fd72fa4549f Mon Sep 17 00:00:00 2001 From: shinyobjectz Date: Tue, 17 Nov 2026 10:17:35 -0800 Subject: [PATCH] Windows: canonicalize goes through dunce and the home folder through user_home (all but five crates) canonicalize() through std gives \\?\C:\... on Windows: a path Git for Windows can neither read nor lock, Rolldown can't resolve, and which shares no root with the C:\... git and everything else print. It broke a new workspace's git config (fixed in apps/workspace earlier today). Here the calls in the apps (CapCut, check, direction, engines, fingerprint, game, interchange, judge, solid, sound, targets, tools), the bundler, the CLI, the modules loader, the native shim's realpath, the page's motion, io (assets, gen, home, shell), runtime/bundle/lib, js, track and world, the systems (fingerprint-use, footage, index, ml, page-net), the bridge bench's examples and the sdk/ui test tools use dunce::canonicalize, which gives C:\... wherever a path can be said so and is std's own call on the Mac and Linux. Reads of the home folder took HOME alone, which Windows doesn't set for an app opened from the Start menu or Explorer, so the taste file, the settings file, the inbox, the npm store, the caches (sounds, splats, goo, ingest, speech, Core ML, the portable perceive models), the node shim's os.homedir() and CapCut's drafts were looked for under whatever folder raea ran in. raea_io_home::user_home() reads HOME, then USERPROFILE (Git for Windows' order; an empty one counts as unset), and models(), caches(), logs(), env_path() and offline() use it, as do the places that had their own fallback. The caches that had their own copy of "this variable, else this folder under home" (splats, goo, ingest, the npm store, Core ML's models) now call raea_io_home::env_path and models(), and raea_io_home::real canonicalizes a path or keeps it as given, so tools/dupes.max comes down to 289 exact and 58 near. tools/skills.sh reads a variable from env_path("RAEA_...", ".raea/...") as it did from env::var, so files.md keeps RAEA_NPM_HOME on ~/.raea/npm (every generated reference is unchanged). Five crates hold other sessions' uncommitted edits (engine/page/stage, engine/render, runtime/bundle, runtime/export, runtime/live): their few calls, and tools/windows-paths.sh, the check that keeps both at zero, land once those are committed. Checked: cargo check --all-targets of every crate changed, and of sdk/ui/conformance and sdk/ui/parity. On a Windows 11 PC and on macOS the unit tests of raea-io-home (user_home's order and an empty HOME, now in caches_logs_and_the_home_folder_follow_the_platform), raea-app-check, raea-app-workspace, raea-app-registry and raea-core-facts pass (5, 27, 10, 7, 17). --- Cargo.lock | 47 +++++++++++++++++++++++++++ apps/capcut/Cargo.toml | 1 + apps/capcut/src/lib.rs | 2 +- apps/capcut/src/plan.rs | 2 +- apps/capcut/src/tests.rs | 2 +- apps/check/Cargo.toml | 2 ++ apps/check/src/hook.rs | 2 +- apps/check/src/text.rs | 2 +- apps/direction/Cargo.toml | 2 ++ apps/direction/src/check.rs | 8 ++--- apps/direction/src/findings.rs | 2 +- apps/direction/src/ts.rs | 2 +- apps/engines/src/blender_ts.rs | 2 +- apps/engines/src/godot.rs | 2 +- apps/engines/src/godot_run.rs | 4 +-- apps/engines/src/round.rs | 4 +-- apps/engines/src/shot.rs | 2 +- apps/fingerprint/Cargo.toml | 2 ++ apps/fingerprint/src/notes.rs | 4 +-- apps/fingerprint/src/postmortem.rs | 4 +-- apps/fingerprint/src/things.rs | 4 +-- apps/game/Cargo.toml | 1 + apps/game/src/export.rs | 4 +-- apps/game/src/gather.rs | 4 +-- apps/game/src/player.rs | 6 ++-- apps/interchange/Cargo.toml | 1 + apps/interchange/src/export.rs | 2 +- apps/judge/Cargo.toml | 1 + apps/judge/src/agent.rs | 2 +- apps/notes/Cargo.toml | 1 + apps/notes/src/take.rs | 2 +- apps/solid/Cargo.toml | 1 + apps/solid/src/lib.rs | 2 +- apps/sound/Cargo.toml | 1 + apps/sound/src/lib.rs | 2 +- apps/targets/Cargo.toml | 1 + apps/targets/src/macapp.rs | 2 +- apps/targets/src/native.rs | 2 +- apps/targets/src/verbs.rs | 2 +- apps/targets/src/web.rs | 2 +- apps/tools/Cargo.toml | 1 + apps/tools/src/agent_mcp.rs | 2 +- apps/tools/src/sound/library.rs | 2 +- apps/tools/src/splat.rs | 2 +- apps/workspace/Cargo.toml | 1 + apps/workspace/registry/Cargo.toml | 1 + apps/workspace/registry/src/lint.rs | 2 +- apps/workspace/src/workspace.rs | 2 +- bench/bevy-parity/Cargo.toml | 3 ++ bench/bevy-parity/build.rs | 2 +- bench/bridge/Cargo.toml | 1 + bench/bridge/examples/canvas_box.rs | 2 +- bench/bridge/examples/entity_ref.rs | 2 +- bench/bridge/examples/host_query.rs | 2 +- bench/bridge/examples/plain_page.rs | 2 +- bench/bridge/examples/shared_state.rs | 2 +- bench/bridge/examples/texture_slot.rs | 2 +- engine/bundle/Cargo.toml | 1 + engine/bundle/src/edit.rs | 6 ++-- engine/bundle/src/lib.rs | 2 +- engine/cli/Cargo.toml | 1 + engine/cli/src/cli.rs | 8 ++--- engine/cli/src/guide.rs | 2 +- engine/cli/src/refused.rs | 2 +- engine/cli/src/spec.rs | 2 +- engine/modules/Cargo.toml | 1 + engine/modules/src/lib.rs | 4 +-- engine/modules/tests/loader.rs | 6 ++-- engine/native/Cargo.toml | 2 ++ engine/native/src/node.rs | 4 +-- engine/page/Cargo.toml | 1 + engine/page/src/motion.rs | 2 +- io/assets/Cargo.toml | 1 + io/assets/src/lib.rs | 6 ++-- io/assets/src/splat.rs | 3 +- io/capcut/Cargo.toml | 1 + io/capcut/src/store.rs | 2 +- io/gen-core/src/tripo.rs | 2 +- io/gen/Cargo.toml | 1 + io/gen/src/cli.rs | 2 +- io/gen/src/run.rs | 2 +- io/home/Cargo.toml | 1 + io/home/src/lib.rs | 43 ++++++++++++++++++++---- io/npm/src/store.rs | 2 +- io/shell/Cargo.toml | 1 + io/shell/src/archive.rs | 2 +- io/shell/src/fs/calls.rs | 2 +- io/shell/src/fs/mod.rs | 4 +-- io/trace/src/crash.rs | 2 +- runtime/bundle/lib/Cargo.toml | 1 + runtime/bundle/lib/src/app.rs | 4 +-- runtime/bundle/lib/src/lib.rs | 2 +- runtime/encode/src/progress.rs | 2 +- runtime/js/Cargo.toml | 1 + runtime/js/src/html_page.rs | 4 +-- runtime/jsengine/Cargo.toml | 1 + runtime/jsengine/src/upkeep.rs | 2 +- runtime/track/Cargo.toml | 1 + runtime/track/src/lib.rs | 2 +- runtime/world/Cargo.toml | 1 + runtime/world/src/lib.rs | 2 +- runtime/world/src/renders/tests.rs | 2 +- sdk/ui/conformance/Cargo.lock | 7 ++++ sdk/ui/conformance/Cargo.toml | 1 + sdk/ui/conformance/src/run.rs | 2 +- sdk/ui/parity/Cargo.lock | 7 ++++ sdk/ui/parity/Cargo.toml | 1 + sdk/ui/parity/src/app.rs | 2 +- sdk/ui/parity/src/main.rs | 2 +- sdk/ui/parity/src/wpt.rs | 4 +-- systems/bake/Cargo.toml | 1 + systems/bake/src/goo.rs | 3 +- systems/columns/Cargo.toml | 1 + systems/columns/src/lib.rs | 2 +- systems/columns/src/tests.rs | 2 +- systems/fingerprint-use/Cargo.toml | 1 + systems/fingerprint-use/src/grow.rs | 2 +- systems/fingerprint/Cargo.toml | 3 ++ systems/fingerprint/src/tests.rs | 2 +- systems/footage/Cargo.toml | 2 ++ systems/footage/src/ingest/mod.rs | 2 +- systems/footage/src/store.rs | 4 +-- systems/index/Cargo.toml | 1 + systems/index/src/apple.rs | 4 +-- systems/index/src/cli.rs | 4 +-- systems/index/src/lib.rs | 2 +- systems/index/src/serve.rs | 2 +- systems/index/src/walk.rs | 2 +- systems/kimodo/Cargo.toml | 3 ++ systems/kimodo/src/tests.rs | 2 +- systems/ml/Cargo.toml | 1 + systems/ml/src/feed.rs | 2 +- systems/ml/src/lib.rs | 2 +- systems/page-net/Cargo.toml | 1 + systems/page-net/src/lib.rs | 4 +-- systems/perceive/src/face_portable.rs | 2 +- systems/perceive/src/ocr_portable.rs | 2 +- systems/perceive/src/portable.rs | 2 +- systems/song/src/onnx.rs | 2 +- systems/speech/Cargo.toml | 1 + systems/speech/src/speech.rs | 2 +- systems/vision/Cargo.toml | 1 + systems/vision/src/coreml.rs | 8 ++--- tools/dupes.max | 4 +-- tools/skills.sh | 3 +- 145 files changed, 283 insertions(+), 143 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dd9b0768..b6526ffb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13745,6 +13745,7 @@ checksum = "019b4b213425016d7d84a153c4c73afb0946fbb4840e4eece7ba8848b9d6da22" name = "raea-app-capcut" version = "0.1.0" dependencies = [ + "dunce", "image", "raea-core-scene", "raea-io-alpha", @@ -13759,11 +13760,13 @@ dependencies = [ name = "raea-app-check" version = "0.1.0" dependencies = [ + "dunce", "raea-app-check-flash", "raea-app-check-inbox", "raea-core-brief", "raea-core-facts", "raea-io-ffmpeg", + "raea-io-home", "raea-io-trace", "raea-sys-measure", "serde_json", @@ -13794,11 +13797,13 @@ dependencies = [ name = "raea-app-direction" version = "0.1.0" dependencies = [ + "dunce", "raea-app-check", "raea-app-notes", "raea-app-registry", "raea-core-brief", "raea-core-facts", + "raea-io-home", "raea-io-trace", "raea-runtime-bundle", "raea-runtime-react", @@ -13826,8 +13831,10 @@ name = "raea-app-fingerprint" version = "0.1.0" dependencies = [ "anyhow", + "dunce", "fastrand", "raea-app-check", + "raea-io-home", "raea-sys-columns", "raea-sys-fingerprint", "raea-sys-fingerprint-things", @@ -13841,6 +13848,7 @@ name = "raea-app-game" version = "0.1.0" dependencies = [ "base64 0.22.1", + "dunce", "raea-gpu-device", "raea-io-home", "raea-io-media", @@ -13859,6 +13867,7 @@ dependencies = [ name = "raea-app-interchange" version = "0.1.0" dependencies = [ + "dunce", "raea-core-scene", "raea-core-shape", "raea-runtime-bundle", @@ -13872,6 +13881,7 @@ name = "raea-app-judge" version = "0.1.0" dependencies = [ "base64 0.22.1", + "dunce", "image", "raea-core-facts", "raea-io-home", @@ -13899,6 +13909,7 @@ name = "raea-app-notes" version = "0.1.0" dependencies = [ "raea-core-facts", + "raea-io-home", "raea-io-trace", "serde", "serde_json", @@ -13930,6 +13941,7 @@ dependencies = [ "dunce", "oxc", "raea-core-facts", + "raea-io-home", "serde_json", ] @@ -13937,6 +13949,7 @@ dependencies = [ name = "raea-app-solid" version = "0.1.0" dependencies = [ + "dunce", "raea-app-judge", "raea-core-facts", "raea-core-meshcheck", @@ -13950,6 +13963,7 @@ dependencies = [ name = "raea-app-sound" version = "0.1.0" dependencies = [ + "dunce", "raea-io-media", "raea-runtime-bundle", "raea-runtime-export", @@ -13961,6 +13975,7 @@ name = "raea-app-targets" version = "0.1.0" dependencies = [ "base64 0.22.1", + "dunce", "raea-io-home", "raea-runtime-bundle", "serde_json", @@ -13970,6 +13985,7 @@ dependencies = [ name = "raea-app-tools" version = "0.1.0" dependencies = [ + "dunce", "raea-io-assets", "raea-io-gen", "raea-io-home", @@ -13989,6 +14005,7 @@ dependencies = [ "raea-app-registry", "raea-core-brief", "raea-core-facts", + "raea-io-home", "serde_json", ] @@ -14060,6 +14077,7 @@ dependencies = [ "chacha20 0.10.2", "indexmap", "nonmax", + "raea-io-home", "raea-sys-parity", "rand 0.10.3", ] @@ -14143,6 +14161,7 @@ name = "raea-bridge-bench" version = "0.1.0" dependencies = [ "bevy", + "dunce", "image", "raea-core-alloc", "raea-core-wire", @@ -14167,6 +14186,7 @@ name = "raea-bundle" version = "0.1.0" dependencies = [ "anyhow", + "dunce", "lightningcss", "oxc", "raea-io-home", @@ -14202,6 +14222,7 @@ name = "raea-cli" version = "0.1.0" dependencies = [ "bevy", + "dunce", "raea-app-capcut", "raea-app-check", "raea-app-ci", @@ -14460,6 +14481,7 @@ dependencies = [ name = "raea-io-assets" version = "0.1.0" dependencies = [ + "dunce", "image", "raea-io-home", "ruzstd", @@ -14482,6 +14504,7 @@ dependencies = [ name = "raea-io-capcut" version = "0.1.0" dependencies = [ + "raea-io-home", "serde_json", ] @@ -14510,6 +14533,7 @@ dependencies = [ name = "raea-io-gen" version = "0.1.0" dependencies = [ + "dunce", "image", "raea-io-gen-comfy", "raea-io-gen-core", @@ -14549,6 +14573,7 @@ dependencies = [ name = "raea-io-home" version = "0.1.0" dependencies = [ + "dunce", "serde_json", "url", ] @@ -14626,6 +14651,7 @@ dependencies = [ name = "raea-io-shell" version = "0.1.0" dependencies = [ + "dunce", "flate2", "htmd", "raea-core-calls", @@ -14666,6 +14692,7 @@ name = "raea-modules" version = "0.1.0" dependencies = [ "deno_ast", + "dunce", ] [[package]] @@ -14673,10 +14700,12 @@ name = "raea-native" version = "0.1.0" dependencies = [ "base64 0.22.1", + "dunce", "flate2", "getrandom 0.3.4", "libc", "raea-core-calls", + "raea-io-home", "raea-io-shell", "raea-modules", "raea-runtime-jsengine", @@ -14701,6 +14730,7 @@ dependencies = [ "bevy", "blitz-dom", "blitz-html", + "dunce", "image", "parley", "raea-core-wire", @@ -15046,6 +15076,7 @@ dependencies = [ name = "raea-runtime-bundle-lib" version = "0.1.0" dependencies = [ + "dunce", "libloading", "raea-io-home", "serde_json", @@ -15234,6 +15265,7 @@ dependencies = [ "base64 0.22.1", "bevy", "cpal 0.15.3", + "dunce", "raea-bevy-world", "raea-core-wire", "raea-io-home", @@ -15252,6 +15284,7 @@ name = "raea-runtime-jsengine" version = "0.1.0" dependencies = [ "objc2 0.6.5", + "raea-io-home", "rquickjs", ] @@ -15466,6 +15499,7 @@ dependencies = [ name = "raea-runtime-track" version = "0.1.0" dependencies = [ + "dunce", "raea-io-assets", "raea-native", "raea-runtime-bundle", @@ -15519,6 +15553,7 @@ name = "raea-runtime-world" version = "0.1.0" dependencies = [ "bevy", + "dunce", "image", "raea-core-facts", "raea-core-scene", @@ -15583,6 +15618,7 @@ name = "raea-sys-bake" version = "0.1.0" dependencies = [ "image", + "raea-io-home", "rapier3d", "serde_json", "sha2 0.10.9", @@ -15621,6 +15657,7 @@ dependencies = [ "half", "image", "ort", + "raea-io-home", "raea-io-media", "raea-sys-ml", "rustfft", @@ -15694,6 +15731,7 @@ name = "raea-sys-fingerprint" version = "0.1.0" dependencies = [ "anyhow", + "raea-io-home", "raea-sys-columns", "serde", "serde_json", @@ -15717,6 +15755,7 @@ name = "raea-sys-fingerprint-use" version = "0.1.0" dependencies = [ "anyhow", + "dunce", "fastrand", "image", "raea-sys-columns", @@ -15769,7 +15808,9 @@ dependencies = [ name = "raea-sys-footage" version = "0.1.0" dependencies = [ + "dunce", "image", + "raea-io-home", "raea-io-media", "raea-sys-layout", "raea-sys-song", @@ -15854,6 +15895,7 @@ version = "0.1.0" dependencies = [ "anyhow", "block2 0.6.2", + "dunce", "half", "objc2 0.6.5", "objc2-app-kit 0.3.2", @@ -15896,6 +15938,7 @@ version = "0.1.0" dependencies = [ "anyhow", "mlx-rs", + "raea-io-home", "raea-sys-ml", "raea-sys-mlx", "serde_json", @@ -16014,6 +16057,7 @@ name = "raea-sys-ml" version = "0.1.0" dependencies = [ "anyhow", + "dunce", "half", "ort", "raea-io-home", @@ -16060,6 +16104,7 @@ dependencies = [ "bevy", "blitz-dom", "blitz-traits", + "dunce", "percent-encoding", "raea-io-net", "raea-sys-image", @@ -16210,6 +16255,7 @@ version = "0.1.0" dependencies = [ "anyhow", "ort", + "raea-io-home", "raea-sys-ml", "serde_json", "tokenizers", @@ -16302,6 +16348,7 @@ dependencies = [ "objc2-core-video", "objc2-foundation 0.3.2", "objc2-vision", + "raea-io-home", "raea-io-media", "raea-sys-layout", "serde", diff --git a/apps/capcut/Cargo.toml b/apps/capcut/Cargo.toml index bd218504..f445cc1a 100644 --- a/apps/capcut/Cargo.toml +++ b/apps/capcut/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "`raea export capcut`: a composition as a CapCut draft ready in its timeline, its footage and sounds as clips of their files and what raea draws as transparent overlays (docs/capcut.feature)" [dependencies] +dunce = "1" raea-runtime-bundle = { path = "../../runtime/bundle" } raea-io-capcut = { path = "../../io/capcut" } raea-io-alpha = { path = "../../io/alpha" } diff --git a/apps/capcut/src/lib.rs b/apps/capcut/src/lib.rs index 59df849b..6874b6b3 100644 --- a/apps/capcut/src/lib.rs +++ b/apps/capcut/src/lib.rs @@ -64,7 +64,7 @@ fn render(args: &[String], env: &[(&str, &str)]) -> R<()> { fn export(args: &[String]) -> R { let tsx = args.first().filter(|a| !a.starts_with('-')).ok_or(USAGE)?; - let tsx = PathBuf::from(tsx).canonicalize().map_err(|e| format!("{tsx}: {e}"))?; + let tsx = dunce::canonicalize(&PathBuf::from(tsx)).map_err(|e| format!("{tsx}: {e}"))?; let dir = tsx.parent().unwrap().to_path_buf(); let codec = flag(args, "--alpha-codec").map_or(Ok(raea_io_alpha::Codec::default_here()), |c| raea_io_alpha::Codec::parse(&c))?; let (root, in_store) = match flag(args, "-o") { diff --git a/apps/capcut/src/plan.rs b/apps/capcut/src/plan.rs index 99f48757..829e7e1d 100644 --- a/apps/capcut/src/plan.rs +++ b/apps/capcut/src/plan.rs @@ -178,5 +178,5 @@ pub fn lay(kind: Kind, name: &str, clips: Vec) -> Vec { /// media/, then the project's media/ and assets/; else absolute; else relative to the composition's folder. pub fn resolve(dir: &Path, src: &str) -> PathBuf { let p = raea_core_scene::media_path(dir, src); - p.canonicalize().unwrap_or(p) + dunce::canonicalize(&p).unwrap_or(p) } diff --git a/apps/capcut/src/tests.rs b/apps/capcut/src/tests.rs index dcd95da7..ce5c070f 100644 --- a/apps/capcut/src/tests.rs +++ b/apps/capcut/src/tests.rs @@ -77,7 +77,7 @@ fn a_static_file_is_found_in_the_edits_media_folder() { let dir = std::env::temp_dir().join(format!("raea-capcut-resolve-{}", std::process::id())); std::fs::create_dir_all(dir.join("media")).unwrap(); std::fs::write(dir.join("media/a.mp4"), "").unwrap(); - let want = dir.join("media/a.mp4").canonicalize().unwrap(); + let want = dunce::canonicalize(&dir.join("media/a.mp4")).unwrap(); assert_eq!(resolve(&dir, "/media/a.mp4"), want); assert_eq!(resolve(&dir, "media/a.mp4"), want); assert_eq!(resolve(&dir, want.to_str().unwrap()), want); diff --git a/apps/check/Cargo.toml b/apps/check/Cargo.toml index a8cca0b5..ec8ca01e 100644 --- a/apps/check/Cargo.toml +++ b/apps/check/Cargo.toml @@ -7,10 +7,12 @@ publish = false description = "`raea check`: the floor's measurable lines on an export, ranked P0-P3" [dependencies] +dunce = "1" # taste.ts rules, as the raea CLI evaluates them (docs/projects.feature PJ0) raea-core-brief = { path = "../../core/brief" } # a transcript's words, read as `raea world` reads them (docs/direction.feature DR1) raea-core-facts = { path = "../../core/facts" } +raea-io-home = { path = "../../io/home" } # a check's record named by when it was (UTC, DR3) raea-io-trace = { path = "../../io/trace" } # ffmpeg's flag for every decoded frame, by its version diff --git a/apps/check/src/hook.rs b/apps/check/src/hook.rs index 8260086d..06ead16f 100644 --- a/apps/check/src/hook.rs +++ b/apps/check/src/hook.rs @@ -154,7 +154,7 @@ pub fn hook(args: &[String]) -> R { } let after_tool = matches!(event, "PostToolUse" | "AfterTool"); if let Some(cmd) = shell_command(&v).filter(|_| !after_tool) { - let home = std::env::var("HOME").unwrap_or_default(); + let home = raea_io_home::user_home().unwrap_or_default().display().to_string(); let files = opened_media(cmd); let key = format!("{}\n{}\n{cmd}", v["session_id"].as_str().unwrap_or(""), v["cwd"].as_str().unwrap_or("")); if !files.is_empty() && app_installed(&home) && !tried_before(&PathBuf::from(&home).join(".raea/hooks/again"), &key) { diff --git a/apps/check/src/text.rs b/apps/check/src/text.rs index a1644120..9b5f2b18 100644 --- a/apps/check/src/text.rs +++ b/apps/check/src/text.rs @@ -22,7 +22,7 @@ pub(crate) struct Run { pub(crate) fn brand_kit(near: &[&str], issues: &mut Vec, passed: &mut Vec) { let mut seen = std::collections::HashSet::new(); for start in near.iter().filter(|p| !p.is_empty()) { - let abs = std::path::Path::new(start).canonicalize().unwrap_or_else(|_| std::path::PathBuf::from(start)); + let abs = dunce::canonicalize(&std::path::Path::new(start)).unwrap_or_else(|_| std::path::PathBuf::from(start)); let mut d = abs.parent(); for _ in 0..5 { let Some(here) = d else { break }; diff --git a/apps/direction/Cargo.toml b/apps/direction/Cargo.toml index d15e816a..e038d3c1 100644 --- a/apps/direction/Cargo.toml +++ b/apps/direction/Cargo.toml @@ -7,6 +7,8 @@ publish = false description = "How raea takes direction (docs/direction.feature): `raea world`, a composition's frame as one world of facts, queried across media" [dependencies] +dunce = "1" +raea-io-home = { path = "../../io/home" } raea-runtime-world = { path = "../../runtime/world" } raea-runtime-bundle = { path = "../../runtime/bundle" } raea-core-facts = { path = "../../core/facts" } diff --git a/apps/direction/src/check.rs b/apps/direction/src/check.rs index 20068cac..6cc40020 100644 --- a/apps/direction/src/check.rs +++ b/apps/direction/src/check.rs @@ -32,7 +32,7 @@ pub struct Host { /// The person's taste folder: RAEA_TASTE, else ~/.raea/taste. pub fn taste_dir() -> Option { - std::env::var_os("RAEA_TASTE").map(PathBuf::from).or_else(|| std::env::var_os("HOME").map(|h| PathBuf::from(h).join(".raea/taste"))) + std::env::var_os("RAEA_TASTE").map(PathBuf::from).or_else(|| raea_io_home::user_home().map(|h| h.join(".raea/taste"))) } /// The .ts files `--taste` names: the file, or every .ts in the folder. A file named under the person's taste folder @@ -133,12 +133,12 @@ fn held(project: &Path, given: Vec, host: &Host) -> (Vec, Vec R)>> { let one = flag(args, "--composition"); - let (dir, file) = if target.is_dir() { (target.to_path_buf(), None) } else { (target.parent().unwrap_or(Path::new(".")).to_path_buf(), Some(target.canonicalize().map_err(|e| format!("{}: {e}", target.display()))?)) }; + let (dir, file) = if target.is_dir() { (target.to_path_buf(), None) } else { (target.parent().unwrap_or(Path::new(".")).to_path_buf(), Some(dunce::canonicalize(&target).map_err(|e| format!("{}: {e}", target.display()))?)) }; let reg = raea_app_registry::scan(&dir, &[]); let mut out: Vec<(PathBuf, Option)> = Vec::new(); for c in ®.compositions { let path = reg.dir.join(&c.file); - let path = path.canonicalize().unwrap_or(path); + let path = dunce::canonicalize(&path).unwrap_or(path); let id = (c.how == raea_app_registry::How::Registered).then(|| c.id.clone()); if file.as_ref().is_none_or(|f| *f == path) && one.as_ref().is_none_or(|o| Some(o) == id.as_ref()) { out.push((path, id)); @@ -325,7 +325,7 @@ pub fn check(args: &[String], host: &Host) -> R<(String, bool)> { let target = raea_app_check::words(args, &TAKES).first().map_or_else(|| PathBuf::from("."), PathBuf::from); // the folder it is in, made whole (`lyric.tsx`'s is the empty path): a rule's check is a path from it let here = if target.is_dir() { target.clone() } else { target.parent().filter(|p| !p.as_os_str().is_empty()).map_or_else(|| PathBuf::from("."), Path::to_path_buf) }; - let here = here.canonicalize().map_err(|e| format!("{}: {e}", here.display()))?; + let here = dunce::canonicalize(&here).map_err(|e| format!("{}: {e}", here.display()))?; let project = record::up(&here, ".raea/project").unwrap_or(here); let (mut rules, unread, notes) = rules(&project, taste_files(args), host); if let Some(only) = flag(args, "--only") { diff --git a/apps/direction/src/findings.rs b/apps/direction/src/findings.rs index 183791ee..31fd0ec2 100644 --- a/apps/direction/src/findings.rs +++ b/apps/direction/src/findings.rs @@ -84,7 +84,7 @@ pub fn cli(args: &[String]) -> Result { } let target = args.get(1).filter(|a| !a.starts_with("--")).map_or_else(|| PathBuf::from("."), PathBuf::from); // made absolute first: a bare name's parent is "", which names no folder - let from = if target.is_file() { target.canonicalize().unwrap_or_else(|_| target.clone()).parent().map_or_else(|| PathBuf::from("."), Path::to_path_buf) } else { target.clone() }; + let from = if target.is_file() { dunce::canonicalize(&target).unwrap_or_else(|_| target.clone()).parent().map_or_else(|| PathBuf::from("."), Path::to_path_buf) } else { target.clone() }; let project = record::up(&from, ".raea/project").ok_or_else(|| format!("raea findings: {} isn't in a raea project (no .raea/project at or above it), so nothing is recorded\n{USAGE}", target.display()))?; let (about, check, since) = (flag(args, "--about"), flag(args, "--check"), flag(args, "--since")); let keep = |f: &Finding| about.as_deref().is_none_or(|n| f.about.iter().any(|a| a.name == n || a.key.as_deref() == Some(n))) && check.as_deref().is_none_or(|c| f.check == c); diff --git a/apps/direction/src/ts.rs b/apps/direction/src/ts.rs index 8a640630..59daae46 100644 --- a/apps/direction/src/ts.rs +++ b/apps/direction/src/ts.rs @@ -69,7 +69,7 @@ pub fn run(files: &[PathBuf], plan: &[Planned], worlds: &[Facts], host: &Host) - std::fs::create_dir_all(&work).map_err(|e| e.to_string())?; let data = work.join("worlds.json"); std::fs::write(&data, serde_json::to_string(worlds).map_err(|e| e.to_string())?).map_err(|e| e.to_string())?; - let imports: String = files.iter().enumerate().map(|(i, f)| format!("import c{i} from {:?};\n", f.canonicalize().unwrap_or_else(|_| f.clone()).display().to_string())).collect(); + let imports: String = files.iter().enumerate().map(|(i, f)| format!("import c{i} from {:?};\n", dunce::canonicalize(&f).unwrap_or_else(|_| f.clone()).display().to_string())).collect(); let checks = (0..files.len()).map(|i| format!("c{i}")).collect::>().join(", "); let planned: Vec = plan.iter().map(|p| json!({"check": p.check, "frames": p.frames, "values": p.values, "level": p.level, "by": p.by})).collect(); let entry = format!( diff --git a/apps/engines/src/blender_ts.rs b/apps/engines/src/blender_ts.rs index 91c46f88..a076bced 100644 --- a/apps/engines/src/blender_ts.rs +++ b/apps/engines/src/blender_ts.rs @@ -47,7 +47,7 @@ pub(crate) fn spec(p: &Path) -> String { } pub fn run(args: &[String]) -> R { - let ts = PathBuf::from(&args[2]).canonicalize().map_err(|e| format!("{}: {e}", args[2]))?; + let ts = dunce::canonicalize(&PathBuf::from(&args[2])).map_err(|e| format!("{}: {e}", args[2]))?; let file = args.get(3).filter(|a| a.ends_with(".blend")).map(PathBuf::from); // ARGS for Blender's sys.argv, without raea's own --timeout SECS let mut rest = args[if file.is_some() { 4 } else { 3 }..].to_vec(); diff --git a/apps/engines/src/godot.rs b/apps/engines/src/godot.rs index 57fd2d85..4b506a3e 100644 --- a/apps/engines/src/godot.rs +++ b/apps/engines/src/godot.rs @@ -197,7 +197,7 @@ pub fn setup(args: &[String]) -> R { /// The project folder: DIR, else the current folder; it needs its project.godot. fn project(arg: Option<&String>) -> R { let dir = arg.map(PathBuf::from).unwrap_or_else(|| PathBuf::from(".")); - let dir = dir.canonicalize().map_err(|e| format!("{}: {e}", dir.display()))?; + let dir = dunce::canonicalize(&dir).map_err(|e| format!("{}: {e}", dir.display()))?; if !dir.join("project.godot").is_file() { return Err(format!("{} has no project.godot", dir.display())); } diff --git a/apps/engines/src/godot_run.rs b/apps/engines/src/godot_run.rs index 15e566ed..66cab93e 100644 --- a/apps/engines/src/godot_run.rs +++ b/apps/engines/src/godot_run.rs @@ -38,7 +38,7 @@ fn opts(args: &[String]) -> R { let script = args.get(2).ok_or("raea godot run SCRIPT.ts [--project DIR] [--window] [--movie FILE [--fps N] [--frames N]] [--scene res://X.tscn] [--size WxH] [--timeout S] [ARGS...]")?; // no script, only flags: the project's --scene plays with nothing of yours added (sdk/godot/src/host/none.ts) let bare = script.starts_with("--"); - let script = if bare { raea_io_home::home().join("sdk/godot/src/host/none.ts") } else { PathBuf::from(script).canonicalize().map_err(|e| format!("{script}: {e}"))? }; + let script = if bare { raea_io_home::home().join("sdk/godot/src/host/none.ts") } else { dunce::canonicalize(&PathBuf::from(script)).map_err(|e| format!("{script}: {e}"))? }; let mut o = Opts { script, project: None, window: false, timeout: 3600.0, movie: None, fps: 30, size: None, frames: None, scene: None, rest: Vec::new() }; let mut it = args[if bare { 2 } else { 3 }..].iter(); while let Some(a) = it.next() { @@ -176,7 +176,7 @@ pub fn run(args: &[String]) -> R { } // the project: --project, the nearest project.godot above the script, else an empty one for this run let found = match &o.project { - Some(p) => Some(p.canonicalize().map_err(|e| format!("{}: {e}", p.display()))?), + Some(p) => Some(dunce::canonicalize(&p).map_err(|e| format!("{}: {e}", p.display()))?), None => nearest_project(o.script.parent().unwrap_or(Path::new("."))), }; let temp = std::env::temp_dir().join(format!("raea-godot-{}", std::process::id())); diff --git a/apps/engines/src/round.rs b/apps/engines/src/round.rs index ba01e028..9da661c9 100644 --- a/apps/engines/src/round.rs +++ b/apps/engines/src/round.rs @@ -69,7 +69,7 @@ pub fn godot_export(args: &[String]) -> R { } pub fn godot_back(args: &[String]) -> R { - let dir = PathBuf::from(args.get(2).ok_or(USAGE)?).canonicalize().map_err(|e| format!("{}: {e}", args[2]))?; + let dir = dunce::canonicalize(&PathBuf::from(args.get(2).ok_or(USAGE)?)).map_err(|e| format!("{}: {e}", args[2]))?; let media = media_of(&dir)?; let now = dir.join(".raea-now.json"); let script = raea_io_home::home().join("sdk/godot/src/host/back.ts"); @@ -129,7 +129,7 @@ pub fn blender_open(args: &[String]) -> R { } pub fn blender_back(args: &[String]) -> R { - let blend = PathBuf::from(args.get(2).filter(|a| a.ends_with(".blend")).ok_or(USAGE)?).canonicalize().map_err(|e| format!("{}: {e}", args[2]))?; + let blend = dunce::canonicalize(&PathBuf::from(args.get(2).filter(|a| a.ends_with(".blend")).ok_or(USAGE)?)).map_err(|e| format!("{}: {e}", args[2]))?; let dir = blend.parent().ok_or("the .blend's folder")?.to_path_buf(); if !dir.join("scene.json").is_file() { return Err(format!("{} has no scene.json beside it: raea blender back reads a .blend raea blender open made", blend.display())); diff --git a/apps/engines/src/shot.rs b/apps/engines/src/shot.rs index da2e77a1..13058bee 100644 --- a/apps/engines/src/shot.rs +++ b/apps/engines/src/shot.rs @@ -113,7 +113,7 @@ pub fn blender(args: &[String]) -> R { let entry = if is_blend { format!("{shoot}Promise.resolve().then(() => shoot({opts})){}\n", blender_ts::CLOSE) } else { - let ts = src.canonicalize().map_err(|e| format!("{}: {e}", s.src))?; + let ts = dunce::canonicalize(&src).map_err(|e| format!("{}: {e}", s.src))?; format!("import * as M from {};\n{shoot}{}.then(() => shoot({opts})){}\n", blender_ts::spec(&ts), blender_ts::DEFAULT, blender_ts::CLOSE) }; let mut rest = s.rest.clone(); diff --git a/apps/fingerprint/Cargo.toml b/apps/fingerprint/Cargo.toml index 15ef1196..50a7e4c4 100644 --- a/apps/fingerprint/Cargo.toml +++ b/apps/fingerprint/Cargo.toml @@ -7,6 +7,8 @@ publish = false description = "`raea fingerprint` (docs/fingerprint.feature FP3a): new, bootstrap, teach, score and report, run by a resident service on localhost that keeps the encoders loaded" [dependencies] +dunce = "1" +raea-io-home = { path = "../../io/home" } # the taxonomy, evidence and heads raea-sys-fingerprint = { path = "../../systems/fingerprint" } # scoring and the sheet, which one judges a piece, diff and profiles diff --git a/apps/fingerprint/src/notes.rs b/apps/fingerprint/src/notes.rs index 5424fe26..52cc2143 100644 --- a/apps/fingerprint/src/notes.rs +++ b/apps/fingerprint/src/notes.rs @@ -23,7 +23,7 @@ pub const INBOX: &str = "fingerprint"; /// A post's video on this machine: the renders library, else the project's own folder fn media(project: &Path, m: &Value) -> Option { let p = m["path"].as_str()?; - let home = PathBuf::from(std::env::var("HOME").unwrap_or_default()); + let home = raea_io_home::user_home().unwrap_or_default(); [home.join(".raea/feed/media").join(p), project.join(p)].into_iter().find(|f| f.is_file()) } @@ -208,7 +208,7 @@ pub(crate) fn readings_here(args: &[String], cwd: &Path) -> i32 { } if has(args, "--tally") { let asked: serde_json::Map = std::fs::read(dir.dir.join("asked.json")).ok().and_then(|b| serde_json::from_slice(&b).ok()).unwrap_or_default(); - let inbox = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(format!(".raea/inbox/{INBOX}.jsonl")); + let inbox = raea_io_home::user_home().unwrap_or_default().join(format!(".raea/inbox/{INBOX}.jsonl")); for line in std::fs::read_to_string(inbox).unwrap_or_default().lines() { let Ok(v) = serde_json::from_str::(line) else { continue }; let Some(batch) = v["item"].as_str().and_then(|i| asked.get(i)).and_then(Value::as_array) else { continue }; diff --git a/apps/fingerprint/src/postmortem.rs b/apps/fingerprint/src/postmortem.rs index 9e16d0ba..3d3f2c84 100644 --- a/apps/fingerprint/src/postmortem.rs +++ b/apps/fingerprint/src/postmortem.rs @@ -10,7 +10,7 @@ use raea_sys_fingerprint::evidence::{Row, features}; use raea_sys_fingerprint::retrain; use raea_sys_fingerprint_use::postmortem::{self as pm, MOST}; use raea_sys_fingerprint_use::score::{Scored, score}; -use std::path::{Path, PathBuf}; +use std::path::Path; pub(crate) fn run(enc: &mut Encoders, args: &[String], cwd: &Path, eval: Eval) -> Result<(String, i32)> { let project = crate::pick::piece_in(args, cwd).parent().map(Path::to_path_buf).unwrap_or_else(|| cwd.to_path_buf()); @@ -18,7 +18,7 @@ pub(crate) fn run(enc: &mut Encoders, args: &[String], cwd: &Path, eval: Eval) - let (dir, fp, w) = crate::verbs::open(enc, args, eval, Some(&crate::pick::piece_in(args, cwd)))?; let before = dir.trained()?.map(|t| t.0).ok_or_else(|| anyhow!("{} has no trained heads yet: `raea fingerprint bootstrap` or teach it first", fp.name))?; if has(args, "--tally") { - let inbox = std::fs::read_to_string(PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(format!(".raea/inbox/{}.jsonl", pm::INBOX))).unwrap_or_default(); + let inbox = std::fs::read_to_string(raea_io_home::user_home().unwrap_or_default().join(format!(".raea/inbox/{}.jsonl", pm::INBOX))).unwrap_or_default(); let answers = pm::answered(&dir.dir, &inbox); let mut l = dir.ledger()?; // every tally adds every answer again, so tallying twice is safe diff --git a/apps/fingerprint/src/things.rs b/apps/fingerprint/src/things.rs index f6acb0fd..58e7b15c 100644 --- a/apps/fingerprint/src/things.rs +++ b/apps/fingerprint/src/things.rs @@ -12,10 +12,10 @@ use std::path::{Path, PathBuf}; pub(crate) fn run(enc: &mut Encoders, args: &[String], cwd: &Path) -> Result<(String, i32)> { let file = cwd.join(args.first().filter(|a| !a.starts_with("--")).ok_or_else(|| anyhow::anyhow!("things FILE"))?); let project = flag(args, "--project").map_or_else(|| cwd.to_path_buf(), |p| cwd.join(p)); - let me = file.canonicalize().ok(); + let me = dunce::canonicalize(&file).ok(); let marks: Vec = crate::notes::pinned(&project) .into_iter() - .filter(|r| r.media.canonicalize().ok() == me) + .filter(|r| dunce::canonicalize(&r.media).ok() == me) .filter_map(|r| Some(Mark { name: r.text.chars().take(40).collect(), t: r.t, a: (r.t - 1.0).max(0.0), b: r.to.unwrap_or(r.t + 1.0), region: r.region? })) .collect(); let t = things(enc, &file, &marks)?; diff --git a/apps/game/Cargo.toml b/apps/game/Cargo.toml index afd26d8f..8e2d4ad8 100644 --- a/apps/game/Cargo.toml +++ b/apps/game/Cargo.toml @@ -19,6 +19,7 @@ player = [] surfaces = ["raea-runtime-react/surfaces"] [dependencies] +dunce = "1" raea-runtime-react = { path = "../../runtime/react", default-features = false } raea-runtime-page = { path = "../../runtime/page" } raea-runtime-export = { path = "../../runtime/export" } diff --git a/apps/game/src/export.rs b/apps/game/src/export.rs index 647266a8..6eb640df 100644 --- a/apps/game/src/export.rs +++ b/apps/game/src/export.rs @@ -14,7 +14,7 @@ pub(crate) fn keep_dsym(player: &Path) { let Ok(o) = std::process::Command::new("dwarfdump").arg("--uuid").arg(&dsym).output() else { return }; let text = String::from_utf8_lossy(&o.stdout); let Some(uuid) = text.split_whitespace().nth(1).filter(|u| u.len() == 36) else { return }; - let Some(home) = std::env::var_os("HOME") else { return }; + let Some(home) = raea_io_home::user_home() else { return }; let to = Path::new(&home).join("Library/Caches/raea/dsym").join(uuid).join("raea-game.dSYM"); if to.exists() { return; @@ -34,7 +34,7 @@ pub const USAGE: &str = "raea export-game EDIT.tsx -o OUT [--target mac-app|mac- pub fn export(args: &[String]) -> R { let usage = USAGE; let tsx = PathBuf::from(args.get(1).filter(|a| !a.starts_with("--")).ok_or(usage)?); - let tsx = tsx.canonicalize().map_err(|e| format!("{}: {e}", tsx.display()))?; + let tsx = dunce::canonicalize(&tsx).map_err(|e| format!("{}: {e}", tsx.display()))?; let dir = tsx.parent().unwrap().to_path_buf(); let out = PathBuf::from(flag(args, "-o").ok_or(usage)?); let target = flag(args, "--target").unwrap_or_else(|| if out.extension().is_some_and(|x| x == "app") { "mac-app".into() } else { "mac-cli".into() }); diff --git a/apps/game/src/gather.rs b/apps/game/src/gather.rs index 510f4642..c553effc 100644 --- a/apps/game/src/gather.rs +++ b/apps/game/src/gather.rs @@ -85,7 +85,7 @@ pub(crate) fn gather(bundle: &mut String, dir: &Path, game: &Path, got: &mut Gat } } } - let inside = |p: &Path| -> Option { p.canonicalize().ok().and_then(|c| c.strip_prefix(dir.canonicalize().ok()?).ok().map(|r| r.to_string_lossy().to_string())) }; + let inside = |p: &Path| -> Option { dunce::canonicalize(&p).ok().and_then(|c| c.strip_prefix(dunce::canonicalize(&dir).ok()?).ok().map(|r| r.to_string_lossy().to_string())) }; let mut rewrites: Vec<(String, String)> = Vec::new(); for s in &lits { if s.contains("://") || s.starts_with("data:") || s.len() < 2 || s.contains('\u{0}') { @@ -134,7 +134,7 @@ pub(crate) fn gather(bundle: &mut String, dir: &Path, game: &Path, got: &mut Gat } } None => { - let canon = file.canonicalize().unwrap_or(file.clone()); + let canon = dunce::canonicalize(&file).unwrap_or(file.clone()); let h = twox_hash::XxHash3_64::oneshot(canon.to_string_lossy().as_bytes()); let rel = format!("media/_ext/{:08x}-{}", h as u32, file.file_name().unwrap().to_string_lossy()); put(&file, &rel, game, got)?; diff --git a/apps/game/src/player.rs b/apps/game/src/player.rs index bd859775..c6b9fdbd 100644 --- a/apps/game/src/player.rs +++ b/apps/game/src/player.rs @@ -50,11 +50,11 @@ pub(crate) fn find_game(args: &[String]) -> R { return Ok(PathBuf::from(d)); } let exe = std::env::current_exe().map_err(|e| e.to_string())?; - let exe = exe.canonicalize().unwrap_or(exe); + let exe = dunce::canonicalize(&exe).unwrap_or(exe); let here = exe.parent().unwrap_or(Path::new(".")); for c in [here.join("../Resources/game"), here.join("game")] { if c.join(MANIFEST).exists() { - return Ok(c.canonicalize().unwrap_or(c)); + return Ok(dunce::canonicalize(&c).unwrap_or(c)); } } Err(format!("no game beside {} (an exported game's player looks in ../Resources/game or game/; --game DIR names one)", exe.display())) @@ -300,7 +300,7 @@ pub(crate) fn selftest(game: &Game, secs: f64, args: &[String]) -> R { "has_3d": game.has_3d, "snapshots": snapped, "panics": panics, - "env": {"home": std::env::var("HOME").unwrap_or_default(), "raea_vars_given": std::env::vars().filter(|(k, _)| k.starts_with("RAEA_") && k != "RAEA_AUDIO_MUTE" && k != "RAEA_AUDIO_TAP").count()}, + "env": {"home": raea_io_home::user_home().unwrap_or_default().display().to_string(), "raea_vars_given": std::env::vars().filter(|(k, _)| k.starts_with("RAEA_") && k != "RAEA_AUDIO_MUTE" && k != "RAEA_AUDIO_TAP").count()}, }); if let Some(p) = flag(args, "--json") { std::fs::write(&p, serde_json::to_string_pretty(&report).unwrap()).map_err(|e| format!("{p}: {e}"))?; diff --git a/apps/interchange/Cargo.toml b/apps/interchange/Cargo.toml index 9c8a6a2a..15f5e16e 100644 --- a/apps/interchange/Cargo.toml +++ b/apps/interchange/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "A composition's 3D as data another tool builds (`raea scene export`: scene.json, its meshes and models), a Godot project written from it, and what changed in Blender or Godot read back as edits to the TSX (docs/blender.feature BL37-BL39, docs/godot.feature GD12-GD13)" [dependencies] +dunce = "1" # the composition bundled and stepped to its frames' 3D (raea-runtime-export's scene_frames), walked into parts raea-runtime-bundle = { path = "../../runtime/bundle" } raea-runtime-export = { path = "../../runtime/export" } diff --git a/apps/interchange/src/export.rs b/apps/interchange/src/export.rs index c991ac63..475c907c 100644 --- a/apps/interchange/src/export.rs +++ b/apps/interchange/src/export.rs @@ -237,7 +237,7 @@ pub fn scene(all: &[Vec], frames: &[i64], dir: &Path, out: &Path) -> R R<(PathBuf, Value)> { let edit = args.get(2).ok_or(USAGE)?; - let tsx = PathBuf::from(edit).canonicalize().map_err(|e| format!("{edit}: {e}"))?; + let tsx = dunce::canonicalize(&PathBuf::from(edit)).map_err(|e| format!("{edit}: {e}"))?; let dir = tsx.parent().ok_or("the edit's folder")?.to_path_buf(); let out = args.iter().position(|a| a == "-o").and_then(|i| args.get(i + 1)).ok_or(USAGE)?; let out = std::path::absolute(out).map_err(|e| e.to_string())?; diff --git a/apps/judge/Cargo.toml b/apps/judge/Cargo.toml index 4b8e612d..223e3602 100644 --- a/apps/judge/Cargo.toml +++ b/apps/judge/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "raea judge: a review's sheets judged by clef-omni on a frozen rubric, the pass decided in code, calibrated against the person's eye before it gates" [dependencies] +dunce = "1" raea-io-home = { path = "../../io/home" } # what a judge saw, as raea's one Finding (docs/direction.feature DR3) raea-core-facts = { path = "../../core/facts" } diff --git a/apps/judge/src/agent.rs b/apps/judge/src/agent.rs index f532c956..8729af24 100644 --- a/apps/judge/src/agent.rs +++ b/apps/judge/src/agent.rs @@ -84,7 +84,7 @@ pub fn read(v: &Value) -> (Map, Vec, Value) { /// said on stderr as it comes, so a watcher sees it working through a judgement that can take minutes. pub fn ask(by: &str, dir: &Path, brief: &Value, target: Option<&Path>) -> Result { use std::io::BufRead as _; - let dir = dir.canonicalize().map_err(|e| format!("judge: {}: {e}", dir.display()))?; + let dir = dunce::canonicalize(&dir).map_err(|e| format!("judge: {}: {e}", dir.display()))?; let p = prompt(&dir, brief, target); let mut cmd = match by { "kimi" => { diff --git a/apps/notes/Cargo.toml b/apps/notes/Cargo.toml index 6926175f..cee121f8 100644 --- a/apps/notes/Cargo.toml +++ b/apps/notes/Cargo.toml @@ -9,6 +9,7 @@ description = "A person's notes on a project as files the work is held to (docs/ [dependencies] # Note and Ask, the project found by its .raea/project, and the world a note is an entity in raea-core-facts = { path = "../../core/facts" } +raea-io-home = { path = "../../io/home" } # when a run of an ask's check was (UTC), as raea check stamps its record raea-io-trace = { path = "../../io/trace" } # what each ask has been through, kept as JSON (state.rs) diff --git a/apps/notes/src/take.rs b/apps/notes/src/take.rs index f09ab777..438cc6ad 100644 --- a/apps/notes/src/take.rs +++ b/apps/notes/src/take.rs @@ -27,7 +27,7 @@ pub(crate) struct New { fn inbox_dir() -> PathBuf { match std::env::var_os("RAEA_INBOX_DIR") { Some(dir) => dir.into(), - None => Path::new(&std::env::var_os("HOME").unwrap_or_default()).join(".raea/inbox"), + None => raea_io_home::user_home().unwrap_or_default().join(".raea/inbox"), } } diff --git a/apps/solid/Cargo.toml b/apps/solid/Cargo.toml index 39d60af7..e923db93 100644 --- a/apps/solid/Cargo.toml +++ b/apps/solid/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "raea solid info and raea solid view: a solid file run, its parts measured (raea-core-solidinfo), and its review sheets in colour and clay" [dependencies] +dunce = "1" raea-core-solidinfo = { path = "../../core/solidinfo" } # what solid info finds, as raea's one Finding (docs/direction.feature DR3) raea-core-facts = { path = "../../core/facts" } diff --git a/apps/solid/src/lib.rs b/apps/solid/src/lib.rs index 5fc2bdf8..2adfdefa 100644 --- a/apps/solid/src/lib.rs +++ b/apps/solid/src/lib.rs @@ -102,7 +102,7 @@ pub fn verb(args: &[String]) -> Option> { pub fn cli(args: &[String]) -> Result { let (Some(verb @ ("info" | "view" | "export")), Some(file)) = (args.get(1).map(String::as_str), args.get(2)) else { return Err(USAGE.into()) }; - let file = PathBuf::from(file).canonicalize().map_err(|e| format!("{file}: {e}"))?; + let file = dunce::canonicalize(&PathBuf::from(file)).map_err(|e| format!("{file}: {e}"))?; let json_out = args.iter().any(|a| a == "--json"); let set = flag(args, "--set").map(|s| parse_set(&s)).transpose()?.unwrap_or_default(); let expect_path = flag(args, "--expect").map(PathBuf::from).or_else(|| { diff --git a/apps/sound/Cargo.toml b/apps/sound/Cargo.toml index f5aa3f4f..c4177353 100644 --- a/apps/sound/Cargo.toml +++ b/apps/sound/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "A render's sound alone (`raea render EDIT.tsx -o OUT.wav`, no frames drawn) and a video's sound written beside it from the same pass (`--audio OUT.wav`)" [dependencies] +dunce = "1" raea-runtime-export = { path = "../../runtime/export" } raea-runtime-bundle = { path = "../../runtime/bundle" } raea-sys-mix = { path = "../../systems/mix" } diff --git a/apps/sound/src/lib.rs b/apps/sound/src/lib.rs index a952ff94..29423542 100644 --- a/apps/sound/src/lib.rs +++ b/apps/sound/src/lib.rs @@ -42,7 +42,7 @@ pub fn render(args: &[String]) -> Option> { /// mastered by its , written as 48 kHz WAV, with what it measures. fn sound(args: &[String], out: &Path) -> R { let edit = args.get(1).filter(|a| !a.starts_with('-')).ok_or("raea render EDIT.tsx -o OUT.wav")?; - let tsx = PathBuf::from(edit).canonicalize().map_err(|e| format!("{edit}: {e}"))?; + let tsx = dunce::canonicalize(&PathBuf::from(edit)).map_err(|e| format!("{edit}: {e}"))?; let dir = tsx.parent().ok_or("the edit has no folder")?.to_path_buf(); let js = std::env::temp_dir().join(format!("raea-sound-{}.js", std::process::id())); raea_runtime_bundle::bundle_composition(&tsx, &js, &raea_runtime_bundle::comp_opts(args)?, None)?; diff --git a/apps/targets/Cargo.toml b/apps/targets/Cargo.toml index 37a7efcb..e36d3c68 100644 --- a/apps/targets/Cargo.toml +++ b/apps/targets/Cargo.toml @@ -6,6 +6,7 @@ license = "FSL-1.1-ALv2" description = "An app's target, web (Blitz on Bevy) or native (Rune), read from its file, and raea app run|check|bundle on either (docs/targets.feature)" [dependencies] +dunce = "1" serde_json = "1" # the page host's frames over BRP base64 = "0.22" diff --git a/apps/targets/src/macapp.rs b/apps/targets/src/macapp.rs index 011e58b8..fa3692bc 100644 --- a/apps/targets/src/macapp.rs +++ b/apps/targets/src/macapp.rs @@ -97,7 +97,7 @@ mod tests { #[test] fn the_host_runs_as_the_launchers_child() { // canonical, so the launcher's own `pwd` names Resources as this test does (macOS's temp folder is a link) - let dir = std::env::temp_dir().canonicalize().unwrap().join(format!("raea-macapp-launcher-{}", std::process::id())); + let dir = dunce::canonicalize(&std::env::temp_dir()).unwrap().join(format!("raea-macapp-launcher-{}", std::process::id())); let _ = std::fs::remove_dir_all(&dir); let (macos, res) = (dir.join("T.app/Contents/MacOS"), dir.join("T.app/Contents/Resources")); std::fs::create_dir_all(&macos).unwrap(); diff --git a/apps/targets/src/native.rs b/apps/targets/src/native.rs index 925fe04d..345b40c4 100644 --- a/apps/targets/src/native.rs +++ b/apps/targets/src/native.rs @@ -71,7 +71,7 @@ pub fn host(args: &[String]) -> Result { // the app's folder (relative media and fonts) and the CSS it imported (its @font-face rules), T3d let sheet = script.with_extension("css"); std::fs::write(&sheet, css).map_err(|e| format!("{}: {e}", sheet.display()))?; - let dir = p.canonicalize().ok().map(raea_io_home::plain).and_then(|c| c.parent().map(Path::to_path_buf)).unwrap_or_default(); + let dir = dunce::canonicalize(&p).ok().map(raea_io_home::plain).and_then(|c| c.parent().map(Path::to_path_buf)).unwrap_or_default(); extra.extend(["--base".to_string(), dir.display().to_string(), "--css".to_string(), sheet.display().to_string()]); } else { handed.push(a.clone()); diff --git a/apps/targets/src/verbs.rs b/apps/targets/src/verbs.rs index f624c75b..c47e7c28 100644 --- a/apps/targets/src/verbs.rs +++ b/apps/targets/src/verbs.rs @@ -141,7 +141,7 @@ pub fn find(name: &str, built: &[PathBuf]) -> Result { s.push(std::env::consts::EXE_SUFFIX); PathBuf::from(s) }; - let beside = std::env::current_exe().ok().map(|e| e.canonicalize().unwrap_or(e)).and_then(|e| e.parent().map(|d| d.join(name))); + let beside = std::env::current_exe().ok().map(|e| dunce::canonicalize(&e).unwrap_or(e)).and_then(|e| e.parent().map(|d| d.join(name))); let on_path = std::env::var_os("PATH").map(|p| std::env::split_paths(&p).map(|d| d.join(name)).collect::>()).unwrap_or_default(); beside.into_iter().chain(on_path).chain(built.iter().cloned()).map(exe).find(|p| p.is_file()).ok_or(format!("no {name}: put it beside raea or on PATH (in a checkout, build it)")) } diff --git a/apps/targets/src/web.rs b/apps/targets/src/web.rs index 365c538e..8897e6e1 100644 --- a/apps/targets/src/web.rs +++ b/apps/targets/src/web.rs @@ -22,7 +22,7 @@ pub struct Built { /// `app` bundled into `dir` (made if missing): app.js and app.css (Tailwind's, for the classes the app's folder uses, after /// any CSS the app imports) pub fn build(app: &Path, dir: &Path) -> Result { - let app = raea_io_home::plain(app.canonicalize().map_err(|e| format!("{}: {e}", app.display()))?); + let app = raea_io_home::plain(dunce::canonicalize(&app).map_err(|e| format!("{}: {e}", app.display()))?); std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?; let (js, imported) = raea_runtime_bundle::inproc::app::bundle(&app, &raea_io_home::home(), raea_runtime_bundle::inproc::app::WINDOW)?; let folder = app.parent().unwrap_or(Path::new(".")); diff --git a/apps/tools/Cargo.toml b/apps/tools/Cargo.toml index edce548b..6376c96b 100644 --- a/apps/tools/Cargo.toml +++ b/apps/tools/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "The `raea` verbs that run raea's model tools: sao, tokensynth, setup-audio, sounds, splat, song and gen" [dependencies] +dunce = "1" raea-io-assets = { path = "../../io/assets" } # generation flows: made.app, fal, Replicate, OpenRouter, Modal, ComfyUI (`raea gen`) raea-io-gen = { path = "../../io/gen" } diff --git a/apps/tools/src/agent_mcp.rs b/apps/tools/src/agent_mcp.rs index da771f6a..13bfbc0d 100644 --- a/apps/tools/src/agent_mcp.rs +++ b/apps/tools/src/agent_mcp.rs @@ -14,7 +14,7 @@ type R = Result; /// The person's home folder (HOME, or USERPROFILE on Windows). pub fn user_home() -> R { - std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")).map(PathBuf::from).ok_or_else(|| "no home folder (HOME)".into()) + raea_io_home::user_home().ok_or_else(|| "no home folder (HOME)".into()) } /// The JSON file holding `mcpServers` for agents configured that way (Kimi Code, Gemini CLI, Claude Code's own file). diff --git a/apps/tools/src/sound/library.rs b/apps/tools/src/sound/library.rs index cac20db5..69b24e28 100644 --- a/apps/tools/src/sound/library.rs +++ b/apps/tools/src/sound/library.rs @@ -187,7 +187,7 @@ pub(crate) fn sounds_get(args: &[String]) -> R { let base = PathBuf::from(flag(args, "--dir").unwrap_or_else(|| ".".into())); let out = flag(args, "-o").map(PathBuf::from).unwrap_or_else(|| base.join("media/sounds").join(format!("{pid}-{iid}"))); std::fs::create_dir_all(&out).map_err(|e| format!("{}: {e}", out.display()))?; - let cache = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache/raea-sounds").join(pid).join(iid); + let cache = raea_io_home::user_home().unwrap_or_default().join(".cache/raea-sounds").join(pid).join(iid); let template = pack["url"].as_str().unwrap_or_default(); let mut bytes = 0u64; for (file, name, _) in &chosen { diff --git a/apps/tools/src/splat.rs b/apps/tools/src/splat.rs index d91c8ca5..887b9ef4 100644 --- a/apps/tools/src/splat.rs +++ b/apps/tools/src/splat.rs @@ -71,7 +71,7 @@ pub fn splat(args: &[String]) -> R { fn train(args: &[String]) -> R { let (input, params) = parse(args)?; - let input = input.canonicalize().map_err(|e| format!("{}: {e}", input.display()))?; + let input = dunce::canonicalize(&input).map_err(|e| format!("{}: {e}", input.display()))?; let out = PathBuf::from(flag(args, "-o").or_else(|| flag(args, "--o")).ok_or(format!("-o OUT.ply is required\n{USAGE}"))?); if out.extension().and_then(|e| e.to_str()) != Some("ply") { return Err(format!("-o names a .ply, got {}", out.display())); diff --git a/apps/workspace/Cargo.toml b/apps/workspace/Cargo.toml index db0e2511..bcb95114 100644 --- a/apps/workspace/Cargo.toml +++ b/apps/workspace/Cargo.toml @@ -10,6 +10,7 @@ description = "`raea workspace`, `raea project` and `raea controller`: a workspa dunce = "1" # the controller schema (core/brief controller.rs): a controller file is checked and normalized against it raea-core-brief = { path = "../../core/brief" } +raea-io-home = { path = "../../io/home" } serde_json = "1" # a project's compositions, components and controllers read from their source (docs/projects.feature PJ8) raea-app-registry = { path = "registry" } diff --git a/apps/workspace/registry/Cargo.toml b/apps/workspace/registry/Cargo.toml index 45bc3b37..7045b5b2 100644 --- a/apps/workspace/registry/Cargo.toml +++ b/apps/workspace/registry/Cargo.toml @@ -10,6 +10,7 @@ description = "A raea project's compositions, components and controllers, read f dunce = "1" # the version engine/bundle parses TSX with oxc = { version = "=0.152.0", features = ["ast_visit"] } +raea-io-home = { path = "../../../io/home" } serde_json = "1" # what the scan finds, as raea's one Finding (docs/direction.feature DR3) raea-core-facts = { path = "../../../core/facts" } diff --git a/apps/workspace/registry/src/lint.rs b/apps/workspace/registry/src/lint.rs index 0fd080ee..9099ab15 100644 --- a/apps/workspace/registry/src/lint.rs +++ b/apps/workspace/registry/src/lint.rs @@ -56,7 +56,7 @@ impl Lint { /// A path with the home folder as ~, as a person reads it. fn tilde(p: &Path) -> String { - match std::env::var_os("HOME").map(PathBuf::from) { + match raea_io_home::user_home() { Some(h) if p.starts_with(&h) => format!("~/{}", p.strip_prefix(&h).unwrap_or(p).display()), _ => p.display().to_string(), } diff --git a/apps/workspace/src/workspace.rs b/apps/workspace/src/workspace.rs index 2b9b4a20..7ba7d6ab 100644 --- a/apps/workspace/src/workspace.rs +++ b/apps/workspace/src/workspace.rs @@ -94,7 +94,7 @@ pub fn root() -> PathBuf { let set = config(None, &["--global", "raea.root"]).ok().filter(|s| !s.is_empty()); // HOME, else USERPROFILE: Windows sets no HOME for an app opened from the Start menu, which made the root // Documents/raea under whatever folder raea ran in. git's global config is found the same way. - let home = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE")).map(PathBuf::from).unwrap_or_default(); + let home = raea_io_home::user_home().unwrap_or_default(); match set { Some(s) if s.starts_with("~/") => home.join(&s[2..]), Some(s) => PathBuf::from(s), diff --git a/bench/bevy-parity/Cargo.toml b/bench/bevy-parity/Cargo.toml index 6aa33afb..6f3833b4 100644 --- a/bench/bevy-parity/Cargo.toml +++ b/bench/bevy-parity/Cargo.toml @@ -30,3 +30,6 @@ ignored = ["argh", "accesskit", "rand", "chacha20", "bytemuck", "indexmap", "non [features] default = ["default_font"] default_font = [] + +[build-dependencies] +raea-io-home = { path = "../../io/home" } diff --git a/bench/bevy-parity/build.rs b/bench/bevy-parity/build.rs index 13498f55..36499f4c 100644 --- a/bench/bevy-parity/build.rs +++ b/bench/bevy-parity/build.rs @@ -9,7 +9,7 @@ fn main() { let here = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); let src = std::env::var("BEVY_SRC") .map(PathBuf::from) - .unwrap_or_else(|_| PathBuf::from(std::env::var("HOME").unwrap()).join(".cache/raea-vendor/bevy-0.20.0")); + .unwrap_or_else(|_| raea_io_home::user_home().unwrap().join(".cache/raea-vendor/bevy-0.20.0")); let out = PathBuf::from(std::env::var("OUT_DIR").unwrap()); println!("cargo:rerun-if-changed=examples.list"); println!("cargo:rerun-if-env-changed=BEVY_SRC"); diff --git a/bench/bridge/Cargo.toml b/bench/bridge/Cargo.toml index 97ccd09f..88b10df1 100644 --- a/bench/bridge/Cargo.toml +++ b/bench/bridge/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "The Blitz-Bevy bridge's bench (run.sh): its examples, each a Bevy program that checks one of the bridge's claims (B3 H1-H11)" [dev-dependencies] +dunce = "1" raea-io-home = { path = "../../io/home" } raea-runtime-react = { path = "../../runtime/react" } raea-runtime-page = { path = "../../runtime/page" } diff --git a/bench/bridge/examples/canvas_box.rs b/bench/bridge/examples/canvas_box.rs index ade23aa9..790ae83c 100644 --- a/bench/bridge/examples/canvas_box.rs +++ b/bench/bridge/examples/canvas_box.rs @@ -29,7 +29,7 @@ fn main() { std::process::exit(2); }; let out = args.next(); - let js = PathBuf::from(js).canonicalize().expect("the bundle"); + let js = dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"); let mut app = App::new(); app.add_plugins( DefaultPlugins diff --git a/bench/bridge/examples/entity_ref.rs b/bench/bridge/examples/entity_ref.rs index 5ce2dbbd..486facc0 100644 --- a/bench/bridge/examples/entity_ref.rs +++ b/bench/bridge/examples/entity_ref.rs @@ -21,7 +21,7 @@ fn main() { eprintln!("usage: entity_ref ENTITY.js"); std::process::exit(2); }; - let js = PathBuf::from(js).canonicalize().expect("the bundle"); + let js = dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"); let (w, h) = (320, 240); let mut app = App::new(); app.add_plugins( diff --git a/bench/bridge/examples/host_query.rs b/bench/bridge/examples/host_query.rs index 783627ee..501e0c59 100644 --- a/bench/bridge/examples/host_query.rs +++ b/bench/bridge/examples/host_query.rs @@ -35,7 +35,7 @@ fn main() { eprintln!("usage: host_query HOSTQUERY.js"); std::process::exit(2); }; - let js = PathBuf::from(js).canonicalize().expect("the bundle"); + let js = dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"); let mut app = App::new(); app.add_plugins( DefaultPlugins diff --git a/bench/bridge/examples/plain_page.rs b/bench/bridge/examples/plain_page.rs index cfa5a323..a8cd19d5 100644 --- a/bench/bridge/examples/plain_page.rs +++ b/bench/bridge/examples/plain_page.rs @@ -38,7 +38,7 @@ fn main() { std::process::exit(2); }; let n = |i: usize, d: u32| args.get(i).and_then(|a| a.parse().ok()).unwrap_or(d); - let a = Args { js: PathBuf::from(js).canonicalize().expect("the bundle"), out: out.clone(), size: (n(2, 640), n(3, 360)), frame: n(4, 30) as i64, fps: n(5, 30) as f64, scene_only }; + let a = Args { js: dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"), out: out.clone(), size: (n(2, 640), n(3, 360)), frame: n(4, 30) as i64, fps: n(5, 30) as f64, scene_only }; if window { std::process::exit(in_window(a)); } diff --git a/bench/bridge/examples/shared_state.rs b/bench/bridge/examples/shared_state.rs index ee74d4e4..50b3f7e5 100644 --- a/bench/bridge/examples/shared_state.rs +++ b/bench/bridge/examples/shared_state.rs @@ -33,7 +33,7 @@ fn main() { eprintln!("usage: shared_state SHARED.js"); std::process::exit(2); }; - let js = PathBuf::from(js).canonicalize().expect("the bundle"); + let js = dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"); let mut app = App::new(); app.add_plugins( DefaultPlugins diff --git a/bench/bridge/examples/texture_slot.rs b/bench/bridge/examples/texture_slot.rs index 833a6f68..c240029b 100644 --- a/bench/bridge/examples/texture_slot.rs +++ b/bench/bridge/examples/texture_slot.rs @@ -30,7 +30,7 @@ fn main() { std::process::exit(2); }; let out = args.next(); - let js = PathBuf::from(js).canonicalize().expect("the bundle"); + let js = dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"); let mut app = App::new(); app.add_plugins( DefaultPlugins diff --git a/engine/bundle/Cargo.toml b/engine/bundle/Cargo.toml index 174f19ea..e2e5960a 100644 --- a/engine/bundle/Cargo.toml +++ b/engine/bundle/Cargo.toml @@ -13,6 +13,7 @@ description = "A work folder's TypeScript, TSX and their imports bundled in proc crate-type = ["rlib", "cdylib"] [dependencies] +dunce = "1" serde_json = "1" raea-io-home = { path = "../../io/home" } rolldown = "=1.2.12" diff --git a/engine/bundle/src/edit.rs b/engine/bundle/src/edit.rs index d2b05860..6ed9620b 100644 --- a/engine/bundle/src/edit.rs +++ b/engine/bundle/src/edit.rs @@ -30,7 +30,7 @@ impl EditResolve { /// importer was ever under the work folder, so a live game's own `import "react"` went to the engine's React instead of /// the live runtime its tsconfig paths name, and `raea play` threw "not a function" before the first frame pub fn new(e: Edit) -> Self { - let real = |p: PathBuf| p.canonicalize().map(raea_io_home::plain).unwrap_or(p); + let real = |p: PathBuf| dunce::canonicalize(&p).map(raea_io_home::plain).unwrap_or(p); EditResolve(Edit { dir: real(e.dir), js: real(e.js), work: real(e.work) }) } @@ -40,7 +40,7 @@ impl EditResolve { /// work folder and every live play threw "not a function" (the engine's React, with no `__h`) before its first frame fn from_edit(&self, imp: &str) -> bool { let named = Path::new(imp); - let imp = named.canonicalize().map(raea_io_home::plain).unwrap_or_else(|_| named.to_path_buf()); + let imp = dunce::canonicalize(&named).map(raea_io_home::plain).unwrap_or_else(|_| named.to_path_buf()); imp.starts_with(&self.0.work) && !imp.components().any(|c| c.as_os_str() == "node_modules") } @@ -48,7 +48,7 @@ impl EditResolve { /// not the SDK's copies beside them fn own_source(&self, imp: &str) -> bool { let named = Path::new(imp); - let imp = named.canonicalize().map(raea_io_home::plain).unwrap_or_else(|_| named.to_path_buf()); + let imp = dunce::canonicalize(&named).map(raea_io_home::plain).unwrap_or_else(|_| named.to_path_buf()); self.from_edit(&imp.to_string_lossy()) && ["src", "ext"].iter().any(|d| imp.starts_with(self.0.work.join(d))) } diff --git a/engine/bundle/src/lib.rs b/engine/bundle/src/lib.rs index 84129cdb..1bd13036 100644 --- a/engine/bundle/src/lib.rs +++ b/engine/bundle/src/lib.rs @@ -298,7 +298,7 @@ impl Plugin for Stamp { } let file = Path::new(path); // the resolver names files with symlinks resolved (/var is /private/var on the Mac) - let src = self.src.canonicalize().unwrap_or_else(|_| self.src.clone()); + let src = dunce::canonicalize(&self.src).unwrap_or_else(|_| self.src.clone()); let Some(rel) = stamp::own(file, &src).or_else(|| stamp::own(file, &self.src)) else { return Ok(None) }; let text = std::fs::read_to_string(file)?; let Some(stamped) = stamp::stamp(&text, &rel, jsx, &self.helper.to_string_lossy()) else { return Ok(None) }; diff --git a/engine/cli/Cargo.toml b/engine/cli/Cargo.toml index 08cd8189..92a5bb67 100644 --- a/engine/cli/Cargo.toml +++ b/engine/cli/Cargo.toml @@ -20,6 +20,7 @@ path = "src/bin/raea-bevy-sdk.rs" required-features = ["bevy-plugins"] [dependencies] +dunce = "1" raea-runtime-plugins = { path = "../../runtime/plugins" } raea-io-home = { path = "../../io/home" } # the schemas of what an agent writes (brief.ts, script.ts, taste.ts, controllers): raea context reads specs against them diff --git a/engine/cli/src/cli.rs b/engine/cli/src/cli.rs index 3d31ecc8..0ab75b9b 100644 --- a/engine/cli/src/cli.rs +++ b/engine/cli/src/cli.rs @@ -111,7 +111,7 @@ fn notes_run(project: &Path, rules: &[raea_app_notes::check::Rule], args: &[Stri /// worlds, print). The script's default export, if a function, is called; what it prints goes to stdout; a throw /// ends the run with exit 1. pub fn run_script(args: &[String]) -> R { - let ts = PathBuf::from(&args[1]).canonicalize().map_err(|e| format!("{}: {e}", args[1]))?; + let ts = dunce::canonicalize(&PathBuf::from(&args[1])).map_err(|e| format!("{}: {e}", args[1]))?; let out = std::env::temp_dir().join(format!("raea-cli-{}.js", std::process::id())); bundle_script(&ts, &out)?; let secs: f64 = flag(args, "--timeout").and_then(|t| t.parse().ok()).unwrap_or(120.0); @@ -277,7 +277,7 @@ pub fn run(args: &[String]) -> R { .to_string()); } if args.first().map(String::as_str) == Some("bundle") && args.len() >= 2 { - let ts = PathBuf::from(&args[1]).canonicalize().map_err(|e| format!("{}: {e}", args[1]))?; + let ts = dunce::canonicalize(&PathBuf::from(&args[1])).map_err(|e| format!("{}: {e}", args[1]))?; let out = PathBuf::from(flag(args, "-o").ok_or("raea bundle SCRIPT.ts -o OUT.js")?); if args.iter().any(|a| a == "--composition-bundle") { let portable = flag(args, "--portable").map(PathBuf::from); @@ -319,7 +319,7 @@ pub fn run(args: &[String]) -> R { i += 2; continue; } - files.push(PathBuf::from(&args[i]).canonicalize().map_err(|e| format!("{}: {e}", args[i]))?); + files.push(dunce::canonicalize(&PathBuf::from(&args[i])).map_err(|e| format!("{}: {e}", args[i]))?); i += 1; } let extra: Vec<&str> = owned.iter().map(String::as_str).collect(); @@ -331,7 +331,7 @@ pub fn run(args: &[String]) -> R { } // the repo root for fixtures (tests read RAEA_ROOT through host.env) if std::env::var_os("RAEA_ROOT").is_none() { - unsafe { std::env::set_var("RAEA_ROOT", raea_io_home::home().canonicalize().unwrap_or_default()) }; + unsafe { std::env::set_var("RAEA_ROOT", dunce::canonicalize(&raea_io_home::home()).unwrap_or_default()) }; } let out = std::env::temp_dir().join(format!("raea-cli-t{}.js", std::process::id())); bundle_tests(&files, &out, flag(args, "--filter").as_deref(), &extra)?; diff --git a/engine/cli/src/guide.rs b/engine/cli/src/guide.rs index eb54ace7..ea5aa763 100644 --- a/engine/cli/src/guide.rs +++ b/engine/cli/src/guide.rs @@ -91,7 +91,7 @@ fn brief_at(project: &str) -> R { let path = Path::new(project); let brief_path = if path.is_dir() { // from anywhere inside a project: the nearest folder up with a brief.ts or a .raea/project - let dir = path.canonicalize().ok().and_then(|d| d.ancestors().find(|a| a.join("brief.ts").is_file() || a.join(".raea/project").is_file()).map(Path::to_path_buf)); + let dir = dunce::canonicalize(&path).ok().and_then(|d| d.ancestors().find(|a| a.join("brief.ts").is_file() || a.join(".raea/project").is_file()).map(Path::to_path_buf)); dir.unwrap_or_else(|| path.to_path_buf()).join("brief.ts") } else { path.to_path_buf() diff --git a/engine/cli/src/refused.rs b/engine/cli/src/refused.rs index 433b4b7b..2ffe3aeb 100644 --- a/engine/cli/src/refused.rs +++ b/engine/cli/src/refused.rs @@ -14,7 +14,7 @@ fn source_of(args: &[String]) -> Option { } let f = Path::new(args.get(1)?); let ext = f.extension()?.to_str()?; - (matches!(ext, "tsx" | "ts" | "jsx" | "js") && f.is_file()).then(|| f.canonicalize().unwrap_or_else(|_| f.to_path_buf())) + (matches!(ext, "tsx" | "ts" | "jsx" | "js") && f.is_file()).then(|| dunce::canonicalize(&f).unwrap_or_else(|_| f.to_path_buf())) } /// raea's caches' refused/HASH.json (raea_io_home::caches) for that file (RAEA_REFUSED_CACHE moves it; "0" turns it off) diff --git a/engine/cli/src/spec.rs b/engine/cli/src/spec.rs index 1348dfd2..5c89558a 100644 --- a/engine/cli/src/spec.rs +++ b/engine/cli/src/spec.rs @@ -9,7 +9,7 @@ use std::sync::atomic::Ordering; /// The default export of a spec module, as the JSON it evaluates to. pub fn spec_json(ts: &Path) -> R { - let ts = ts.canonicalize().map_err(|e| format!("{}: {e}", ts.display()))?; + let ts = dunce::canonicalize(&ts).map_err(|e| format!("{}: {e}", ts.display()))?; let out = std::env::temp_dir().join(format!("raea-spec-{}.js", std::process::id())); bundle_module(&ts, &out, PRINT_DEFAULT)?; // the JSON is ours to read, not the person's to see: the run prints nothing to the terminal diff --git a/engine/modules/Cargo.toml b/engine/modules/Cargo.toml index a31c2025..c312e80d 100644 --- a/engine/modules/Cargo.toml +++ b/engine/modules/Cargo.toml @@ -8,3 +8,4 @@ description = "The agent's TypeScript and TSX loaded in process: resolved inside [dependencies] deno_ast = { version = "=0.53.3", features = ["transpiling"] } +dunce = "1" diff --git a/engine/modules/src/lib.rs b/engine/modules/src/lib.rs index 0b12255f..dac9c077 100644 --- a/engine/modules/src/lib.rs +++ b/engine/modules/src/lib.rs @@ -126,7 +126,7 @@ fn lexical(p: &Path) -> PathBuf { impl Loader { /// `root` is the space folder; `prebuilt` the libraries the prebuilt bundle serves. pub fn new(root: &Path, prebuilt: Vec) -> Result { - let root = root.canonicalize().map_err(|e| Refusal::new(RefusalKind::Space, format!("the space {} can't be opened: {e}", root.display()), None, None))?; + let root = dunce::canonicalize(&root).map_err(|e| Refusal::new(RefusalKind::Space, format!("the space {} can't be opened: {e}", root.display()), None, None))?; Ok(Loader { root, prebuilt: prebuilt.into_iter().map(|p| (p.specifier.clone(), p)).collect(), cache: HashMap::new(), transpiled: 0 }) } @@ -147,7 +147,7 @@ impl Loader { // the importing file's folder by its real path (macOS's /var is /private/var; spaces link folders in), and the // import joined to it without following links, so a linked media/ inside the space stays inside it let base = if referrer.starts_with("raea:") { self.root.clone() } else { Path::new(from).parent().map(Path::to_path_buf).unwrap_or_else(|| self.root.clone()) }; - let base = base.canonicalize().unwrap_or(base); + let base = dunce::canonicalize(&base).unwrap_or(base); let raw = specifier.strip_prefix("file://").unwrap_or(specifier); let want = lexical(&if raw.starts_with('/') { PathBuf::from(raw) } else { base.join(raw) }); // inside the space, or inside its workspace's shared/ (a file there imports its neighbours relatively) diff --git a/engine/modules/tests/loader.rs b/engine/modules/tests/loader.rs index 4c7cb2b0..a9add3db 100644 --- a/engine/modules/tests/loader.rs +++ b/engine/modules/tests/loader.rs @@ -38,8 +38,8 @@ fn imports_resolve_inside_the_space_and_refuse_outside() { let d = space("resolve", &[("edit.tsx", ""), ("parts/index.ts", "export const x = 1;"), ("a/b.ts", "")]); let l = Loader::new(&d, libs()).unwrap(); let entry = d.join("edit.tsx").display().to_string(); - assert_eq!(l.resolve("./parts", &entry).unwrap(), ModuleId::File(d.canonicalize().unwrap().join("parts/index.ts"))); - let b = d.canonicalize().unwrap().join("a/b.ts").display().to_string(); + assert_eq!(l.resolve("./parts", &entry).unwrap(), ModuleId::File(dunce::canonicalize(&d).unwrap().join("parts/index.ts"))); + let b = dunce::canonicalize(&d).unwrap().join("a/b.ts").display().to_string(); assert!(matches!(l.resolve("../edit", &b).unwrap(), ModuleId::File(_))); let out = l.resolve("../../etc/passwd", &entry).unwrap_err().message; assert!(out.contains("outside the space"), "{out}"); @@ -103,7 +103,7 @@ fn shared_imports_resolve_to_the_workspaces_shared_folder() { ("shared/components/props/index.ts", "export const p = 1;"), ("projects/a/compositions/main.tsx", ""), ]); - let root = w.canonicalize().unwrap(); + let root = dunce::canonicalize(&w).unwrap(); let l = Loader::new(&w.join("projects/a"), libs()).unwrap(); let entry = root.join("projects/a/compositions/main.tsx").display().to_string(); assert_eq!(l.resolve("@shared/components/desk", &entry).unwrap(), ModuleId::File(root.join("shared/components/desk.tsx"))); diff --git a/engine/native/Cargo.toml b/engine/native/Cargo.toml index 7004e2c8..590d77cf 100644 --- a/engine/native/Cargo.toml +++ b/engine/native/Cargo.toml @@ -18,7 +18,9 @@ modules = ["dep:raea-modules"] portable = ["raea-runtime-jsengine/portable"] [dependencies] +dunce = "1" raea-core-calls = { path = "../../core/calls" } +raea-io-home = { path = "../../io/home" } # the shell's natives (fs, net, sql, archive) raea-io-shell = { path = "../../io/shell", default-features = false } serde_json = "1" diff --git a/engine/native/src/node.rs b/engine/native/src/node.rs index 31fd774c..56333d3c 100644 --- a/engine/native/src/node.rs +++ b/engine/native/src/node.rs @@ -324,7 +324,7 @@ pub fn call(op: &str, a: &[Value]) -> Value { } "rename" => std::fs::rename(s(0), s(1)).map(|_| Value::Null).unwrap_or_else(|e| io_err(e, "rename", &s(0))), "copyFile" => std::fs::copy(s(0), s(1)).map(|_| Value::Null).unwrap_or_else(|e| io_err(e, "copyfile", &s(0))), - "realpath" => std::fs::canonicalize(s(0)).map(|p| json!(p.display().to_string())).unwrap_or_else(|e| io_err(e, "realpath", &s(0))), + "realpath" => dunce::canonicalize(s(0)).map(|p| json!(p.display().to_string())).unwrap_or_else(|e| io_err(e, "realpath", &s(0))), "mkdtemp" => { let prefix = s(0); for _ in 0..100 { @@ -359,7 +359,7 @@ pub fn call(op: &str, a: &[Value]) -> Value { } "spawn" => spawn(&s(0), a.get(1), a.get(2).unwrap_or(&Value::Null)), "tmpdir" => json!(std::env::temp_dir().display().to_string().trim_end_matches('/')), - "homedir" => json!(std::env::var("HOME").unwrap_or_default()), + "homedir" => json!(raea_io_home::user_home().unwrap_or_default().display().to_string()), "cwd" => json!(std::env::current_dir().map(|p| p.display().to_string()).unwrap_or_default()), "resolve" => resolve_file(&s(0), Path::new(&s(1)), false).map(|p| json!(p.display().to_string())).unwrap_or_else(|e| err("MODULE_NOT_FOUND", e)), // a CommonJS file's source for require (JSON as an expression, TypeScript transpiled to CommonJS) diff --git a/engine/page/Cargo.toml b/engine/page/Cargo.toml index 178cf51f..f18a4894 100644 --- a/engine/page/Cargo.toml +++ b/engine/page/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "HTML, CSS and React pages in Bevy (docs/blitz-bevy.feature): Blitz works out what a page looks like, Vello paints it on Bevy's own GPU device into a Bevy Image" [dependencies] +dunce = "1" # the layers under it raea-sys-page = { path = "../../systems/page" } raea-sys-fonts = { path = "../../systems/fonts" } diff --git a/engine/page/src/motion.rs b/engine/page/src/motion.rs index 1f60682d..bdc2b04f 100644 --- a/engine/page/src/motion.rs +++ b/engine/page/src/motion.rs @@ -217,7 +217,7 @@ impl BlitzPage { let at = Page { size: UVec2::new(self.w, self.h), scale: 1.0 }; let mut config = raea_sys_page::config(at); config.net_provider = Some(Arc::new(raea_sys_page::net::FileNet { roots: root.map(Path::to_path_buf).into_iter().collect() })); - let abs = std::fs::canonicalize(path).map_err(|e| format!("{}: {e}", path.display()))?; + let abs = dunce::canonicalize(path).map_err(|e| format!("{}: {e}", path.display()))?; config.base_url = Some(url::Url::from_file_path(&abs).map_err(|_| format!("{}: not a file URL", abs.display()))?.to_string()); config.font_ctx = self.fonts.clone(); // a byte order mark is the decoder's, never the document's (it also hid ` J { pub fn install_dir(model: &str) -> PathBuf { let (var, name) = install_var(model); std::env::var_os(var).filter(|v| !v.is_empty()).map(PathBuf::from) - .unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache").join(name)) + .unwrap_or_else(|| raea_io_home::user_home().unwrap_or_default().join(".cache").join(name)) } /// A local model's install variable and default folder name. @@ -189,7 +189,7 @@ fn install_var(model: &str) -> (&'static str, &'static str) { pub fn setup_script(model: &str) -> PathBuf { let tools = std::env::var_os("RAEA_TOOLS").map(PathBuf::from).unwrap_or_else(|| raea_io_home::home().join("tools")); let p = tools.join(model).join("setup.sh"); - p.canonicalize().unwrap_or(p) + dunce::canonicalize(&p).unwrap_or(p) } /// Whether a local model can run from `dir`. SAO: the venv and either run.py with setup.sh's `.ready`, or the @@ -270,7 +270,7 @@ pub fn matchmove_params(p: &J) -> Result { pub fn perceive_bin() -> PathBuf { // raea-perceive.exe on Windows (#43) const NAME: &str = if cfg!(windows) { "raea-perceive.exe" } else { "raea-perceive" }; - let beside = std::env::current_exe().ok().and_then(|e| e.canonicalize().ok()).and_then(|e| Some(e.parent()?.join(NAME))); + let beside = std::env::current_exe().ok().and_then(|e| dunce::canonicalize(&e).ok()).and_then(|e| Some(e.parent()?.join(NAME))); let found = beside.into_iter().chain([PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"), "/../../target/release")).join(NAME)]).chain(std::env::var_os("PATH").iter().flat_map(std::env::split_paths).map(|d| d.join(NAME))).find(|p| p.is_file()); std::env::var_os("RAEA_PERCEIVE").filter(|v| !v.is_empty()).map(PathBuf::from).or(found).unwrap_or_else(|| NAME.into()) } diff --git a/io/assets/src/splat.rs b/io/assets/src/splat.rs index e3bbc264..245a2491 100644 --- a/io/assets/src/splat.rs +++ b/io/assets/src/splat.rs @@ -11,8 +11,7 @@ use super::*; /// Where the splat trainer is installed: $RAEA_SPLAT, else ~/.cache/raea-splat. pub fn splat_dir() -> PathBuf { - std::env::var_os("RAEA_SPLAT").filter(|v| !v.is_empty()).map(PathBuf::from) - .unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache/raea-splat")) + raea_io_home::env_path("RAEA_SPLAT", ".cache/raea-splat") } fn splat_installed(dir: &Path) -> bool { diff --git a/io/capcut/Cargo.toml b/io/capcut/Cargo.toml index 5423e867..944ba14c 100644 --- a/io/capcut/Cargo.toml +++ b/io/capcut/Cargo.toml @@ -7,4 +7,5 @@ publish = false description = "A CapCut desktop draft written from a timeline of clips (docs/capcut.feature CC2): tracks, segments and materials as CapCut's own, the project folder, the store's version markers and its project list" [dependencies] +raea-io-home = { path = "../home" } serde_json = "1" diff --git a/io/capcut/src/store.rs b/io/capcut/src/store.rs index b4b9a034..96bd29e3 100644 --- a/io/capcut/src/store.rs +++ b/io/capcut/src/store.rs @@ -14,7 +14,7 @@ pub fn store_root() -> Option { let local = std::env::var_os("LOCALAPPDATA")?; return Some(PathBuf::from(local).join("CapCut/User Data/Projects/com.lveditor.draft")); } - let home = std::env::var_os("HOME")?; + let home = raea_io_home::user_home()?; cfg!(target_os = "macos").then(|| PathBuf::from(home).join("Movies/CapCut/User Data/Projects/com.lveditor.draft")) } diff --git a/io/gen-core/src/tripo.rs b/io/gen-core/src/tripo.rs index bf6101ab..63f39bc7 100644 --- a/io/gen-core/src/tripo.rs +++ b/io/gen-core/src/tripo.rs @@ -59,7 +59,7 @@ pub fn available() -> bool { } fn home_dir() -> PathBuf { - std::env::var_os("HOME").map(PathBuf::from).unwrap_or_default() + raea_io_home::user_home().unwrap_or_default() } fn command() -> Command { diff --git a/io/gen/Cargo.toml b/io/gen/Cargo.toml index 9c224d23..30fe72f2 100644 --- a/io/gen/Cargo.toml +++ b/io/gen/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Generation flows: made.app's models at provider cost, ComfyUI workflows read and written, and the runner that routes each step to made, fal, Replicate, OpenRouter, Modal, a ComfyUI server or a local model" [dependencies] +dunce = "1" raea-io-gen-comfy = { path = "../gen-comfy" } raea-io-gen-core = { path = "../gen-core" } raea-io-home = { path = "../home" } diff --git a/io/gen/src/cli.rs b/io/gen/src/cli.rs index 158150f2..633ca9ee 100644 --- a/io/gen/src/cli.rs +++ b/io/gen/src/cli.rs @@ -104,7 +104,7 @@ pub fn command(args: &[String], local: Option<&dyn Local>) -> Result = args.windows(2).filter(|w| w[0] == "--image").map(|w| w[1].as_str()).collect(); let mut flow = Flow::default(); for (k, f) in images.iter().enumerate() { - let abs = std::fs::canonicalize(f).map_err(|e| format!("{f}: {e}"))?; + let abs = dunce::canonicalize(f).map_err(|e| format!("{f}: {e}"))?; flow.steps.insert(format!("in{k}"), Step::new("media.load", json!({"path": abs}))); } let refs: Vec = (0..images.len()).map(|k| json!(format!("@in{k}"))).collect(); diff --git a/io/gen/src/run.rs b/io/gen/src/run.rs index 84df4ea2..fbb8ce71 100644 --- a/io/gen/src/run.rs +++ b/io/gen/src/run.rs @@ -398,7 +398,7 @@ fn name_output(dir: &Path, name: &str, files: &[PathBuf]) -> Result let copy = |from: &Path, to: &Path| { // a name that already is the file (a link to it, or the file itself) is left alone: copying a file onto itself // truncates it to nothing (11-05: four Tripo models lost their step files so). A link elsewhere is replaced. - if let (Ok(a), Ok(b)) = (std::fs::canonicalize(from), std::fs::canonicalize(to)) { + if let (Ok(a), Ok(b)) = (dunce::canonicalize(from), dunce::canonicalize(to)) { if a == b { return Ok(to.to_path_buf()); } diff --git a/io/home/Cargo.toml b/io/home/Cargo.toml index 17e18f8f..b0a71185 100644 --- a/io/home/Cargo.toml +++ b/io/home/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Where raea's own files are ($RAEA_HOME, an install's share/raea, or the tree a build came from), and its per-user caches and logs" [dependencies] +dunce = "1" serde_json = "1" [dev-dependencies] diff --git a/io/home/src/lib.rs b/io/home/src/lib.rs index a77c388a..fe2373d1 100644 --- a/io/home/src/lib.rs +++ b/io/home/src/lib.rs @@ -13,7 +13,7 @@ pub fn home() -> std::path::PathBuf { if let Some(h) = std::env::var_os("RAEA_HOME").filter(|v| !v.is_empty()) { return std::path::PathBuf::from(h); } - let installed = std::env::current_exe().ok().and_then(|e| e.canonicalize().ok()).map(plain).and_then(|e| e.parent()?.parent().map(|p| p.join("share/raea"))); + let installed = std::env::current_exe().ok().and_then(|e| dunce::canonicalize(&e).ok()).map(plain).and_then(|e| e.parent()?.parent().map(|p| p.join("share/raea"))); if let Some(d) = installed.filter(|d| d.join("sdk/raea/src").is_dir()) { return d; } @@ -22,7 +22,7 @@ pub fn home() -> std::path::PathBuf { return std::path::PathBuf::from("/nonexistent/raea"); } let tree = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("../.."); - tree.canonicalize().map(plain).unwrap_or(tree) + dunce::canonicalize(&tree).map(plain).unwrap_or(tree) }) .clone() } @@ -38,11 +38,25 @@ pub fn plain(p: std::path::PathBuf) -> std::path::PathBuf { } } +/// `p` canonical (links resolved, and on Windows plain C:\..., through dunce), or `p` as given when it can't be read +/// (it doesn't exist yet). +pub fn real(p: std::path::PathBuf) -> std::path::PathBuf { + dunce::canonicalize(&p).unwrap_or(p) +} + /// a verbatim drive path's plain form (`\\?\C:\x` is `C:\x`); None for any other path fn drive(s: &str) -> Option<&str> { s.strip_prefix(r"\\?\").filter(|r| r.as_bytes().get(1) == Some(&b':')) } +/// The person's home folder: $HOME, else %USERPROFILE%, the order Git for Windows reads them in. Windows gives an app +/// opened from the Start menu or Explorer no HOME, so a read of HOME alone found nothing there and put ~/.raea, the +/// caches and the inbox under whatever folder raea ran in. None when neither is set (an empty one counts as unset). +/// Every read of the home folder goes through here (tools/windows-paths.sh). +pub fn user_home() -> Option { + ["HOME", "USERPROFILE"].into_iter().find_map(|k| std::env::var_os(k).filter(|v| !v.is_empty())).map(std::path::PathBuf::from) +} + /// Where raea's models are kept (Beat This!, Demucs, TransNet, Silero, the Core ML ones): ~/.local/share/raea-models on /// the Mac and Linux, %LOCALAPPDATA%\raea\models on Windows, which has no HOME (#43). Relative when neither is set. pub fn models() -> std::path::PathBuf { @@ -50,7 +64,7 @@ pub fn models() -> std::path::PathBuf { let var = |k: &str| std::env::var_os(k).filter(|v| !v.is_empty()).map(PathBuf::from); match var("LOCALAPPDATA").filter(|_| cfg!(windows)) { Some(d) => d.join("raea").join("models"), - None => var("HOME").unwrap_or_default().join(".local/share/raea-models"), + None => user_home().unwrap_or_default().join(".local/share/raea-models"), } } @@ -73,7 +87,7 @@ fn user_dir(apple: &str, xdg: &str, xdg_default: &str, windows: &str) -> Option< if cfg!(windows) { return std::env::var_os("LOCALAPPDATA").filter(|d| !d.is_empty()).map(|d| PathBuf::from(d).join("raea").join(windows)); } - let home = PathBuf::from(std::env::var_os("HOME").filter(|h| !h.is_empty())?); + let home = user_home()?; if cfg!(target_vendor = "apple") { return Some(home.join(apple)); } @@ -86,7 +100,7 @@ fn user_dir(apple: &str, xdg: &str, xdg_default: &str, windows: &str) -> Option< pub fn env_path(var: &str, under_home: &str) -> std::path::PathBuf { match std::env::var_os(var).filter(|v| !v.is_empty()) { Some(p) => p.into(), - None => std::path::PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(under_home), + None => user_home().unwrap_or_default().join(under_home), } } @@ -183,7 +197,7 @@ mod tests { } #[test] - fn caches_and_logs_follow_the_platform() { + fn caches_logs_and_the_home_folder_follow_the_platform() { // one test, so nothing else reads these variables while it sets them unsafe { std::env::set_var("HOME", "/h"); @@ -197,6 +211,21 @@ mod tests { // a relative XDG_CACHE_HOME is ignored, as the spec says assert_eq!((c.to_str().unwrap(), l.to_str().unwrap()), ("/h/.cache/raea", "/state/raea")); } + // the home folder: HOME, else USERPROFILE (an app opened from Windows' Start menu has no HOME); empty is unset + let was = std::env::var_os("USERPROFILE"); + unsafe { std::env::set_var("USERPROFILE", r"C:\Users\Ada") }; + assert_eq!(super::user_home().unwrap().to_str(), Some("/h")); + unsafe { std::env::set_var("HOME", "") }; + assert_eq!(super::user_home().unwrap().to_str(), Some(r"C:\Users\Ada")); + assert_eq!(super::env_path("RAEA_NO_SUCH_VAR", ".raea/env"), std::path::Path::new(r"C:\Users\Ada").join(".raea/env")); + unsafe { std::env::remove_var("USERPROFILE") }; + assert_eq!(super::user_home(), None); + unsafe { + std::env::set_var("HOME", "/h"); + if let Some(w) = was { + std::env::set_var("USERPROFILE", w); + } + } } } @@ -209,7 +238,7 @@ pub fn offline(what: &str) -> Result<(), String> { let set = match std::env::var("RAEA_OFFLINE") { Ok(v) => on(&v), Err(_) => { - let file = std::env::var_os("RAEA_ENV_FILE").map(std::path::PathBuf::from).or_else(|| std::env::var_os("HOME").map(|h| std::path::PathBuf::from(h).join(".raea/env"))); + let file = std::env::var_os("RAEA_ENV_FILE").map(std::path::PathBuf::from).or_else(|| user_home().map(|h| h.join(".raea/env"))); file.and_then(|f| std::fs::read_to_string(f).ok()).is_some_and(|s| { s.lines().filter(|l| !l.trim_start().starts_with('#')).filter_map(|l| l.split_once('=')).any(|(k, v)| k.trim() == "RAEA_OFFLINE" && on(v.trim().trim_matches('"'))) }) diff --git a/io/npm/src/store.rs b/io/npm/src/store.rs index 8e8260d5..0c4a31a1 100644 --- a/io/npm/src/store.rs +++ b/io/npm/src/store.rs @@ -4,7 +4,7 @@ use super::*; /// Where raea's npm keeps what it fetched: RAEA_NPM_HOME, or ~/.raea/npm. pub(crate) fn home() -> PathBuf { - std::env::var_os("RAEA_NPM_HOME").map(PathBuf::from).unwrap_or_else(|| PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(".raea/npm")) + raea_io_home::env_path("RAEA_NPM_HOME", ".raea/npm") } /// A package name as one path segment ("@scope/name" is "@scope+name"). diff --git a/io/shell/Cargo.toml b/io/shell/Cargo.toml index 22639520..a0f5d1cf 100644 --- a/io/shell/Cargo.toml +++ b/io/shell/Cargo.toml @@ -12,6 +12,7 @@ default = ["net"] net = ["dep:raea-io-net", "dep:url"] [dependencies] +dunce = "1" raea-io-home = { path = "../../io/home" } raea-core-calls = { path = "../../core/calls" } serde_json = "1" diff --git a/io/shell/src/archive.rs b/io/shell/src/archive.rs index 9eb7cde6..17d423c8 100644 --- a/io/shell/src/archive.rs +++ b/io/shell/src/archive.rs @@ -41,7 +41,7 @@ fn inside(root: &Path, base: &Path, rel: &Path) -> Option { } fn run(v: &Value) -> R { - let root = PathBuf::from(s(v, "root")?).canonicalize().map_err(|e| e.to_string())?; + let root = dunce::canonicalize(&PathBuf::from(s(v, "root")?)).map_err(|e| e.to_string())?; let cwd = PathBuf::from(s(v, "cwd")?); let file = inside(&root, &cwd, Path::new(s(v, "file")?)).ok_or("tar: the archive is outside the project")?; let gz = v.get("gzip").and_then(Value::as_bool).unwrap_or(false) || s(v, "file").map(|f| f.ends_with(".tgz") || f.ends_with(".gz")).unwrap_or(false); diff --git a/io/shell/src/fs/calls.rs b/io/shell/src/fs/calls.rs index 5ca2194d..742bd12b 100644 --- a/io/shell/src/fs/calls.rs +++ b/io/shell/src/fs/calls.rs @@ -13,7 +13,7 @@ pub(crate) fn calls() -> Vec { mk("fs.open", "{ root: string }", "{ id: number; root: string }", "a project folder opened as a filesystem (made if missing)", Arc::new(|v| { let root = Path::new(s(v, "root")?); fs::create_dir_all(root).map_err(|e| format!("{}: {e}", root.display()))?; - let root = root.canonicalize().map_err(|e| e.to_string())?; + let root = dunce::canonicalize(&root).map_err(|e| e.to_string())?; let mut pr = Project { root: root.clone(), group: None, seq: 0, state: "0".repeat(64), done: Vec::new(), redo: Vec::new() }; for r in pr.rows() { pr.seq = r["seq"].as_u64().unwrap_or(pr.seq); diff --git a/io/shell/src/fs/mod.rs b/io/shell/src/fs/mod.rs index 6ff9cea7..c5078f50 100644 --- a/io/shell/src/fs/mod.rs +++ b/io/shell/src/fs/mod.rs @@ -110,7 +110,7 @@ impl Project { /// The real path with every link followed, refused if it leaves the project. fn follow(&self, v: &str, op: &str) -> R { let p = self.real(v)?; - match p.canonicalize() { + match dunce::canonicalize(&p) { Ok(c) if c.starts_with(&self.root) => { if c.strip_prefix(&self.root).ok().and_then(|r| r.components().next()).is_some_and(|c| c.as_os_str() == META) { return Err(err("ENOENT", "no such file or directory", op, v)); @@ -128,7 +128,7 @@ impl Project { /// put in reach. fn follow_read(&self, v: &str, op: &str) -> R { match self.follow(v, op) { - Err(e) if e.starts_with("EACCES") => self.real(v)?.canonicalize().map_err(|_| err("ENOENT", "no such file or directory", op, v)), + Err(e) if e.starts_with("EACCES") => dunce::canonicalize(&self.real(v)?).map_err(|_| err("ENOENT", "no such file or directory", op, v)), r => r, } } diff --git a/io/trace/src/crash.rs b/io/trace/src/crash.rs index 58019c9a..d4cc861e 100644 --- a/io/trace/src/crash.rs +++ b/io/trace/src/crash.rs @@ -163,7 +163,7 @@ pub(crate) fn install_signal_handlers() { /// Sessions under `base` that ended unclean (no end.json, their process gone) get macOS's crash report for their pid. pub(crate) fn adopt_crash_reports(base: &Path) { - let reports = std::env::var_os("HOME").map(|h| PathBuf::from(h).join("Library/Logs/DiagnosticReports")); + let reports = raea_io_home::user_home().map(|h| h.join("Library/Logs/DiagnosticReports")); let Ok(entries) = std::fs::read_dir(base) else { return }; for e in entries.flatten() { let d = e.path(); diff --git a/runtime/bundle/lib/Cargo.toml b/runtime/bundle/lib/Cargo.toml index 5498a465..bc4b9937 100644 --- a/runtime/bundle/lib/Cargo.toml +++ b/runtime/bundle/lib/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "raea-bundle's library (engine/bundle: Rolldown) loaded at run time: an entry in, its script and CSS out" [dependencies] +dunce = "1" # never a Cargo dependency on raea-bundle itself: Rolldown's crates turn on serde_json's preserve_order and # arbitrary_precision, and features unify across a binary (f60e0b7) libloading = "0.8" diff --git a/runtime/bundle/lib/src/app.rs b/runtime/bundle/lib/src/app.rs index a7768233..877a4875 100644 --- a/runtime/bundle/lib/src/app.rs +++ b/runtime/bundle/lib/src/app.rs @@ -49,9 +49,9 @@ pub const SCREEN: &str = "{ width: innerWidth, height: innerHeight }"; pub fn bundle(app: &Path, home: &Path, props: &str) -> Result<(String, String), String> { // canonical, and on Windows without canonicalize()'s verbatim \\?\ prefix: Rolldown can't resolve an entry that // imports a path written with it (T1f: the Windows release check, 11-07) - let app = raea_io_home::plain(app.canonicalize().map_err(|e| format!("{}: {e}", app.display()))?); + let app = raea_io_home::plain(dunce::canonicalize(&app).map_err(|e| format!("{}: {e}", app.display()))?); // one path per file: a module reached by two spellings of its path is bundled twice (two wires, two call ids) - let home = &raea_io_home::plain(home.canonicalize().map_err(|e| format!("{}: {e}", home.display()))?); + let home = &raea_io_home::plain(dunce::canonicalize(&home).map_err(|e| format!("{}: {e}", home.display()))?); // one work folder per call: tests bundle on several threads of one process static N: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0); let work = std::env::temp_dir().join(format!("raea-app-{}-{}", std::process::id(), N.fetch_add(1, std::sync::atomic::Ordering::Relaxed))); diff --git a/runtime/bundle/lib/src/lib.rs b/runtime/bundle/lib/src/lib.rs index 325b0383..008faf0d 100644 --- a/runtime/bundle/lib/src/lib.rs +++ b/runtime/bundle/lib/src/lib.rs @@ -24,7 +24,7 @@ pub fn lib() -> Result<&'static Lib, String> { let mut at: Vec = std::env::var_os("RAEA_BUNDLE_LIB").map(PathBuf::from).into_iter().collect(); // beside the binary (runtime/react/build.rs puts it there), or a folder up (test binaries run from deps/); the binary // itself, not a link to it (an install links ~/.local/bin/raea to ~/.raea/bin) - if let Some(dir) = std::env::current_exe().ok().map(|e| e.canonicalize().unwrap_or(e)).and_then(|e| e.parent().map(Path::to_path_buf)) { + if let Some(dir) = std::env::current_exe().ok().map(raea_io_home::real).and_then(|e| e.parent().map(Path::to_path_buf)) { at.push(dir.join(&name)); at.extend(dir.parent().map(|d| d.join(&name))); } diff --git a/runtime/encode/src/progress.rs b/runtime/encode/src/progress.rs index 465f4bd4..34e25a77 100644 --- a/runtime/encode/src/progress.rs +++ b/runtime/encode/src/progress.rs @@ -31,7 +31,7 @@ fn dir() -> Option { return None; } // unset: ~/.raea/renders, the home being USERPROFILE on Windows, which has no HOME - match (named, std::env::var_os("HOME").or(std::env::var_os("USERPROFILE"))) { + match (named, raea_io_home::user_home()) { (Some(d), _) => Some(PathBuf::from(d)), (None, Some(home)) => Some(Path::new(&home).join(".raea/renders")), (None, None) => None, diff --git a/runtime/js/Cargo.toml b/runtime/js/Cargo.toml index e265ac37..5e98b0c7 100644 --- a/runtime/js/Cargo.toml +++ b/runtime/js/Cargo.toml @@ -19,6 +19,7 @@ media = ["dep:raea-io-media", "dep:cpal"] [dependencies] # images bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "bevy_render", "bevy_image"] } +dunce = "1" # the op wire to and from a page's script raea-core-wire = { path = "../../core/wire" } raea-io-net = { path = "../../io/net", features = ["ws"] } diff --git a/runtime/js/src/html_page.rs b/runtime/js/src/html_page.rs index 6de1a3a9..9593ef3d 100644 --- a/runtime/js/src/html_page.rs +++ b/runtime/js/src/html_page.rs @@ -134,11 +134,11 @@ pub fn prepare(file: &Path, fps: f64, fonts: Option<&Path>, size: Option<(u32, u let file = if file.is_dir() { file.join("index.html") } else { file.to_path_buf() }; let source = std::fs::read_to_string(&file).map_err(|e| format!("{}: {e}", file.display()))?; // (plain: Windows canonicalizes to a verbatim `\\?\D:\` path, #40) - let file = file.canonicalize().map(raea_io_home::plain).unwrap_or(file); + let file = dunce::canonicalize(&file).map(raea_io_home::plain).unwrap_or(file); // served: the page's folder is `root` and the page a path under it (`/x` is then root's x, as a server rooted // there serves it); the project listing is left out (a WPT checkout is too big to list, and only a // composition's sub-compositions use it) - let served = root.and_then(|r| r.canonicalize().ok()).map(raea_io_home::plain).filter(|r| file.starts_with(r)); + let served = root.and_then(|r| dunce::canonicalize(&r).ok()).map(raea_io_home::plain).filter(|r| file.starts_with(r)); let (dir, name, files) = match &served { Some(r) => (r.clone(), file.strip_prefix(r).unwrap_or(&file).to_string_lossy().into_owned(), vec![]), None => { diff --git a/runtime/jsengine/Cargo.toml b/runtime/jsengine/Cargo.toml index ecd2a76c..64532869 100644 --- a/runtime/jsengine/Cargo.toml +++ b/runtime/jsengine/Cargo.toml @@ -14,6 +14,7 @@ name = "raea_runtime_jsengine" portable = ["dep:rquickjs"] [dependencies] +raea-io-home = { path = "../../io/home" } rquickjs = { version = "0.14", optional = true, features = ["loader"] } [target.'cfg(target_vendor = "apple")'.dependencies] diff --git a/runtime/jsengine/src/upkeep.rs b/runtime/jsengine/src/upkeep.rs index 1b155b19..49a4b7c5 100644 --- a/runtime/jsengine/src/upkeep.rs +++ b/runtime/jsengine/src/upkeep.rs @@ -74,7 +74,7 @@ impl Upkeep { fn open_log() -> Option { static N: AtomicU32 = AtomicU32::new(0); - let home = std::env::var_os("HOME").or_else(|| std::env::var_os("USERPROFILE"))?; + let home = raea_io_home::user_home()?; let dir = PathBuf::from(home).join(".raea").join("logs"); if let Err(e) = std::fs::create_dir_all(&dir) { eprintln!("raea-runtime-jsengine: no heap log in {}: {e}", dir.display()); diff --git a/runtime/track/Cargo.toml b/runtime/track/Cargo.toml index f396d2e3..1c83c6b2 100644 --- a/runtime/track/Cargo.toml +++ b/runtime/track/Cargo.toml @@ -6,6 +6,7 @@ description = "Matchmove: a clip's camera solved for , as `raea track license = "FSL-1.1-ALv2" [dependencies] +dunce = "1" raea-io-assets = { path = "../../io/assets" } raea-native = { path = "../../engine/native", default-features = false } raea-runtime-bundle = { path = "../../runtime/bundle" } diff --git a/runtime/track/src/lib.rs b/runtime/track/src/lib.rs index 0f0f73b8..eedfbf7c 100644 --- a/runtime/track/src/lib.rs +++ b/runtime/track/src/lib.rs @@ -70,7 +70,7 @@ fn answer(store: &raea_io_assets::Store, a: &raea_io_assets::Asset) -> R /// `raea track CLIP ...`: the clip's camera solved once and kept; what it found. pub fn track(args: &[String]) -> R { let (clip, params) = parse(args)?; - let clip = clip.canonicalize().map_err(|e| format!("{}: {e}", clip.display()))?; + let clip = dunce::canonicalize(&clip).map_err(|e| format!("{}: {e}", clip.display()))?; let dir = PathBuf::from(flag(args, "--dir").unwrap_or_else(|| ".".into())); let store = raea_io_assets::Store::beside(&dir.join("edit.tsx")); let t0 = std::time::Instant::now(); diff --git a/runtime/world/Cargo.toml b/runtime/world/Cargo.toml index cd3805a3..6e148f47 100644 --- a/runtime/world/Cargo.toml +++ b/runtime/world/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "A composition's frames read into worlds of facts (docs/direction.feature DR1): React stepped with nothing drawn, its 3D, its page laid out and its timeline as entities with components" [dependencies] +dunce = "1" raea-core-facts = { path = "../../core/facts" } raea-core-scene = { path = "../../core/scene" } raea-runtime-scene = { path = "../scene" } diff --git a/runtime/world/src/lib.rs b/runtime/world/src/lib.rs index 3b5bc9ec..84ab0dfe 100644 --- a/runtime/world/src/lib.rs +++ b/runtime/world/src/lib.rs @@ -49,7 +49,7 @@ struct Snap { /// The frames of `tsx`'s composition (`o` picks it) as worlds, one a frame, in `ask.frames`' order. The same frame /// gives the same world each time: frames are pure. pub fn read(tsx: &Path, o: &CompOpts, ask: &Ask) -> R> { - let tsx = tsx.canonicalize().map_err(|e| format!("{}: {e}", tsx.display()))?; + let tsx = dunce::canonicalize(&tsx).map_err(|e| format!("{}: {e}", tsx.display()))?; let js =std::env::temp_dir().join(format!("raea-world-{}.js", std::process::id())); // every element and part stamped with its place in the code, so each entity has its Source (as the stage's // picks have their keys, engine/page/stage); RAEA_SOURCE_STAMPS=0 in the environment keeps them off diff --git a/runtime/world/src/renders/tests.rs b/runtime/world/src/renders/tests.rs index cddb526d..d0e49aaa 100644 --- a/runtime/world/src/renders/tests.rs +++ b/runtime/world/src/renders/tests.rs @@ -9,7 +9,7 @@ fn project(name: &str) -> (PathBuf, PathBuf) { std::fs::write(dir.join(".raea/project"), "").unwrap(); let tsx = dir.join("piece.tsx"); std::fs::write(&tsx, "export default 1").unwrap(); - let dir = dir.canonicalize().unwrap(); + let dir = dunce::canonicalize(&dir).unwrap(); (dir.clone(), dir.join("piece.tsx")) } diff --git a/sdk/ui/conformance/Cargo.lock b/sdk/ui/conformance/Cargo.lock index c7188ea0..b148229b 100644 --- a/sdk/ui/conformance/Cargo.lock +++ b/sdk/ui/conformance/Cargo.lock @@ -7,6 +7,7 @@ name = "conformance" version = "0.1.0" dependencies = [ "conformance-fake", + "dunce", "libc", "serde_json", "toml", @@ -19,6 +20,12 @@ dependencies = [ "serde_json", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "equivalent" version = "1.0.3" diff --git a/sdk/ui/conformance/Cargo.toml b/sdk/ui/conformance/Cargo.toml index 1aa3c34d..c691298a 100644 --- a/sdk/ui/conformance/Cargo.toml +++ b/sdk/ui/conformance/Cargo.toml @@ -14,6 +14,7 @@ name = "conformance" path = "src/main.rs" [dependencies] +dunce = "1" serde_json = "1" toml = "1" libc = "0.2" diff --git a/sdk/ui/conformance/src/run.rs b/sdk/ui/conformance/src/run.rs index 67ebd082..e945f459 100644 --- a/sdk/ui/conformance/src/run.rs +++ b/sdk/ui/conformance/src/run.rs @@ -83,7 +83,7 @@ fn build_app(app: &Path) -> Result<(), String> { impl Opts { pub fn parse(args: &[String]) -> Result { let here = crate::here(); - let repo = here.join("../../..").canonicalize().unwrap_or(here.join("../../..")); + let repo = dunce::canonicalize(&here.join("../../..")).unwrap_or(here.join("../../..")); let mut o = Opts { bin: repo.join("target/release/raea-page-host"), substrate: "current".into(), diff --git a/sdk/ui/parity/Cargo.lock b/sdk/ui/parity/Cargo.lock index f27d3b4d..9d928223 100644 --- a/sdk/ui/parity/Cargo.lock +++ b/sdk/ui/parity/Cargo.lock @@ -103,6 +103,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + [[package]] name = "fdeflate" version = "0.3.7" @@ -447,6 +453,7 @@ name = "ui-parity" version = "0.1.0" dependencies = [ "base64", + "dunce", "image", "serde_json", "ui-parity-compare", diff --git a/sdk/ui/parity/Cargo.toml b/sdk/ui/parity/Cargo.toml index 654dd627..b70cc206 100644 --- a/sdk/ui/parity/Cargo.toml +++ b/sdk/ui/parity/Cargo.toml @@ -15,6 +15,7 @@ name = "ui-parity" path = "src/main.rs" [dependencies] +dunce = "1" # Chrome's side and the comparison ui-parity-compare = { path = "compare" } serde_json = "1" diff --git a/sdk/ui/parity/src/app.rs b/sdk/ui/parity/src/app.rs index 93508dff..e3aa83e2 100644 --- a/sdk/ui/parity/src/app.rs +++ b/sdk/ui/parity/src/app.rs @@ -126,7 +126,7 @@ pub fn run(o: Opts) -> Result { let html = std::fs::read_to_string(&index).map_err(|e| format!("dist/index.html: {e}"))?; let html = html.replacen("", &format!(""), 1); std::fs::write(&index, html.replacen("", &format!(""), 1)).map_err(|e| e.to_string())?; - let base = crate::wpt::serve(o.app.join("dist").canonicalize().map_err(|e| e.to_string())?)?; + let base = crate::wpt::serve(dunce::canonicalize(&o.app.join("dist")).map_err(|e| e.to_string())?)?; let js = std::fs::read_to_string(o.app.join("blitz/out/app.js")).map_err(|e| format!("blitz/out/app.js: {e}"))?; let sheet = std::fs::read_to_string(o.app.join("blitz/out/app.css")).map_err(|e| format!("blitz/out/app.css: {e}"))?; std::fs::write(o.app.join("blitz/out/app.pinned.css"), format!("{sheet}\n{PIN}\n")).map_err(|e| e.to_string())?; diff --git a/sdk/ui/parity/src/main.rs b/sdk/ui/parity/src/main.rs index 92bc1ec7..d5193739 100644 --- a/sdk/ui/parity/src/main.rs +++ b/sdk/ui/parity/src/main.rs @@ -61,7 +61,7 @@ fn here() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")) } fn repo() -> PathBuf { - here().join("../../..").canonicalize().unwrap_or(here().join("../../..")) + dunce::canonicalize(&here().join("../../..")).unwrap_or(here().join("../../..")) } struct Opts { diff --git a/sdk/ui/parity/src/wpt.rs b/sdk/ui/parity/src/wpt.rs index b31f49b4..b1eaeff2 100644 --- a/sdk/ui/parity/src/wpt.rs +++ b/sdk/ui/parity/src/wpt.rs @@ -284,7 +284,7 @@ pub(crate) fn serve(root: PathBuf) -> Result { if file.is_dir() { file = file.join("index.html"); } - let ok = file.canonicalize().is_ok_and(|f| f.starts_with(&root) && f.is_file()); + let ok = dunce::canonicalize(&file).is_ok_and(|f| f.starts_with(&root) && f.is_file()); let (status, body, ty) = if ok { ("200 OK", std::fs::read(&file).unwrap_or_default(), mime(&file)) } else { ("404 Not Found", vec![], "text/plain") }; // CORS for any origin: an app's sandboxed frame (origin "null") loads its module scripts from here (src/app.rs) let _ = write!(s, "HTTP/1.1 {status}\r\nContent-Type: {ty}\r\nContent-Length: {}\r\nAccess-Control-Allow-Origin: *\r\nConnection: close\r\n\r\n", body.len()); @@ -320,7 +320,7 @@ pub fn run(o: Opts) -> Result { PathBuf::from(String::from_utf8_lossy(&r.stdout).trim()) } }; - let root = root.canonicalize().map_err(|e| format!("{}: {e}", root.display()))?; + let root = dunce::canonicalize(&root).map_err(|e| format!("{}: {e}", root.display()))?; let commit = std::fs::read_to_string(root.join(".git/HEAD")).unwrap_or_default().trim().to_string(); let (tests, skipped) = discover(&root, &o.areas, &o.only); let tests = sample(tests, &o.tier); diff --git a/systems/bake/Cargo.toml b/systems/bake/Cargo.toml index 8c9b5a7c..f03f90b4 100644 --- a/systems/bake/Cargo.toml +++ b/systems/bake/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Rigid bodies, glTF parts and goo baked once per request into a composition's asset store" [dependencies] +raea-io-home = { path = "../../io/home" } serde_json = "1" sha2 = "0.10" image = { version = "0.25", default-features = false, features = ["png"] } diff --git a/systems/bake/src/goo.rs b/systems/bake/src/goo.rs index 64a4d06a..91e3cbfb 100644 --- a/systems/bake/src/goo.rs +++ b/systems/bake/src/goo.rs @@ -7,8 +7,7 @@ use serde_json::{Value, json}; use super::*; fn goo_dir() -> PathBuf { - std::env::var_os("RAEA_GOO").filter(|v| !v.is_empty()).map(PathBuf::from) - .unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache/raea-goo")) + raea_io_home::env_path("RAEA_GOO", ".cache/raea-goo") } /// the goo tool's scripts (tools/goo): run.py (MPM) and sph.py (SPlisHSPlasH, a spec's "solver": "sph"); a bake is diff --git a/systems/columns/Cargo.toml b/systems/columns/Cargo.toml index d81cb64a..cf3e5532 100644 --- a/systems/columns/Cargo.toml +++ b/systems/columns/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Fingerprint's columns (docs/fingerprint.feature FP1a): a file's frames and sound read once by frozen on-device encoders (SigLIP 2, CLAP and YAMNet on ONNX Runtime) with change and look columns, cached by content hash; and the damage that makes labels by construction (FP4a)" [dependencies] +raea-io-home = { path = "../../io/home" } # every encoder is an ONNX model on ONNX Runtime's CPU kernels (raea-sys-ml), never Core ML's GPU raea-sys-ml = { path = "../ml" } ort = { version = "=2.0.0-rc.13", features = ["half"] } diff --git a/systems/columns/src/lib.rs b/systems/columns/src/lib.rs index c47f5614..7b510861 100644 --- a/systems/columns/src/lib.rs +++ b/systems/columns/src/lib.rs @@ -219,7 +219,7 @@ pub(crate) fn text_model(model: &Path, tokenizer: &Path, what: &str) -> Result<( pub fn under(var: &str, rel: &str) -> PathBuf { match std::env::var_os(var) { Some(p) => p.into(), - None => Path::new(&std::env::var_os("HOME").unwrap_or_default()).join(rel), + None => raea_io_home::user_home().unwrap_or_default().join(rel), } } diff --git a/systems/columns/src/tests.rs b/systems/columns/src/tests.rs index ace63441..56f10a32 100644 --- a/systems/columns/src/tests.rs +++ b/systems/columns/src/tests.rs @@ -6,7 +6,7 @@ use super::*; use std::path::PathBuf; fn spike() -> PathBuf { - std::env::var_os("FP_SPIKE").map(PathBuf::from).unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap()).join("films/fingerprint-spike")) + std::env::var_os("FP_SPIKE").map(PathBuf::from).unwrap_or_else(|| raea_io_home::user_home().unwrap().join("films/fingerprint-spike")) } fn cos(a: &[f32], b: &[f32]) -> f32 { diff --git a/systems/fingerprint-use/Cargo.toml b/systems/fingerprint-use/Cargo.toml index 36c7807c..26abefb4 100644 --- a/systems/fingerprint-use/Cargo.toml +++ b/systems/fingerprint-use/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Using a fingerprint (docs/fingerprint.feature FP3, FP6e, FP8b, FP12a, FP14c): a piece scored per moment and drawn as a sheet, patch heads that say where, which fingerprint judges a piece, where two differ, and profiles of admired work" [dependencies] +dunce = "1" # the fingerprint: its taxonomy, folder, evidence, heads and words raea-sys-fingerprint = { path = "../fingerprint" } # a piece's columns, and the frames and sound the sheet draws diff --git a/systems/fingerprint-use/src/grow.rs b/systems/fingerprint-use/src/grow.rs index f5aa3152..7fb7f726 100644 --- a/systems/fingerprint-use/src/grow.rs +++ b/systems/fingerprint-use/src/grow.rs @@ -26,7 +26,7 @@ pub fn perceive() -> Option { } let name = if cfg!(windows) { "raea-perceive.exe" } else { "raea-perceive" }; let mut dirs: Vec = Vec::new(); - if let Ok(exe) = std::env::current_exe().and_then(|e| e.canonicalize()) { + if let Ok(exe) = std::env::current_exe().and_then(|e| dunce::canonicalize(&e)) { dirs.extend(exe.parent().map(Path::to_path_buf)); } if let Some(path) = std::env::var_os("PATH") { diff --git a/systems/fingerprint/Cargo.toml b/systems/fingerprint/Cargo.toml index 351c717c..f5d28897 100644 --- a/systems/fingerprint/Cargo.toml +++ b/systems/fingerprint/Cargo.toml @@ -13,3 +13,6 @@ raea-sys-columns = { path = "../columns" } serde = { version = "1", features = ["derive"] } serde_json = "1" anyhow = "1" + +[dev-dependencies] +raea-io-home = { path = "../../io/home" } diff --git a/systems/fingerprint/src/tests.rs b/systems/fingerprint/src/tests.rs index 95e390af..31f43751 100644 --- a/systems/fingerprint/src/tests.rs +++ b/systems/fingerprint/src/tests.rs @@ -141,7 +141,7 @@ fn about_extends_and_applies_round_trip() { #[test] #[ignore] fn word_heads_score_noise_and_clipping_from_words_alone() { - let spike = std::env::var_os("FP_SPIKE").map(std::path::PathBuf::from).unwrap_or_else(|| std::path::PathBuf::from(std::env::var("HOME").unwrap()).join("films/fingerprint-spike")); + let spike = std::env::var_os("FP_SPIKE").map(std::path::PathBuf::from).unwrap_or_else(|| raea_io_home::user_home().unwrap().join("films/fingerprint-spike")); let items: Vec = serde_json::from_slice(&std::fs::read(spike.join("clap/items.json")).unwrap()).unwrap(); let mut enc = raea_sys_columns::Encoders::load().unwrap(); let w = Words::build(&mut enc, &base("me")).unwrap(); diff --git a/systems/footage/Cargo.toml b/systems/footage/Cargo.toml index 52a311aa..b1e3757c 100644 --- a/systems/footage/Cargo.toml +++ b/systems/footage/Cargo.toml @@ -10,6 +10,8 @@ description = "raea's perception of footage (perception.feature): a clip read on denoise = ["raea-sys-song/denoise"] [dependencies] +dunce = "1" +raea-io-home = { path = "../../io/home" } # frames come from the media plane (VideoToolbox on Apple, ffmpeg or the software decoders elsewhere) raea-io-media = { path = "../../io/media", default-features = false, features = ["apple"] } raea-sys-layout = { path = "../layout" } diff --git a/systems/footage/src/ingest/mod.rs b/systems/footage/src/ingest/mod.rs index f90696cb..288cc6ff 100644 --- a/systems/footage/src/ingest/mod.rs +++ b/systems/footage/src/ingest/mod.rs @@ -288,7 +288,7 @@ pub fn ingest(path: &Path, store: &Path, backend: &str, v: &dyn Vision) -> Resul if m.version != INGEST_VERSION { m = Manifest { version: INGEST_VERSION, ..Default::default() }; } - m.source = std::fs::canonicalize(path).unwrap_or(path.to_path_buf()).display().to_string(); + m.source = dunce::canonicalize(path).unwrap_or(path.to_path_buf()).display().to_string(); m.hash = hash; let save = |m: &Manifest| std::fs::write(&mpath, serde_json::to_string_pretty(m).unwrap()).map_err(|e| e.to_string()); let timed = |f: &mut dyn FnMut() -> Result<(), String>| -> Result { diff --git a/systems/footage/src/store.rs b/systems/footage/src/store.rs index 557f9065..ef9724fd 100644 --- a/systems/footage/src/store.rs +++ b/systems/footage/src/store.rs @@ -5,9 +5,7 @@ use std::path::Path; /// The default store: $RAEA_INGEST, else ~/.cache/raea-ingest. pub fn store() -> std::path::PathBuf { - std::env::var_os("RAEA_INGEST") - .map(std::path::PathBuf::from) - .unwrap_or_else(|| std::path::PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache/raea-ingest")) + raea_io_home::env_path("RAEA_INGEST", ".cache/raea-ingest") } pub fn content_hash(path: &Path) -> Result { diff --git a/systems/index/Cargo.toml b/systems/index/Cargo.toml index bf881b26..bc9bdfe0 100644 --- a/systems/index/Cargo.toml +++ b/systems/index/Cargo.toml @@ -8,6 +8,7 @@ description = "Index's fast pass (docs/index.feature IX1-IX3): every picture, an [dependencies] anyhow = "1" +dunce = "1" half = "2" rayon = "1" rusqlite = { version = "0.37", features = ["bundled"] } diff --git a/systems/index/src/apple.rs b/systems/index/src/apple.rs index 3a0769fb..8eb136a1 100644 --- a/systems/index/src/apple.rs +++ b/systems/index/src/apple.rs @@ -22,7 +22,7 @@ use objc2_image_io::{ kCGImageSourceCreateThumbnailFromImageIfAbsent, kCGImageSourceCreateThumbnailWithTransform, kCGImageSourceShouldCache, kCGImageSourceShouldCacheImmediately, kCGImageSourceThumbnailMaxPixelSize, }; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::ptr::NonNull; /// SigLIP 2 B/16-256's side @@ -135,7 +135,7 @@ impl Model { if !package.exists() { return Err(format!("{}: not installed", package.display())); } - let caches = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join("Library/Caches/raea-index"); + let caches = raea_io_home::user_home().unwrap_or_default().join("Library/Caches/raea-index"); std::fs::create_dir_all(&caches).map_err(|e| e.to_string())?; let name = package.file_stem().and_then(|s| s.to_str()).unwrap_or("model"); let compiled = caches.join(format!("{name}.mlmodelc")); diff --git a/systems/index/src/cli.rs b/systems/index/src/cli.rs index 0a4469af..0b4ea0ee 100644 --- a/systems/index/src/cli.rs +++ b/systems/index/src/cli.rs @@ -53,7 +53,7 @@ fn run(args: &[String]) -> Result<()> { "remove" => { let which = f.rest.first().ok_or_else(|| anyhow!("remove takes a source id or the folder"))?; let mut store = Store::open(&home)?; - let canon = std::fs::canonicalize(which).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| which.clone()); + let canon = dunce::canonicalize(which).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| which.clone()); let source = store.find(which)?.or(store.find(&canon)?).ok_or_else(|| anyhow!("no source {which}"))?; let n = store.remove(&source)?; println!("removed {source}: {n} items"); @@ -119,7 +119,7 @@ fn find(f: &Flags, home: &std::path::Path) -> Result<()> { let store = Store::open(home)?; let source = match &f.source { Some(s) => { - let canon = std::fs::canonicalize(s).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| s.clone()); + let canon = dunce::canonicalize(s).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| s.clone()); Some(store.find(s)?.or(store.find(&canon)?).ok_or_else(|| anyhow!("no source {s}"))?) } None => None, diff --git a/systems/index/src/lib.rs b/systems/index/src/lib.rs index 0b39813d..6f02b802 100644 --- a/systems/index/src/lib.rs +++ b/systems/index/src/lib.rs @@ -69,7 +69,7 @@ pub fn root_of(path: &str) -> Result { if path == PHOTOS { return Ok(PathBuf::from(PHOTOS)); } - let root = std::fs::canonicalize(path).map_err(|e| anyhow::anyhow!("{path}: {e}"))?; + let root = dunce::canonicalize(path).map_err(|e| anyhow::anyhow!("{path}: {e}"))?; anyhow::ensure!(root.is_dir(), "{path} isn't a folder"); Ok(root) } diff --git a/systems/index/src/serve.rs b/systems/index/src/serve.rs index 7621e61d..6959fdf6 100644 --- a/systems/index/src/serve.rs +++ b/systems/index/src/serve.rs @@ -154,7 +154,7 @@ fn answer(sh: &Shared, store: &mut Store, jobs: &mpsc::Sender, finds: & } "remove" => { let which = s("source").or_else(|| s("path")).ok_or_else(|| anyhow!("remove needs a source"))?; - let canon = std::fs::canonicalize(&which).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| which.clone()); + let canon = dunce::canonicalize(&which).map(|p| p.to_string_lossy().into_owned()).unwrap_or_else(|_| which.clone()); let Some(source) = store.find(&which)?.or(store.find(&canon)?) else { anyhow::bail!("no source {which}") }; let root: String = store.db.query_row("SELECT root FROM sources WHERE id = ?1", [&source], |r| r.get(0))?; sh.waiting.lock().unwrap().retain(|r| *r != root); diff --git a/systems/index/src/walk.rs b/systems/index/src/walk.rs index 04dc9e54..5b6aba04 100644 --- a/systems/index/src/walk.rs +++ b/systems/index/src/walk.rs @@ -54,7 +54,7 @@ pub fn cloud_only(_: &std::fs::Metadata) -> bool { /// Whether a file lives in iCloud Drive (a link is followed to where it lives): its cloud-only files go in from Quick /// Look's thumbnail (cloud.rs) without a download pub fn in_icloud(path: &Path) -> bool { - cfg!(target_os = "macos") && std::fs::canonicalize(path).is_ok_and(|p| p.to_string_lossy().contains("/Library/Mobile Documents/")) + cfg!(target_os = "macos") && dunce::canonicalize(path).is_ok_and(|p| p.to_string_lossy().contains("/Library/Mobile Documents/")) } /// Every picture and video under `root`, `on` called with each batch of `every` as they're found; says how many it diff --git a/systems/kimodo/Cargo.toml b/systems/kimodo/Cargo.toml index 438111db..29fc691a 100644 --- a/systems/kimodo/Cargo.toml +++ b/systems/kimodo/Cargo.toml @@ -17,3 +17,6 @@ raea-sys-mlx = { path = "../mlx" } raea-sys-ml = { path = "../ml" } mlx-rs = "=0.34.0" tokenizers = { version = "0.23", default-features = false, features = ["onig"] } + +[dev-dependencies] +raea-io-home = { path = "../../io/home" } diff --git a/systems/kimodo/src/tests.rs b/systems/kimodo/src/tests.rs index 14aca21d..302aa388 100644 --- a/systems/kimodo/src/tests.rs +++ b/systems/kimodo/src/tests.rs @@ -20,7 +20,7 @@ fn exact() { } fn cache() -> PathBuf { - PathBuf::from(std::env::var("HOME").unwrap()).join(".cache/raea-kimodo/mlx") + raea_io_home::user_home().unwrap().join(".cache/raea-kimodo/mlx") } fn fixture(name: &str) -> Option> { diff --git a/systems/ml/Cargo.toml b/systems/ml/Cargo.toml index e5ecedd7..c8c9ab5a 100644 --- a/systems/ml/Cargo.toml +++ b/systems/ml/Cargo.toml @@ -11,6 +11,7 @@ license = "FSL-1.1-ALv2" coreml = ["ort/coreml"] [dependencies] +dunce = "1" raea-io-home = { path = "../../io/home" } # the same ort pin and prebuilt runtime as the legacy app's voice and raea's perception ort = { version = "=2.0.0-rc.13", features = ["half"] } diff --git a/systems/ml/src/feed.rs b/systems/ml/src/feed.rs index d51b366b..88411131 100644 --- a/systems/ml/src/feed.rs +++ b/systems/ml/src/feed.rs @@ -34,7 +34,7 @@ pub fn cache() -> PathBuf { } fn user() -> PathBuf { - std::env::var_os("HOME").map(PathBuf::from).unwrap_or_else(|| PathBuf::from(".")) + raea_io_home::user_home().unwrap_or_else(|| PathBuf::from(".")) } fn made(dir: PathBuf) -> PathBuf { diff --git a/systems/ml/src/lib.rs b/systems/ml/src/lib.rs index 1342d0e1..37ad1cb5 100644 --- a/systems/ml/src/lib.rs +++ b/systems/ml/src/lib.rs @@ -380,7 +380,7 @@ fn sweep(r: &mut Registry) { /// The model at `file` with `options`: the session already loaded for them, or a new one. Each load is held until /// its `release`; a model nobody holds is freed after the idle limit. pub fn load(file: &Path, options: &Options) -> anyhow::Result> { - let file = file.canonicalize().with_context(|| format!("{}: no such model", file.display()))?; + let file = dunce::canonicalize(&file).with_context(|| format!("{}: no such model", file.display()))?; let key = (file.clone(), options.clone()); { let mut r = registry().lock().unwrap(); diff --git a/systems/page-net/Cargo.toml b/systems/page-net/Cargo.toml index 3e5465c3..617b0b46 100644 --- a/systems/page-net/Cargo.toml +++ b/systems/page-net/Cargo.toml @@ -10,6 +10,7 @@ description = "A page's loads: files beside it and under RAEA_PAGE_ROOT, data UR bevy = { version = "=0.20.0", default-features = false, features = ["std", "bevy_log"] } blitz-dom = { version = "=0.3.0-beta.4", default-features = false } blitz-traits = "=0.3.0-beta.4" +dunce = "1" raea-io-net = { path = "../../io/net" } raea-sys-image = { path = "../image" } serde_json = "1" diff --git a/systems/page-net/src/lib.rs b/systems/page-net/src/lib.rs index 2548d358..b39fa541 100644 --- a/systems/page-net/src/lib.rs +++ b/systems/page-net/src/lib.rs @@ -108,8 +108,8 @@ pub struct FrameNet { impl FrameNet { /// `path`, or its root-absolute form under a root, if it resolves inside that root pub fn confined(&self, path: &std::path::Path) -> Option { - self.roots.iter().filter_map(|r| r.canonicalize().ok()).find_map(|root| { - let at = |p: std::path::PathBuf| p.canonicalize().ok().filter(|c| c.starts_with(&root)); + self.roots.iter().filter_map(|r| dunce::canonicalize(&r).ok()).find_map(|root| { + let at = |p: std::path::PathBuf| dunce::canonicalize(&p).ok().filter(|c| c.starts_with(&root)); at(path.to_path_buf()).or_else(|| at(root.join(root_relative(path)?))) }) } diff --git a/systems/perceive/src/face_portable.rs b/systems/perceive/src/face_portable.rs index 4b079de7..39e28c55 100644 --- a/systems/perceive/src/face_portable.rs +++ b/systems/perceive/src/face_portable.rs @@ -14,7 +14,7 @@ const MODEL: (&str, &str) = ( const SIDE: usize = 640; fn model() -> Result { - let dir = PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(".cache/raea/yunet"); + let dir = raea_io_home::user_home().unwrap_or_default().join(".cache/raea/yunet"); let p = dir.join(MODEL.0); if !p.exists() { std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; diff --git a/systems/perceive/src/ocr_portable.rs b/systems/perceive/src/ocr_portable.rs index 40acd06b..766b60ac 100644 --- a/systems/perceive/src/ocr_portable.rs +++ b/systems/perceive/src/ocr_portable.rs @@ -11,7 +11,7 @@ const MODELS: [(&str, &str); 2] = [ ]; fn model(name: &str, url: &str) -> Result { - let dir = PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(".cache/raea/ocrs"); + let dir = raea_io_home::user_home().unwrap_or_default().join(".cache/raea/ocrs"); let p = dir.join(name); if !p.exists() { std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; diff --git a/systems/perceive/src/portable.rs b/systems/perceive/src/portable.rs index da2c82da..cdc88931 100644 --- a/systems/perceive/src/portable.rs +++ b/systems/perceive/src/portable.rs @@ -25,7 +25,7 @@ const MOBILENET: (&str, &str, &str) = ( ); pub fn fetch((dir, name, url): (&str, &str, &str)) -> Result { - let dir = PathBuf::from(std::env::var_os("HOME").unwrap_or_default()).join(".cache/raea").join(dir); + let dir = raea_io_home::user_home().unwrap_or_default().join(".cache/raea").join(dir); let p = dir.join(name); if !p.exists() { std::fs::create_dir_all(&dir).map_err(|e| e.to_string())?; diff --git a/systems/song/src/onnx.rs b/systems/song/src/onnx.rs index a247c6e1..14e18b3c 100644 --- a/systems/song/src/onnx.rs +++ b/systems/song/src/onnx.rs @@ -31,7 +31,7 @@ pub fn session(name: &str, path: impl AsRef) -> ort::Result ort::Result { use ort::ep::coreml::{ComputeUnits, CoreML, ModelFormat}; - let cache = std::path::PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".cache/raea-coreml"); + let cache = raea_io_home::user_home().unwrap_or_default().join(".cache/raea-coreml"); let _ = std::fs::create_dir_all(&cache); Ok(b.with_execution_providers([CoreML::default() .with_compute_units(ComputeUnits::CPUAndNeuralEngine) diff --git a/systems/speech/Cargo.toml b/systems/speech/Cargo.toml index a6dca07c..837464c1 100644 --- a/systems/speech/Cargo.toml +++ b/systems/speech/Cargo.toml @@ -7,6 +7,7 @@ description = "Speech on raea's ONNX facility: Pocket TTS streamed sentence by s license = "FSL-1.1-ALv2" [dependencies] +raea-io-home = { path = "../../io/home" } raea-sys-ml = { path = "../ml" } ort = { version = "=2.0.0-rc.13", features = ["half"] } anyhow = "1" diff --git a/systems/speech/src/speech.rs b/systems/speech/src/speech.rs index b4cda272..c18c2658 100644 --- a/systems/speech/src/speech.rs +++ b/systems/speech/src/speech.rs @@ -133,7 +133,7 @@ fn cache_dir() -> PathBuf { if let Some(p) = std::env::var_os("RAEA_SPEECH_CACHE") { return PathBuf::from(p); } - std::env::var_os("HOME").map(PathBuf::from).unwrap_or_else(|| PathBuf::from(".")).join(".cache/raea-speech") + raea_io_home::user_home().unwrap_or_else(|| PathBuf::from(".")).join(".cache/raea-speech") } impl Service { diff --git a/systems/vision/Cargo.toml b/systems/vision/Cargo.toml index 09518df4..5e53272d 100644 --- a/systems/vision/Cargo.toml +++ b/systems/vision/Cargo.toml @@ -7,6 +7,7 @@ publish = false description = "Apple Vision and Core ML models on frames: faces, hands, hair, depth, objects, flow, text, the camera's move, sound classes" [dependencies] +raea-io-home = { path = "../../io/home" } # frames come from the media plane (VideoToolbox on Apple, ffmpeg or the software decoders elsewhere) raea-io-media = { path = "../../io/media", default-features = false, features = ["apple"] } raea-sys-layout = { path = "../layout" } diff --git a/systems/vision/src/coreml.rs b/systems/vision/src/coreml.rs index d3f46f15..33ef193c 100644 --- a/systems/vision/src/coreml.rs +++ b/systems/vision/src/coreml.rs @@ -44,11 +44,9 @@ impl Model { } } -/// The models folder: $RAEA_MODELS, else ~/.local/share/raea-models. +/// The models folder: $RAEA_MODELS, else raea's (raea_io_home::models: ~/.local/share/raea-models on the Mac). pub fn models_dir() -> PathBuf { - std::env::var_os("RAEA_MODELS") - .map(PathBuf::from) - .unwrap_or_else(|| PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".local/share/raea-models")) + std::env::var_os("RAEA_MODELS").filter(|v| !v.is_empty()).map(PathBuf::from).unwrap_or_else(raea_io_home::models) } fn modified(p: &Path) -> std::time::SystemTime { @@ -75,7 +73,7 @@ impl Model { if !package.exists() { return Err(format!("{}: not installed", package.display())); } - let caches = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join("Library/Caches/raea-perception"); + let caches = raea_io_home::user_home().unwrap_or_default().join("Library/Caches/raea-perception"); std::fs::create_dir_all(&caches).map_err(|e| e.to_string())?; let compiled = caches.join(format!("{name}.mlmodelc")); if !compiled.exists() || modified(&compiled) < modified(&package) { diff --git a/tools/dupes.max b/tools/dupes.max index 96bd92b6..2d34224b 100644 --- a/tools/dupes.max +++ b/tools/dupes.max @@ -19,5 +19,5 @@ # io/capcut store.rs:67 (tasklist's stdout, lower-cased; sdk/ui/parity main.rs:88 trims a command's stdout), # io/capcut build.rs:24 parse (serde_json::from_str + expect; engine/native node.rs:172 js_string, to_string), and # apps/capcut plan.rs:67 (a box moved more than 1 px; systems/layout mod.rs:406, within 1.5 px) -exact=292 -near=59 +exact=289 +near=58 diff --git a/tools/skills.sh b/tools/skills.sh index fd849a53..ae9422ce 100755 --- a/tools/skills.sh +++ b/tools/skills.sh @@ -196,7 +196,8 @@ gen_files() { my ($f, $text) = /^([^:]+):\d+:(.*)$/ or next; while ($text =~ m{(?