Expand description
Filesystem and path utilities (base dir, path-component safety, atomic write). Filesystem and path utilities shared across the engine.
These primitives back both the engine config file and credential storage: resolving the per-user base directory, validating untrusted path components, and writing files atomically with restrictive permissions. They are domain-agnostic so callers that persist their own files can reuse them rather than re-implementing the same path safety and atomic-write logic.
Functions§
- config_
base_ dir - Resolves the per-user base directory for an app’s config and data files.
- home_
dir - Returns the user’s home directory.
- is_
safe_ path_ component - Returns true only when
sis a single, non-traversal path component that is valid on all supported platforms. - write_
string_ atomic - Writes
contentstopathvia a uniquely-named temp file then renames it into place. On Unix the rename is atomic, the file is created0600, and newly-created parent directories are best-effort restricted to0700. Pre-existing parent directories are left unchanged so callers that write into established locations (e.g.$HOME) do not alter their permissions. On Windows the rename replaces an existing destination but is not crash-atomic.