go.mod: github.com/alexflint/go-filemutex v1.1.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
16
vendor/github.com/alexflint/go-filemutex/filemutex_flock.go
generated
vendored
16
vendor/github.com/alexflint/go-filemutex/filemutex_flock.go
generated
vendored
@ -35,6 +35,18 @@ func (m *FileMutex) Lock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *FileMutex) TryLock() error {
|
||||
if err := syscall.Flock(m.fd, syscall.LOCK_EX|syscall.LOCK_NB); err != nil {
|
||||
if errno, ok := err.(syscall.Errno); ok {
|
||||
if errno == syscall.EWOULDBLOCK {
|
||||
return AlreadyLocked
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *FileMutex) Unlock() error {
|
||||
if err := syscall.Flock(m.fd, syscall.LOCK_UN); err != nil {
|
||||
return err
|
||||
@ -56,9 +68,7 @@ func (m *FileMutex) RUnlock() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close does an Unlock() combined with closing and unlinking the associated
|
||||
// lock file. You should create a New() FileMutex for every Lock() attempt if
|
||||
// using Close().
|
||||
// Close unlocks the lock and closes the underlying file descriptor.
|
||||
func (m *FileMutex) Close() error {
|
||||
if err := syscall.Flock(m.fd, syscall.LOCK_UN); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user