fsutil

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Overview

Package fsutil holds small filesystem helpers shared across commands.

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = errors.New("directory is in use by another process")

ErrLocked means another process holds the directory's lock.

Functions

func ExistingPerm

func ExistingPerm(path string, def fs.FileMode) fs.FileMode

ExistingPerm returns path's permission bits, or def when it cannot be stat'd. Use with WriteAtomic to keep an existing file's mode.

func OpenJSONL

func OpenJSONL(path string, replay func([]byte)) (*os.File, error)

OpenJSONL replays the append-only log at path line by line into replay, then returns it open for appending. A torn trailing line (crash mid-write) is handed to replay like any other (callers skip lines that don't decode) and then terminated with '\n', so the next record starts on its own line instead of being glued onto — and lost with — the torn one.

func RestrictToOwner

func RestrictToOwner(string) error

RestrictToOwner is a no-op here: the 0600 mode the caller creates files with already is owner-only. (Windows replaces the DACL.)

func SyncDir added in v0.3.0

func SyncDir(dir string) error

SyncDir fsyncs dir so a rename or create inside it survives a crash.

func VerifyPrivate

func VerifyPrivate(path string) error

VerifyPrivate reports whether group and other have no access to path.

func WriteAtomic

func WriteAtomic(path string, data []byte, perm fs.FileMode) (err error)

WriteAtomic writes data to path so a reader sees either the old or the new content, never a partial file: temp file in the same directory, fsync, chmod perm, rename, fsync the directory. The directory must exist.

Types

type DirLock added in v0.5.0

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

DirLock is an exclusive advisory lock on a directory, held through a file in it for as long as the process lives or until Close. The operating system drops it when the process dies, so a crash never leaves a stale lock.

func LockDir added in v0.5.0

func LockDir(dir string) (*DirLock, error)

LockDir takes the exclusive lock on dir (created if absent) via dir/.lock, without waiting. It returns an error wrapping ErrLocked if another process (or another LockDir in this one) holds it.

func (*DirLock) Close added in v0.5.0

func (l *DirLock) Close() error

Close releases the lock. It is safe to call twice.

Jump to

Keyboard shortcuts

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