fileutil

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWrite

func AtomicWrite(path string, data []byte) error

AtomicWrite writes data to path atomically using a temp file in the same directory followed by a rename. This ensures that a crash mid-write leaves the existing file intact. If the target file already exists, its permissions are preserved; otherwise 0644 is used.

func AtomicWriteWithPerm

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

AtomicWriteWithPerm writes data to path atomically using a temp file in the same directory followed by a rename. The perm parameter is the fallback permission used when the target file does not yet exist. If the target file already exists, its current permissions are preserved (H-19).

func DirOf added in v1.4.0

func DirOf(path string) string

DirOf returns the directory component of path, similar to filepath.Dir but optimized for simple path strings without calling filepath.Dir.

Types

type FileLock added in v1.3.0

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

FileLock provides advisory file locking using flock(2). Used to prevent concurrent M31A instances from corrupting shared session files in the same project directory.

func NewFileLock added in v1.3.0

func NewFileLock(path string) *FileLock

NewFileLock creates a FileLock for the given path. The lock file is created on Lock() if it doesn't exist.

func (*FileLock) Lock added in v1.3.0

func (fl *FileLock) Lock() error

Lock acquires an exclusive lock on the file. Blocks until the lock is available. Returns an error if the file cannot be opened.

func (*FileLock) TryLock added in v1.3.0

func (fl *FileLock) TryLock() (bool, error)

TryLock attempts to acquire an exclusive lock without blocking. Returns false if the lock is already held by another process.

func (*FileLock) Unlock added in v1.3.0

func (fl *FileLock) Unlock() error

Unlock releases the lock and closes the file.

Jump to

Keyboard shortcuts

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