Documentation
¶
Overview ¶
Package atomicfile writes private files without ever leaving a half-written one behind.
Both the config file and the fallback credentials file are rewritten in full on every change. A crash or a full disk part-way through a plain os.WriteFile would truncate the user's projects; writing to a temporary file in the same directory and renaming it over the target makes the swap atomic, so a reader sees either the old file or the new one.
Index ¶
Constants ¶
const ( FileMode = 0o600 DirMode = 0o700 )
File and directory modes. Both files hold credentials or credential-adjacent data, so they are owner-only.
const TempPrefix = ".tmp-"
TempPrefix is what the temporary file is called before the rename. It is exported because a crash between the two leaves one behind, and a caller cleaning up after itself has to be able to recognise its own litter — which it cannot do from a prefix spelled out twice and free to drift.
Variables ¶
var ErrNotPrivate = errors.New("file is readable by users other than its owner")
ErrNotPrivate reports a file that others can read. It is advisory: fft warns rather than refuses, because the user may have good reasons and a CLI that bricks itself over a permission bit is worse than one that complains.
Functions ¶
func CheckPrivate ¶
CheckPrivate reports ErrNotPrivate if path is group- or world-accessible. A missing file is fine — there is nothing to leak.
func Write ¶
Write creates path's parent directory if needed and replaces path with data, atomically. The file ends up mode 0600 and the directory mode 0700.
func WriteMode ¶ added in v0.2.0
WriteMode is Write with the modes spelled out, for the files that are not secrets.
The installed agent skill is documentation: it belongs to the user, other tools may want to read it, and 0600 would be a claim about it that is not true. What it does want is the rest of Write — a SKILL.md truncated by a full disk is a skill that lies to an agent, which is worse than one that is absent.
Types ¶
This section is empty.