lockfile

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LockFile

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

LockFile represents an exclusive file lock.

func ForSubscribe

func ForSubscribe(appID string) (*LockFile, error)

ForSubscribe returns a LockFile scoped to the event subscribe command for a given App ID. Lock path: {configDir}/locks/subscribe_{appID}.lock

The appID is sanitized to prevent path traversal: any character outside [a-zA-Z0-9._-] is replaced with "_", and filepath.Base strips directory components, so a malicious appID like "../../tmp/evil" becomes a flat filename under the locks directory.

func New

func New(path string) *LockFile

New creates a LockFile for the given path (does not acquire the lock).

func (*LockFile) Path

func (l *LockFile) Path() string

Path returns the lock file path.

func (*LockFile) TryLock

func (l *LockFile) TryLock() error

TryLock attempts to acquire an exclusive, non-blocking lock. Returns nil on success. Returns an error if the lock is already held by another process (or on any other failure). The lock is automatically released when the process exits.

func (*LockFile) Unlock

func (l *LockFile) Unlock() error

Unlock releases the lock and closes the file descriptor. The lock file is intentionally kept on disk to avoid an inode-reuse race: removing the path between unlock and a competing open+flock would let two processes lock different inodes under the same name.

Jump to

Keyboard shortcuts

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