fileutil

package
v1.0.238 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: MIT Imports: 7 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 fileutil provides durable filesystem helpers shared by package main and internal/* packages (ADR-0003). It has no dependency on the rest of Culvert (stdlib only).

Index

Constants

This section is empty.

Variables

View Source
var ErrReplacedNotSynced = errors.New("atomic write: target replaced but parent directory not synced")

ErrReplacedNotSynced marks an AtomicWrite failure that occurred AFTER the rename: the target file already carries the new content (visible to every reader, and on the overwhelming majority of filesystems durable), but the parent-directory sync failed, so the rename's durability across an immediate crash is not guaranteed. Callers running compensating rollbacks must NOT restore prior in-memory state on this error — memory would then contradict the visible file, and a restart would load the "rolled back" content anyway. Test with errors.Is.

Functions

func AtomicWrite

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

AtomicWrite writes data to path atomically: it writes to a unique temp file in the same directory, chmods, fsyncs the file, renames over the target, and best-effort fsyncs the parent directory. A crash mid-write never leaves a partial or corrupt target file. Moved verbatim from package main's atomicWriteFile (ADR-0003); behaviour is unchanged.

Every failure branch additionally notifies the write-failure observer (CHAOS-45) so error-discarding callers cannot fail silently.

func SetWriteFailureObserver added in v1.0.175

func SetWriteFailureObserver(fn func(path string, err error))

SetWriteFailureObserver publishes the durable-write failure observer. Published once at startup by package main. A nil fn clears the observer, which is what tests use to restore the default no-op state.

func SetWriteSuccessObserver added in v1.0.175

func SetWriteSuccessObserver(fn func(path string))

SetWriteSuccessObserver publishes the durable-write success observer. Nil clears it. See writeOKObserver for why successes are observed at all.

Types

type RotatingFile added in v1.0.16

type RotatingFile struct {
	// contains filtered or unexported fields
}

RotatingFile wraps a log file and rotates it when it exceeds maxBytes.

func NewRotatingFile added in v1.0.16

func NewRotatingFile(path string, maxMB int) (*RotatingFile, error)

NewRotatingFile opens path for append and returns a writer that rotates the file to path+".1" when it exceeds maxMB (<=0 falls back to 50 MB).

func (*RotatingFile) Close added in v1.0.16

func (r *RotatingFile) Close() error

Close closes the underlying file.

func (*RotatingFile) Write added in v1.0.16

func (r *RotatingFile) Write(p []byte) (int, error)

Write appends p, rotating first when the size cap would be exceeded.

Jump to

Keyboard shortcuts

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