Help us shape the future of Go! Take the 2026 Go Developer Survey

filelock

package
v0.19.12 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package filelock takes locks that upstream pi can interoperate with, and keeps the JSON documents those locks guard.

Upstream guards its shared state files with npm proper-lockfile, which creates the lock as a DIRECTORY via mkdir and refreshes its mtime while held. A POSIX flock on the same path leaves a zero-byte regular file behind instead, and proper-lockfile never treats a plain file as stale, so it then fails with EEXIST forever. One orb write is enough to wedge the TypeScript runtime permanently. Every path both runtimes touch must lock through here.

Index

Constants

View Source
const (

	// AsyncStale is the window upstream's async auth lock refreshes against
	// (every 15 s), so a live upstream lock is never reclaimed.
	AsyncStale = 30 * time.Second
)

Variables

This section is empty.

Functions

func Acquire

func Acquire(path string) (func() error, error)

Acquire locks path+".lock" and returns the release.

func GroupOrOtherAccess added in v0.19.1

func GroupOrOtherAccess(mode os.FileMode) bool

GroupOrOtherAccess reports POSIX group or other permission bits. Windows has none (Go reports 0666/0777 there); the profile directory's ACL is what keeps private state private on that platform.

func WriteFile added in v0.19.1

func WriteFile(path string, data []byte, perm os.FileMode) error

WriteFile replaces path with data so a reader sees the old file or the new one, never a torn write. A symlinked path keeps its link, and an existing file keeps permission bits narrower than perm, as an in-place write would.

Types

type File added in v0.19.1

type File struct {
	Path string
	Perm os.FileMode
	// Stale is how long a dead holder's lock takes to expire: AsyncStale for
	// auth.json, whose upstream lock heartbeats; 10 s when zero.
	Stale time.Duration
	// Atomic replaces the file through a renamed temporary (WriteFile).
	// Otherwise it is rewritten in place, as upstream writes auth, settings
	// and trust files, which keeps their owner, umask, symlinks and
	// single-file bind mounts; a private Perm is then enforced on the file.
	Atomic bool
}

File is a Document kept in the file at Path. Update holds the lock upstream takes on the same path; Read takes no lock, so it can nest inside an Update and never blocks on one.

func (File) Read added in v0.19.1

func (f File) Read(context.Context) ([]byte, error)

func (File) Update added in v0.19.1

func (f File) Update(ctx context.Context, change func([]byte) ([]byte, error)) error

Update leaves an unchanged file untouched and deletes it when change returns nil. ctx bounds the wait for the lock only: once change has run (it may have rotated a credential), its result is written.

Jump to

Keyboard shortcuts

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