fsutil

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Overview

Package fsutil holds small filesystem helpers shared across the agent and server. AtomicWriteFile is the durable temp-file → rename pattern that the agent's config writer and both config savers previously each reimplemented (#225), now in one place that also fsyncs the parent directory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile

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

AtomicWriteFile writes data to path atomically and durably. It creates a temp file in the same directory, fsyncs the file, chmods it to perm, renames it over the target, then fsyncs the parent directory so the rename itself survives a crash.

The trailing directory fsync is the crash-safety fix: on Linux/Unix the rename is not durable until the directory entry is flushed, so after power loss the target file could revert to its old content — or, for a first-time write, disappear — even though Write, Sync, and Rename all reported success (#225). The directory sync is best-effort (some filesystems and platforms do not support it) and runs only after the rename has succeeded, so a failure there is logged rather than returned: failing here would be misleading when the new data is already in place.

func SyncDir added in v0.9.0

func SyncDir(dir string)

SyncDir flushes the directory entry so a prior create, rename, or link in dir is durable. Best-effort: directory fsync is unsupported on some platforms and filesystems (on Windows os.File.Sync on a directory returns "Access is denied"), so errors are logged at warn level rather than propagated — by the time it runs the rename/link has already succeeded and the data is in place.

Types

This section is empty.

Jump to

Keyboard shortcuts

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