fsutil

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package fsutil provides crash-safe atomic file writes for sensitive on-disk state (keys, sessions, config). A write either lands in full or not at all, so a crash or full disk never leaves a partial file behind.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteFileAtomic

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

WriteFileAtomic writes data to path atomically, replacing any existing file. It writes a temp file in the same directory, fsyncs it, and renames it over path. The parent directory is created with 0700 if absent.

func WriteFileExclusive

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

WriteFileExclusive writes data to path atomically but fails with os.ErrExist if path already exists. Like WriteFileAtomic it never leaves a partial file; it hard-links the fully written temp file into place, so the create-or-fail decision is atomic against concurrent writers. Callers can match the already-exists case with errors.Is(err, os.ErrExist).

Types

This section is empty.

Jump to

Keyboard shortcuts

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