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 — NTFS journals
metadata changes so a rename is durable once the containing file has been
sync_all’d.
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 (round-17 F3).
Functions§
- basename
- Round-36 F1: return just the file name of
pathas a&str, suitable forpath = %basename(&path)in tracing macros. - 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 (round-17 F6). - sync_
directory - Fsync a directory so its rename/create entries are durable after a crash.
- write_
atomic - Durably write
bytestopathvia create-tmp + fsync + rename + parent fsync.