lockfile

package
v0.0.0-...-7426b64 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LockFile

func LockFile(f *os.File) error

LockFile tries to acquire a read lock on the file f

func LockRelease

func LockRelease(f *os.File) error

func PidExists

func PidExists(pid int) bool

PidExists checks if a process with the given PID exists and is running

Types

type AlreadyLockedError

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

AlreadyLockedError manages info that clarifies why a lock has failed, but is still likely valid.

func NewAlreadyLockedError

func NewAlreadyLockedError(err error, file, msg string) *AlreadyLockedError

NewAlreadyLockedError returns a new AlreadyLockedError.

func (*AlreadyLockedError) Error

func (e *AlreadyLockedError) Error() string

Error implements the error interface.

func (*AlreadyLockedError) Stack

Stack implements the errs.WrapperError interface.

func (*AlreadyLockedError) Unwrap

func (e *AlreadyLockedError) Unwrap() error

Unwrap allows the unwrapping of a causing error.

type PidLock

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

PidLock represents a lock file that can be used for exclusive access to resources that should be accessed by only one process at a time.

The characteristics of the lock are: - Lockfiles are removed after use - Even if the lockfiles are not removed (because a process has been terminated prematurely), it is unlocked - On file-systems that support advisory locks via fcntl or LockFileEx, all file system operations are atomic

Notes: - The implementation currently does not support a blocking wait operation that returns once the lock can be acquired. If required, it can be extended this way. - Storing the PID inside the lockfile was initially intended to be fall-back mechanism for file systems that do not support locking files. This is probably unnecessary, but could be extended to communicate with the process currently holding the lock via its PID.

func NewPidLock

func NewPidLock(path string) (pl *PidLock, err error)

NewPidLock creates a new PidLock that can be used to get exclusive access to resources between processes

func (*PidLock) Close

func (pl *PidLock) Close(keepFile ...bool) error

Close removes the lock file and releases the lock

func (*PidLock) TryLock

func (pl *PidLock) TryLock() (err error)

TryLock attempts to lock the created lock file.

func (*PidLock) WaitForLock

func (pl *PidLock) WaitForLock(timeout time.Duration) error

WaitForLock will attempt to acquire the lock for the duration given

Jump to

Keyboard shortcuts

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