filelock

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: BSD-3-Clause, BSD-3-Clause Imports: 3 Imported by: 0

README

Package cloudeng.io/os/lockedfile/internal/filelock

CircleCI Go Report Card

import cloudeng.io/os/lockedfile/internal/filelock

Package filelock provides a platform-independent API for advisory file locking. Calls to functions in this package on platforms that do not support advisory locks will return errors for which IsNotSupported returns true.

Variables

ErrNotSupported
ErrNotSupported = errors.New("operation not supported")

Functions

Func IsNotSupported
func IsNotSupported(err error) bool

IsNotSupported returns a boolean indicating whether the error is known to report that a function is not supported (possibly for a specific input). It is satisfied by ErrNotSupported as well as some syscall errors.

Func Lock
func Lock(f File) error

Lock places an advisory write lock on the file, blocking until it can be locked.

If Lock returns nil, no other process will be able to place a read or write lock on the file until this process exits, closes f, or calls Unlock on it.

If f's descriptor is already read- or write-locked, the behavior of Lock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called when Lock succeeds.

Func RLock
func RLock(f File) error

RLock places an advisory read lock on the file, blocking until it can be locked.

If RLock returns nil, no other process will be able to place a write lock on the file until this process exits, closes f, or calls Unlock on it.

If f is already read- or write-locked, the behavior of RLock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called if RLock succeeds.

Func Unlock
func Unlock(f File) error

Unlock removes an advisory lock placed on f by this process.

The caller must not attempt to unlock a file that is not locked.

Types

Type File
type File interface {
	// Name returns the name of the file.
	Name() string

	// Fd returns a valid file descriptor.
	// (If the File is an *os.File, it must not be closed.)
	Fd() uintptr

	// Stat returns the FileInfo structure describing file.
	Stat() (os.FileInfo, error)
}

A File provides the minimal set of methods required to lock an open file. File implementations must be usable as map keys. The usual implementation is *os.File.

Documentation

Overview

Package filelock provides a platform-independent API for advisory file locking. Calls to functions in this package on platforms that do not support advisory locks will return errors for which IsNotSupported returns true.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = errors.New("operation not supported")

Functions

func IsNotSupported

func IsNotSupported(err error) bool

IsNotSupported returns a boolean indicating whether the error is known to report that a function is not supported (possibly for a specific input). It is satisfied by ErrNotSupported as well as some syscall errors.

func Lock

func Lock(f File) error

Lock places an advisory write lock on the file, blocking until it can be locked.

If Lock returns nil, no other process will be able to place a read or write lock on the file until this process exits, closes f, or calls Unlock on it.

If f's descriptor is already read- or write-locked, the behavior of Lock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called when Lock succeeds.

func RLock

func RLock(f File) error

RLock places an advisory read lock on the file, blocking until it can be locked.

If RLock returns nil, no other process will be able to place a write lock on the file until this process exits, closes f, or calls Unlock on it.

If f is already read- or write-locked, the behavior of RLock is unspecified.

Closing the file may or may not release the lock promptly. Callers should ensure that Unlock is always called if RLock succeeds.

func Unlock

func Unlock(f File) error

Unlock removes an advisory lock placed on f by this process.

The caller must not attempt to unlock a file that is not locked.

Types

type File

type File interface {
	// Name returns the name of the file.
	Name() string

	// Fd returns a valid file descriptor.
	// (If the File is an *os.File, it must not be closed.)
	Fd() uintptr

	// Stat returns the FileInfo structure describing file.
	Stat() (os.FileInfo, error)
}

A File provides the minimal set of methods required to lock an open file. File implementations must be usable as map keys. The usual implementation is *os.File.

Jump to

Keyboard shortcuts

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