fslocker

package
v0.0.0-...-c3677c5 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2023 License: Apache-2.0 Imports: 8 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExclusiveLock

type ExclusiveLock struct {
	*Lock
}

ExclusiveLock represents the state of a Exclusive Lock

func (*ExclusiveLock) ToSharedLock

func (el *ExclusiveLock) ToSharedLock() *SharedLock

ToSharedLock downgrade an ExclusiveLock into a SharedLock. It should always succeed

func (*ExclusiveLock) Write

func (el *ExclusiveLock) Write(p []byte) (int, error)

Write is a method to implement the io.Writer interface

type FSLocker

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

FSLocker is a configuration holder struct, use NewFSLocker to instantiate

func NewFSLocker

func NewFSLocker(path string) (*FSLocker, error)

NewFSLocker instantiates a new FSLocker instance

func (*FSLocker) ExclusiveLock

func (locker *FSLocker) ExclusiveLock(ctx context.Context, path string, timeout *time.Duration) (*ExclusiveLock, error)

ExclusiveLock tries to get an exclusive Lock on the path If timeout is nil, then this function will be blocking until lock acquisition is successful if timeout is 0, it will be non-blocking and return unix.EWOULDBLOCK if we cannot acquire the lock if timeout is non-zero, and we timeout, it will return unix.ETIMEDOUT

func (*FSLocker) ListFiles

func (locker *FSLocker) ListFiles(path string) ([]Record, error)

ListFiles lists the files for a given path -- only 1 level deep

func (*FSLocker) RemovePath

func (locker *FSLocker) RemovePath(path string) error

RemovePath removes a given path. It requires that there are no subdirectories. It does not ensure the file is not in used

func (*FSLocker) SharedLock

func (locker *FSLocker) SharedLock(ctx context.Context, path string, timeout *time.Duration) (*SharedLock, error)

SharedLock tries to get an shared Lock on the path If timeout is nil, then this function will be blocking until lock acquisition is successful if timeout is 0, it will be non-blocking and return unix.EWOULDBLOCK if we cannot acquire the lock if timeout is non-zero, and we timeout, it will return unix.ETIMEDOUT

type Lock

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

Lock is either a shared lock, or an exclusive lock.

func (*Lock) Bump

func (l *Lock) Bump()

Bump the mtime on the locked file

func (*Lock) Read

func (l *Lock) Read(p []byte) (int, error)

Read is a method to implement the io.Reader interface

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock the lock

type Record

type Record struct {
	Name     string
	BumpTime time.Time
}

Record includes the metadata about the file

type SharedLock

type SharedLock struct {
	*Lock
}

SharedLock represents the state of a Shared Lock

func (*SharedLock) ToExclusiveLock

func (sl *SharedLock) ToExclusiveLock(ctx context.Context, timeout *time.Duration) (*ExclusiveLock, error)

ToExclusiveLock tries to upgrade a SharedLock into an ExclusiveLock. If timeout is nil, then this function will be blocking, otherwise it will be non-blocking. It will return unix.ETIMEDOUT if timeout occurs If timeout is 0

Jump to

Keyboard shortcuts

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