flock

package
v0.5.12 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package flock provides a wrapper around syscall.Flock

Index

Constants

View Source
const (
	// DefaultFileMode is the filemode used when a flock file is first created
	DefaultFileMode = 0666
	// DefaultDirMode is the filemode used when a directory is created
	DefaultDirMode = 0777
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Flock

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

Flock implements a simple wrapper around syscall.Flock

func Lock

func Lock(filename string) (*Flock, error)

Lock flocks a file by name

func New

func New(filename string) *Flock

New instantiates a Flock for a given filename

func NewWithOpener added in v0.5.7

func NewWithOpener(filename string, opener OpenerFunc) *Flock

NewWithOpener instantiates a Flock for a given filename

func (*Flock) Lock

func (lock *Flock) Lock() error

Lock Flocks the file

func (*Flock) Unlock

func (lock *Flock) Unlock()

Unlock releases the flock

type Handle added in v0.5.7

type Handle int

Handle represets a OS specific file descriptor

type OpenerFunc added in v0.5.7

type OpenerFunc func(string) (Handle, error)

OpenerFunc is a function that opens a file

type Options

type Options struct {
	Base    string      // optional prefix
	Create  bool        // create nodes if missing
	DirMode fs.FileMode // mode used for MkdirAll
}

Options provides rules for Flock protected actions

func (Options) JoinName

func (opt Options) JoinName(name string) string

JoinName joins the given name with the Options.Base when not qualified

func (Options) Mkdir

func (opt Options) Mkdir(name string, dmode fs.FileMode) error

Mkdir creates a directory within the base

func (Options) MkdirAll

func (opt Options) MkdirAll(name string, dmode fs.FileMode) error

MkdirAll attempts to create all directories on a path within the base

func (Options) MkdirBase

func (opt Options) MkdirBase(dmode fs.FileMode) error

MkdirBase creates the Options.Base if it doesn't exist

func (Options) NameSplit

func (opt Options) NameSplit(name string) (string, string)

NameSplit considers Options.Base when splitting a given path

func (Options) New

func (opt Options) New(name string, perm fs.FileMode) (*Flock, error)

New creates a new Flock considering Options

func (Options) NewOpener

func (opt Options) NewOpener(perm fs.FileMode) func(string) (Handle, error)

NewOpener creates an opener funcion considering Options.Create and the given permissions

func (Options) ReadDir

func (opt Options) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the entries of a directory, flocked

func (Options) ReadFile

func (opt Options) ReadFile(name string, perm fs.FileMode) ([]byte, error)

ReadFile reads a file whole, flocked

func (Options) WriteFile

func (opt Options) WriteFile(name string, data []byte, perm fs.FileMode) error

WriteFile writes the given content to a locked file

Jump to

Keyboard shortcuts

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