Documentation
¶
Overview ¶
Package fileutil holds small file-system primitives shared across cc-fleet.
AtomicWrite is the single place that implements the create-tempfile + chmod + write + close + rename + cleanup discipline used by config / models / profile / fingerprint / secrets / spawn / userops for every 0o600 metadata or secret file, so a future hardening only changes one implementation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicWrite ¶
AtomicWrite writes data to path via a SAME-DIRECTORY temp file + rename at mode. The parent directory must already exist — this helper deliberately does not mkdir so callers keep control of the directory mode.
Discipline:
- CreateTemp in filepath.Dir(path) so the rename stays within one filesystem (atomic at the kernel level).
- Chmod the temp to exactly mode regardless of umask. CreateTemp's 0600-before-umask is not enough.
- Write data, Close, Rename. Any failure jumps to cleanup.
- Defer os.Remove on the temp path so a failure before rename never leaves an orphan; after a successful rename the temp name no longer exists, so the deferred Remove no-ops.
A partial/failed write therefore never truncates an existing file at path — the old file stays intact until os.Rename swaps in the fully-written replacement in one step. This matters for in-place secret rotation: the previous key stays usable rather than clobbered.
The error wraps a short stage tag + path + the underlying error, never data.
Types ¶
This section is empty.