package flock
import "github.com/gofrs/flock"
Package flock implements a thread-safe interface for file locking. It also includes a non-blocking TryLock() function to allow locking without blocking execution.
Package flock is released under the BSD 3-Clause License. See the LICENSE file for more details.
While using this library, remember that the locking behaviors are not guaranteed to be the same on each platform. For example, some UNIX-like operating systems will transparently convert a shared lock to an exclusive lock. If you Unlock() the flock from a location where you believe that you have the shared lock, you may accidentally drop the exclusive lock.
Index ¶
- type Flock
- func New(path string, opts ...Option) *Flock
- func NewFlock(path string) *Flock
- func (f *Flock) Close() error
- func (f *Flock) Lock() error
- func (f *Flock) Locked() bool
- func (f *Flock) Path() string
- func (f *Flock) RLock() error
- func (f *Flock) RLocked() bool
- func (f *Flock) String() string
- func (f *Flock) TryLock() (bool, error)
- func (f *Flock) TryLockContext(ctx context.Context, retryDelay time.Duration) (bool, error)
- func (f *Flock) TryRLock() (bool, error)
- func (f *Flock) TryRLockContext(ctx context.Context, retryDelay time.Duration) (bool, error)
- func (f *Flock) Unlock() error
- type Option
Types ¶
type Flock ¶
type Flock struct {
// contains filtered or unexported fields
}
Flock is the struct type to handle file locking. All fields are unexported, with access to some of the fields provided by getter methods (Path() and Locked()).
func New ¶
New returns a new instance of *Flock. The only parameter it takes is the path to the desired lockfile.
func NewFlock ¶
NewFlock returns a new instance of *Flock. The only parameter it takes is the path to the desired lockfile.
Deprecated: Use New instead.
func (*Flock) Close ¶
Close is equivalent to calling Unlock.
This will release the lock and close the underlying file descriptor. It will not remove the file from disk, that's up to your application.
func (*Flock) Lock ¶
func (*Flock) Locked ¶
Locked returns the lock state (locked: true, unlocked: false).
Warning: by the time you use the returned value, the state may have changed.
func (*Flock) Path ¶
Path returns the path as provided in NewFlock().
func (*Flock) RLock ¶
func (*Flock) RLocked ¶
RLocked returns the read lock state (locked: true, unlocked: false).
Warning: by the time you use the returned value, the state may have changed.
func (*Flock) String ¶
func (*Flock) TryLock ¶
func (*Flock) TryLockContext ¶
TryLockContext repeatedly tries to take an exclusive lock until one of the conditions is met: - TryLock succeeds - TryLock fails with error - Context Done channel is closed.
func (*Flock) TryRLock ¶
func (*Flock) TryRLockContext ¶
TryRLockContext repeatedly tries to take a shared lock until one of the conditions is met: - TryRLock succeeds - TryRLock fails with error - Context Done channel is closed.
func (*Flock) Unlock ¶
type Option ¶
type Option func(f *Flock)
func SetFlag ¶
SetFlag sets the flag used to create/open the file.
func SetPermissions ¶
SetPermissions sets the OS permissions to set on the file.
Source Files ¶
- Version
- v0.12.1 (latest)
- Published
- Jul 22, 2024
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 2 weeks ago –
Tools for package owners.