atomicio

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package atomicio writes a file atomically (temp + rename) and keeps a single rollback backup. It is the shared swap discipline used for the cached abuse.ch feed snapshots (and is the same temp+rename pattern the rules cache uses), so a concurrent reader never sees a half-written file and a bad write can roll back.

Index

Constants

View Source
const BackupSuffix = ".bak"

BackupSuffix is appended to keep exactly one previous copy.

Variables

This section is empty.

Functions

func ReadCached

func ReadCached(path string) ([]byte, bool)

ReadCached reads path, returning the bytes and true when a non-empty file exists, or (nil, false) otherwise — the warm-start read for a cached feed.

func WriteWithBackup

func WriteWithBackup(path string, data []byte, perm os.FileMode) (err error)

WriteWithBackup writes data to path atomically: it writes a temp file in the same directory, fsyncs it, backs up any existing file to path+".bak", then renames the temp file into place (same-filesystem rename is atomic). The parent directory is created if missing. On any error the original file is left untouched.

Types

This section is empty.

Jump to

Keyboard shortcuts

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