atomicfile

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package atomicfile writes a file so that a crash or a power cut can never leave a half-written one behind. The daemon's state and settings both live in a single JSON file that is rewritten in full, so a torn write there costs the whole torrent list.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadWithBackup

func ReadWithBackup(path string, parse func([]byte) error) (ok, fromBackup bool, err error)

ReadWithBackup reads path, falling back to "<path>.bak" when the main file is missing or parse reports it unusable. ok tells whether anything was read at all; fromBackup says the backup had to be used, which the caller may want to mention in its log.

func Write

func Write(path string, data []byte, perm os.FileMode, keepBackup bool) error

Write replaces path with data. The new content is flushed to the disk before the old file is replaced, so an interrupted write leaves either the previous file or the new one, never a truncated mix of the two. When keepBackup is set the file being replaced is kept as "<path>.bak", which ReadWithBackup falls back to.

Types

This section is empty.

Jump to

Keyboard shortcuts

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