atomicfile

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 4 Imported by: 0

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

View Source
const (
	FileMode = 0o600
	DirMode  = 0o700
)

File and directory modes. Both files hold credentials or credential-adjacent data, so they are owner-only.

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

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

func CheckPrivate(path string) error

CheckPrivate reports ErrNotPrivate if path is group- or world-accessible. A missing file is fine — there is nothing to leak.

func Write

func Write(path string, data []byte) error

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

func WriteMode(path string, data []byte, file, dir os.FileMode) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL