fslock

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 6, 2025 License: MIT Imports: 11 Imported by: 49

README

go-fs-lock

GoDoc Coverage Status Travis CI

Filesystem based locking

Lead Maintainer

Steven Allen

Table of Contents

Install

go-fs-lock is a standard Go module which can be installed with:

go get github.com/ipfs/go-fs-lock

Usage

Running tests

Before running tests, please run:

make deps

This will make sure that dependencies are rewritten to known working versions.

Contribute

PRs are welcome!

Small note: If editing the Readme, please conform to the standard-readme specification.

License

MIT © Protocol Labs, Inc.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Lock

func Lock(confdir, lockFileName string) (io.Closer, error)

Lock creates the lock.

func Locked

func Locked(confdir, lockFile string) (bool, error)

Locked checks if there is a lock already set.

func WaitLock added in v0.1.0

func WaitLock(ctx context.Context, confdir, lockFileName string) (io.Closer, error)

WaitLock keeps trying to acquire the lock that is held by someone else, until the lock is acquired or until the context is canceled. Retires once per second. Logs warning on each retry.

Types

type LockedError added in v0.0.2

type LockedError string

LockedError is returned as the inner error type when the lock is already taken.

Example
package main

import (
	"errors"
	"fmt"
	"os"

	fslock "github.com/ipfs/go-fs-lock"
)

func main() {
	lockFile, err := fslock.Lock(os.TempDir(), "foo.lock")
	fmt.Println("locked:", errors.As(err, new(fslock.LockedError)))
	defer lockFile.Close()

	_, err = fslock.Lock(os.TempDir(), "foo.lock")
	fmt.Println("locked:", errors.As(err, new(fslock.LockedError)))
}
Output:

locked: false
locked: true

func (LockedError) Error added in v0.0.2

func (e LockedError) Error() string

Jump to

Keyboard shortcuts

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