lock

package
v0.260514.4 Latest Latest
Warning

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

Go to latest
Published: May 17, 2026 License: MPL-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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