atomicfile

package
v0.1.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 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.

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.

Types

This section is empty.

Jump to

Keyboard shortcuts

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