Skip to main content

Module fsutil

Module fsutil 

Source
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§

TempPathGuard
RAII guard that unlinks a temp path unless disarm is called. Used to prevent orphan .tmp files when an intermediate step between File::create and rename fails.

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 path as a &str, suitable for path = %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() and read()), and the read itself uses Read::take so 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 bytes to path via create-tmp + fsync + rename + parent fsync.