Documentation
¶
Overview ¶
Package file is a Go library to open files with file locking depending on the system.
Currently file locking on the following systems are supported.
darwin dragonfly freebsd linux netbsd openbsd solaris: Advisory Lock windows: Mandatory Lock android nacl plan9 zos: Not Supported
Index ¶
- func Close(fp *os.File) (err error)
- func Create(path string) (*os.File, error)
- func Lock(fp *os.File) error
- func LockContext(ctx context.Context, retryDelay time.Duration, fp *os.File) error
- func LockEX(fp *os.File) error
- func LockSH(fp *os.File) error
- func NewContextCanceled(message string) error
- func NewContextDone(message string) error
- func NewIOError(message string) error
- func NewLockError(message string) error
- func NewTimeoutError(path string) error
- func Open(path string, flag int, fn func(*os.File) error) (*os.File, error)
- func OpenContext(ctx context.Context, retryDelay time.Duration, path string, flag int, ...) (*os.File, error)
- func OpenToRead(path string) (*os.File, error)
- func OpenToReadContext(ctx context.Context, retryDelay time.Duration, path string) (*os.File, error)
- func OpenToUpdate(path string) (*os.File, error)
- func OpenToUpdateContext(ctx context.Context, retryDelay time.Duration, path string) (*os.File, error)
- func RLock(fp *os.File) error
- func RLockContext(ctx context.Context, retryDelay time.Duration, fp *os.File) error
- func TryLock(fp *os.File) error
- func TryLockEX(fp *os.File) error
- func TryLockSH(fp *os.File) error
- func TryOpenToRead(path string) (*os.File, error)
- func TryOpenToUpdate(path string) (*os.File, error)
- func TryRLock(fp *os.File) error
- func Unlock(fp *os.File) error
- type ContextCanceled
- type ContextDone
- type IOError
- type LockError
- type TimeoutError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
Opens the file with exclusive locking. This function is the same as Open(path, os.O_CREATE|os.O_EXCL|os.O_RDWR, TryLock)
func Lock ¶
Places the exclusive lock on the file. If the file is already locked, waits until the file is released.
func LockContext ¶
Places the exclusive lock on the file. If the file is already locked, tries to lock repeatedly until the conditions is met.
func LockEX ¶
Places an exclusive lock on the file. If the file is already locked, waits until the file is released.
func LockSH ¶
Places a shared lock on the file. If the file is already locked, waits until the file is released.
func NewContextCanceled ¶
func NewContextDone ¶
func NewIOError ¶
func NewLockError ¶
func NewTimeoutError ¶
func OpenContext ¶
func OpenContext(ctx context.Context, retryDelay time.Duration, path string, flag int, fn func(context.Context, time.Duration, *os.File) error) (*os.File, error)
Opens the file with passed locking function. If failed, try to lock repeatedly until the conditions is met.
func OpenToRead ¶
Opens the file with shared lock. This function is the same as Open(path, os.O_RDONLY, RLock)
func OpenToReadContext ¶
func OpenToReadContext(ctx context.Context, retryDelay time.Duration, path string) (*os.File, error)
Opens the file with shared lock. If the file is already locked, tries to lock repeatedly until the conditions is met. This function is the same as OpenContext(ctx, retryDelay, path, RLockContext)
func OpenToUpdate ¶
Opens the file with exclusive lock. This function is the same as Open(path, os.O_RDWR, Lock)
func OpenToUpdateContext ¶
func OpenToUpdateContext(ctx context.Context, retryDelay time.Duration, path string) (*os.File, error)
Opens the file with exclusive lock. If the file is already locked, tries to lock repeatedly until the conditions is met. This function is the same as OpenContext(ctx, retryDelay, path, LockContext)
func RLock ¶
Places the shared lock on the file. If the file is already locked, waits until the file is released.
func RLockContext ¶
Places the shared lock on the file. If the file is already locked, tries to lock repeatedly until the conditions is met.
func TryLock ¶
Places the exclusive lock on the file. If the file is already locked, returns an error immediately.
func TryLockEX ¶
Places an exclusive lock on the file. If the file is already locked, returns an error immediately.
func TryLockSH ¶
Places a shared lock on the file. If the file is already locked, returns an error immediately.
func TryOpenToRead ¶
Tries to lock and opens the file with shared lock. This function is the same as Open(path, os.O_RDONLY, TryRLock)
func TryOpenToUpdate ¶
Tries to lock and opens the file with exclusive lock. This function is the same as Open(path, os.O_RDWR, TryLock)
Types ¶
type ContextCanceled ¶
type ContextCanceled struct {
// contains filtered or unexported fields
}
func (ContextCanceled) Error ¶
func (e ContextCanceled) Error() string
type ContextDone ¶
type ContextDone struct {
// contains filtered or unexported fields
}
func (ContextDone) Error ¶
func (e ContextDone) Error() string
type TimeoutError ¶
type TimeoutError struct {
// contains filtered or unexported fields
}
func (TimeoutError) Error ¶
func (e TimeoutError) Error() string