Skip to main content

default_data_dir

Function default_data_dir 

Source
pub fn default_data_dir() -> PathBuf
Expand description

Resolve ~/.trusty-code, creating it at mode 0700 and tightening it if a previous run left it permissive.

Why: mirrors trusty-mpm’s ~/.trusty-mpm precedent (crates/trusty-mpm/src/core/paths.rs) rather than inventing a new resolution convention. #5426 moved the resolution itself into crate::paths::private_state, which also owns the 0700 mode this directory must carry — a workstream store sitting beside transcripts and logs is private state, not an independent location. #6999: this function is the ONE place every private-state writer resolves that root — the workstream store, serve’s router, and agent_loop::telemetry’s own default_data_dir all end here — so the mode guarantee is applied here rather than at each writer’s own create_dir_all, which would apply the process umask and leave 0755. Applying it anywhere else would be a second copy of the rule. What: delegates to crate::paths::private_state::ensure_private_state_dir: dirs::home_dir()/.trusty-code, created if missing and chmod’d to 0700 if any group or other bit is set. On an I/O failure it falls back to the plain crate::paths::private_state::private_state_dir path, logging at warn — a harness that cannot create its state directory should still report what it tried, not panic. Never panics. Test: path_tests::default_data_dir_is_dot_trusty_code, path_tests::ensure_or_report_creates_and_tightens_a_permissive_dir, tests/cli_e2e.rs::a_non_import_command_tightens_a_permissive_private_state_dir, paths::private_state::private_state_tests::private_state_dir_matches_home_when_available.