filelock

package
v0.0.0-...-b10fd3f Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2025 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Package filelock provides thread-safe file locking functionality in non-blocking mode. It allows for acquiring exclusive locks on files without blocking indefinitely.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrTimeout is returned when a lock operation times out
	ErrTimeout = errors.New("timeout acquiring lock")

	// ErrLockHeld is returned when a non-blocking lock operation fails because the lock is held
	ErrLockHeld = errors.New("lock is held by another process")

	// ErrAlreadyLocked is returned when trying to lock a file that
	// is already locked by this process
	ErrAlreadyLocked = errors.New("file is already locked by this process")

	// ErrNotLocked is returned when trying to unlock a file that is not locked
	ErrNotLocked = errors.New("file is not locked")
)

Functions

This section is empty.

Types

type FileLock

type FileLock interface {
	// Lock attempts to acquire an exclusive lock on the file.
	// Returns ErrLockHeld if the lock is already held by another process.
	Lock() error

	// LockWithTimeout attempts to acquire an exclusive lock on the file with a timeout.
	// If timeout is <= 0, it's a non-blocking operation.
	LockWithTimeout(timeout time.Duration) error

	// Unlock releases the lock on the file.
	// Returns ErrNotLocked if the file is not locked.
	Unlock() error

	// IsLocked returns true if the file is currently locked by this process.
	IsLocked() bool

	// Path returns the path to the locked file.
	Path() string
}

FileLock defines a common interface for file locking mechanisms.

Directories

Path Synopsis
Package unix provides thread-safe file locking functionality in non-blocking mode.
Package unix provides thread-safe file locking functionality in non-blocking mode.
Package filelock provides thread-safe file locking functionality in non-blocking mode.
Package filelock provides thread-safe file locking functionality in non-blocking mode.

Jump to

Keyboard shortcuts

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