Expand description
Private filesystem helpers for sensitive application state.
Policy (spec §5.4): directories 0700, files and temp files 0600,
symlink-safe opens, and atomic create-with-mode → write → rename so no
interval exists where a fresh file is broader than policy. Pre-existing
broader modes are repaired (chmod) on the next write. On non-Unix
platforms the helpers fall back to default platform semantics (symlink
refusal is still enforced via symlink_metadata).
Structs§
- Confined
Dir - A held
O_DIRECTORYhandle beneath a trusted root. Every operation is RELATIVE to this handle (openat/mkdirat/unlinkat), each component is openedO_NOFOLLOW, and no path is ever re-resolved after a check — the check IS the open, so ancestor-symlink plants and concurrent component swaps fail closed (ELOOP/ENOTDIR) instead of escaping. - Confined
Entry - One entry discovered from a held directory handle. Discovery never re-resolves the directory by path; callers still perform the authoritative open relative to the same handle, so entry replacement races fail closed.
Enums§
- Private
FsError - Typed failure for private filesystem operations.
Constants§
- DIR_
MODE - Policy mode for private directories (Unix).
- FILE_
MODE - Policy mode for private files and temp files (Unix).
Functions§
- ensure_
private_ dir - Create
dir(and missing parents) with mode0700, and repair the leaf directory to0700if a pre-existing one is broader than policy. - open_
private_ append - Open
pathfor appending, creating it with mode0600(O_NOFOLLOWon Unix). A symlink at the target yieldsPrivateFsError::SymlinkRefused. A pre-existing broader-mode file is repaired to0600viafchmodon the already-open handle (no path re-resolution). - validated_
relative_ components - Split and validate a RELATIVE multi-component path (
a/b/c.jsonl). Rejects absolute paths,./.., empty components, and backslashes. - write_
atomic_ private - Atomically replace
pathwithdata: the temp file is created in the same directory withcreate_new+ mode0600(never create-then-chmod, so no interval is broader than policy), written, then renamed over the target. A symlink at the target or temp path yields a typed refusal.