Expand description
Cross-platform filesystem helpers.
sync_directory durably persists directory entries on platforms where the
operating system supports it (Unix fsync on a directory file descriptor).
On Windows there is no supported way to flush a directory handle
(FlushFileBuffers requires a file, and opening a directory for File::open
yields PermissionDenied), so this is a no-op there. These helpers do not
establish an equivalent power-loss durability guarantee on Windows.
Structs§
- Temp
Path Guard - RAII guard that unlinks a temp path unless
disarmis called. Used to prevent orphan.tmpfiles when an intermediate step betweenFile::createandrenamefails.
Constants§
- MAX_
ATIF_ BYTES - ATIF trajectories can carry long transcripts; 64 MiB is generous (a 200k-token GPT-4 context in ASCII fits in ~800 KiB).
- MAX_
CONTROL_ BYTES - Small-file caps for control-plane files (config sidecars, journal metadata, marker files, ack files). 1 MiB is well above any real legitimate content but small enough that a hostile plant cannot materialize an OOM before the parser complains.
- MAX_
RECEIPT_ BYTES - Receipts JCS-canonicalize to a few hundred bytes; even a huge
tool-call summary stays well under 16 MiB. Shared between the CLI
(
avctl receipt-verify) and the harness reconciler.
Functions§
- basename
- Return just the file name of
pathas a&str, suitable forpath = %basename(&path)in tracing macros. - create_
dir_ all_ synced - Create
pathand any missing ancestors, then confirm every parent entry in the resolved directory hierarchy with fsync. Existing directories need the same confirmation: they can remain visible after an earlier failed synchronization or a concurrent creator that has not synchronized yet. An empty path is a no-op. Symbolic links are resolved before synchronizing so the actual target hierarchy is confirmed, including relative paths. - read_
capped - Read a file into memory subject to a hard byte cap, refusing
non-regular files. The size check runs on the OPEN handle (not
the path — closes the TOCTOU race where a symlink target is
swapped between
metadata()andread()), and the read itself usesRead::takeso a target that grows after the metadata check still cannot exceed the cap. - read_
capped_ string - UTF-8 variant of
read_capped. Used by the CLI for operator-supplied config / manifest / bearer token files where content is textual. - sweep_
orphaned_ tmp - Remove crash-orphaned
*.tmpfiles underroot, recursively. - sync_
directory - Fsync a directory so its rename/create entries are durable after a crash.
- sync_
directory_ ancestors - Confirm the parent entries of an existing directory without creating it.
This includes every ancestor of the resolved target, highest parent first.
The directory itself is not synchronized; callers persisting its contents
must also call
sync_directory(path). Missing or non-directory paths fail. - unix_
o_ nofollow - POSIX
O_NOFOLLOWopen-flag value for the target platform. Used alongsidestd::os::unix::fs::OpenOptionsExt::custom_flagsto refuse to follow a symlink at the file path being opened — closes the symlink-plant confused-deputy class where a co-tenant with write access to a spool directory pre-plants a symlink at a deterministic file path so the harness’s authenticated append (running as the harness UID) is redirected to a file the attacker can then read or overwrite. - unix_
o_ nonblock O_NONBLOCKforOpenOptions::custom_flags. Opening a FIFO read-only WITHOUT this flag blocks until a writer appears — a pre-planted FIFO (swapped in after any pathname precheck; pathname checks cannot close that race) would hang the caller forever before the post-open handle check could refuse it. With the flag, the open returns immediately and the handle check sees a non-regular file. Regular files ignoreO_NONBLOCKentirely, so the flag is free on the happy path. Same per-arch caution asunix_o_nofollowabove: Linux asm-generic uses 0o4000; the PowerPC layout swaps it; BSD/macOS use 0x4.- write_
atomic - Durably write
bytestopathvia create-tmp + fsync + rename + parent fsync.