Documentation
¶
Overview ¶
Package fslock provides a cross-process mutex based on file locks.
It is built on top of flock for linux and darwin, and LockFileEx on Windows.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidName error = errors.New("fslock: lock name must be a single path component")
ErrInvalidName indicates that the name passed to NewInRoot was not a single path component within the root: it was empty, ".", "..", or contained a path separator.
var ErrLocked error = trylockError("fslock is already locked")
ErrLocked indicates TryLock failed because the lock was already locked.
var ErrTimeout error = timeoutError("lock timeout exceeded")
ErrTimeout indicates that the lock attempt timed out.
Functions ¶
This section is empty.
Types ¶
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock implements cross-process locks using syscalls. This implementation is based on flock syscall.
func New ¶
New returns a new lock around the given file. It opens a handle to the file's parent directory and returns an error if that directory cannot be opened.
func NewInRoot ¶ added in v0.0.5
NewInRoot returns a new lock around the file named name within root. name must be a single path component: it may not be empty, ".", "..", or contain a path separator, and otherwise NewInRoot returns ErrInvalidName. To lock a file in a subdirectory, pass a sub-root obtained from root.OpenRoot. All access to the lock file goes through a directory handle, so it can never escape root via symlinks or "..".
The lock borrows root only for the duration of this call: it opens its own independent handle to root's directory, which it owns and which Close releases. The caller retains ownership of root and may close it independently of the returned Lock.
func (*Lock) Close ¶ added in v0.0.5
Close releases the directory handle held by the lock. It does not release a held lock; call Unlock first. The lock must not be used after Close.
func (*Lock) LockWithContext ¶ added in v0.0.4
LockWithContext tries to lock the lock until the context is canceled or its deadline is exceeded. If the context is canceled before the lock is acquired, this method returns ctx.Err().
func (*Lock) LockWithTimeout ¶
LockWithTimeout tries to lock the lock until the timeout expires. If the timeout expires, this method will return ErrTimeout.
