fileconfig

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package fileconfig provides the durable file primitives shared by authored configuration catalogs.

Index

Constants

This section is empty.

Variables

View Source
var ErrLockBusy = errors.New("file_config_lock_busy")

Functions

func EnsurePrivateDirectory

func EnsurePrivateDirectory(ctx context.Context, path string) error

EnsurePrivateDirectory creates an application-owned directory before callers persist credential intents. Existing ancestors keep their permissions.

func IsAtomicTemporaryName

func IsAtomicTemporaryName(name string) bool

IsAtomicTemporaryName reports whether name has the exact decimal suffix produced by os.CreateTemp for atomicTemporaryPattern.

func TryWithExclusiveLock

func TryWithExclusiveLock(ctx context.Context, path string, action func() error) error

TryWithExclusiveLock uses the same cross-process lock and retained sidecar, returning ErrLockBusy immediately when another owner holds it.

func WithExclusiveLock

func WithExclusiveLock(ctx context.Context, path string, action func() error) error

WithExclusiveLock runs action while holding an operating-system advisory lock for path. The sidecar file is intentionally retained: deleting a lock file can let two callers lock different inodes. Closing the file releases the lock even when a process exits unexpectedly.

func WriteAtomically

func WriteAtomically(ctx context.Context, path string, payload []byte) error

WriteAtomically replaces path only after the complete payload has reached the temporary file. Callers remain responsible for validating the payload.

Types

type ExclusiveLock

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

ExclusiveLock keeps ownership until Close, including after acquisition's context ends. A canceled owner must finish its workers before releasing it.

func TryAcquireExclusiveLock

func TryAcquireExclusiveLock(ctx context.Context, path string) (*ExclusiveLock, error)

TryAcquireExclusiveLock returns a lifetime-owned lock. Its sidecar remains on disk so later owners always acquire the same inode.

func (*ExclusiveLock) Close

func (lock *ExclusiveLock) Close() error

type ParsedCache

type ParsedCache[T any] struct {
	// contains filtered or unexported fields
}

ParsedCache reuses validated authored documents by content, never by mtime. Reading the bytes still detects external edits, replacements and corruption. Callers own their returned copy; failed decodes are never cached.

func (*ParsedCache[T]) Read

func (cache *ParsedCache[T]) Read(key string, raw []byte, decode func() (T, error), clone func(T) T) (T, error)

Jump to

Keyboard shortcuts

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