locking

package
v0.12.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package locking provides a file locking type that is robust to abrupt process termination.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

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

Locker provides file locking facilities.

func NewLocker

func NewLocker(path string, permissions os.FileMode) (*Locker, error)

NewLocker attempts to create a lock with the file at the specified path, creating the file if necessary. The lock is returned in an unlocked state.

func (*Locker) Close

func (l *Locker) Close() error

Close closes the file underlying the locker. This will release any lock held on the file and disable future locking. On POSIX platforms, this also releases other locks held on the same file.

func (*Locker) Held

func (l *Locker) Held() bool

Held returns whether or not the lock is currently held.

func (*Locker) Lock

func (l *Locker) Lock(block bool) error

Lock attempts to acquire the file lock.

func (*Locker) Read

func (l *Locker) Read(buffer []byte) (int, error)

Read implements io.Reader.Read on the underlying file, but errors if the lock is not currently held.

func (*Locker) Truncate added in v0.10.1

func (l *Locker) Truncate(size int64) error

Truncate implements file truncation for the underlying file, but errors if the lock is not currently held.

func (*Locker) Unlock

func (l *Locker) Unlock() error

Unlock releases the file lock.

func (*Locker) Write

func (l *Locker) Write(buffer []byte) (int, error)

Write implements io.Writer.Write on the underlying file, but errors if the lock is not currently held.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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