fsatomic

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package fsatomic implements the single durable-write primitive required by §3.1: every durable write in PayCLI goes through Write.

The sequence is: create a temp file in the *same* directory as the target (so the rename cannot cross a filesystem boundary) named "<base>.<pid>.<rand6>.tmp" -> write -> fsync the file -> chmod to the requested mode -> close -> rename over the target -> fsync the directory.

The explicit chmod matters: O_CREATE applies the process umask, so a file created with 0600 under umask 077 is fine but under an exotic umask could be created 0400 and later reads would fail. Chmod after the write pins the mode exactly, which is what §5.2's 0600 credentials.json depends on.

Index

Constants

View Source
const DirPerm fs.FileMode = 0o700

DirPerm is the mode used for parent directories created by Write. 0700 because PayCLI's state directories hold credentials (§5.2).

Variables

This section is empty.

Functions

func Write

func Write(path string, data []byte, perm fs.FileMode) error

Write atomically replaces path with data, leaving the file mode at perm.

The parent directory is created with DirPerm when it does not exist, so callers never need a separate MkdirAll step. A reader of path always observes either the previous contents or the complete new contents, never a prefix.

func WriteFrom

func WriteFrom(path string, r io.Reader, perm fs.FileMode) error

WriteFrom is Write for a streaming source (used by downloads, §13).

Types

This section is empty.

Jump to

Keyboard shortcuts

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