lock

package
v0.260224.1130 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: MPL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileLock

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

FileLock manages exclusive file locking for single-instance enforcement. The lock is automatically released when the process dies, even if it crashes. It also stores the current process PID for signal-based shutdown.

func NewFileLock

func NewFileLock(configDir string) *FileLock

NewFileLock creates a new file lock instance. The lock file will be created in the specified config directory.

func (*FileLock) GetLockFilePath

func (fl *FileLock) GetLockFilePath() string

GetLockFilePath returns the lock file path for debugging purposes.

func (*FileLock) GetPID

func (fl *FileLock) GetPID() (int, error)

GetPID returns the PID stored in the lock file. Returns error if the lock file doesn't exist or contains invalid data.

func (*FileLock) IsLocked

func (fl *FileLock) IsLocked() bool

IsLocked checks if the lock is currently held by another process. Returns false if the lock is available or if this process holds it.

func (*FileLock) TryLock

func (fl *FileLock) TryLock() error

TryLock attempts to acquire the file lock. Returns an error if the lock is already held by another process. The lock file remains on disk but is unlocked when this process dies. On success, stores the current process PID in the lock file for shutdown signals.

func (*FileLock) Unlock

func (fl *FileLock) Unlock() error

Unlock releases the file lock. Safe to call multiple times; subsequent calls are no-ops.

Jump to

Keyboard shortcuts

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