filelock

package module
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: BSD-3-Clause Imports: 6 Imported by: 1

README

filelock

GoDoc

Package filelock provides locked File struct similar with os.File.

Documentation

Overview

Package filelock provides locked File struct similar with os.File.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocked = LockError{errors.New("locked")}
)

Functions

This section is empty.

Types

type File

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

File represents an open file descriptor such as os.File. But File always has Posix write lock.

func Acquire

func Acquire(ctx context.Context, name string, perm os.FileMode, period time.Duration) (*File, error)

Acquire tries to obtain file lock given period.

func Create

func Create(name string, perm os.FileMode) (*File, error)

Create creates or opens the named file with OpenFile. When an error occurs, Create returns OpenFile error. If the file already exists, it is not truncated as with os.Create. If the file does not exist, it is created with mode perm (before umask). If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode os.O_RDWR.

func Open

func Open(name string) (*File, error)

Open opens the named file with OpenFile for reading. When an error occurs, Open returns the error like OpenFile. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode os.O_RDONLY.

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (f *File, err error)

OpenFile opens the named file with os.OpenFile, after locks with Posix lock. When an error occurs, OpenFile returns os.OpenFile error or LockError. If the file created with os.O_CREATE and LockError occurs, OpenFile will not delete created file.

func (*File) Close

func (f *File) Close() (err error)

Close closes and unlocks the File.

func (*File) Release

func (f *File) Release() (err error)

Release deletes, closes and unlocks the File.

type LockError

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

Directories

Path Synopsis
examples
example1 command

Jump to

Keyboard shortcuts

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