appstate

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

internal/appstate/lock.go

Package appstate centralises all filesystem state access for the Omniview application, providing a single source of truth for the state directory root.

internal/appstate/scoped.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveRoot

func ResolveRoot() (string, error)

ResolveRoot preserves environment > ldflags > production default outside a workspace. Workspace context fails closed and owns its canonical UUID root.

func SelectedRoot added in v0.5.0

func SelectedRoot() (string, error)

SelectedRoot returns the explicit environment/build selection, or an empty string. It never supplies the production default to a workspace resolver.

func ValidateRoot added in v0.5.0

func ValidateRoot(root string) (string, error)

ValidateRoot is also applied to WithRoot: programmatic callers cannot bypass absolute-path, canonical-alias or selected-workspace ownership validation.

Types

type FilesystemIdentity added in v0.5.0

type FilesystemIdentity struct {
	Volume uint64   `json:"volume"`
	File   [16]byte `json:"file"`
}

FilesystemIdentity identifies an owned filesystem object across process restarts. File retains the full Windows FILE_ID_128; Unix stores the inode in its low bytes.

type Option

type Option func(*config)

Option configures the Service constructor.

func WithFlock

func WithFlock(enabled bool) Option

WithFlock enables or disables file locking.

func WithRoot

func WithRoot(path string) Option

WithRoot sets the root directory for the state service.

type ScopedRoot

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

ScopedRoot provides contained filesystem access to a subdirectory. All path arguments are relative to the scope root. The underlying os.Root enforces containment at the kernel level.

func (*ScopedRoot) Close

func (s *ScopedRoot) Close() error

Close releases the underlying os.Root handle.

func (*ScopedRoot) DirectoryIdentity added in v0.5.0

func (s *ScopedRoot) DirectoryIdentity(name string) (FilesystemIdentity, error)

DirectoryIdentity reads the durable identity of a contained, non-redirected directory owned by the current OS user. The root itself may be inspected as ".".

func (*ScopedRoot) FS

func (s *ScopedRoot) FS() fs.FS

func (*ScopedRoot) MkdirAll

func (s *ScopedRoot) MkdirAll(path string, perm fs.FileMode) error

func (*ScopedRoot) MkdirTemp added in v0.5.0

func (s *ScopedRoot) MkdirTemp(prefix string) (string, error)

MkdirTemp creates a private, exclusive directory through the held root capability, without resolving an absolute pathname outside that capability.

func (*ScopedRoot) OpenFile

func (s *ScopedRoot) OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)

func (*ScopedRoot) OpenPrivateFile added in v0.5.0

func (s *ScopedRoot) OpenPrivateFile(name string, flag int) (*os.File, FilesystemIdentity, error)

OpenPrivateFile validates a contained regular file and its owner before the caller reads its contents. It returns identity proof for subsequent removal.

func (*ScopedRoot) ReadDir

func (s *ScopedRoot) ReadDir(name string) ([]fs.DirEntry, error)

ReadDir reads the named directory relative to the scoped root. Implemented as Open + (*File).ReadDir since os.Root does not expose ReadDir.

func (*ScopedRoot) ReadFile

func (s *ScopedRoot) ReadFile(name string) ([]byte, error)

func (*ScopedRoot) Remove

func (s *ScopedRoot) Remove(name string) error

func (*ScopedRoot) RemoveAll

func (s *ScopedRoot) RemoveAll(name string) error

func (*ScopedRoot) Rename

func (s *ScopedRoot) Rename(oldpath, newpath string) error

func (*ScopedRoot) RenameDirectoryNoReplace added in v0.5.0

func (s *ScopedRoot) RenameDirectoryNoReplace(oldpath, newpath string) error

RenameDirectoryNoReplace atomically moves a contained directory only when the destination does not exist. It never emulates exclusion with check-then-rename or copy/delete; unsupported filesystems and kernels return an error.

func (*ScopedRoot) ResolvePath

func (s *ScopedRoot) ResolvePath(name string) string

ResolvePath returns the absolute path for a relative name within the scoped root. If name is empty, the root path itself is returned. If name fails validation (e.g. absolute path or traversal), the root path is returned as a safe fallback.

func (*ScopedRoot) Stat

func (s *ScopedRoot) Stat(name string) (fs.FileInfo, error)

func (*ScopedRoot) WriteFile

func (s *ScopedRoot) WriteFile(name string, data []byte, perm fs.FileMode) error

type Service

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

Service is the central authority for all application state filesystem access. Create once at startup via New() and inject into subsystems.

func New

func New(opts ...Option) (*Service, error)

New creates a new Service with the given options.

func NewTestService

func NewTestService(t testing.TB) *Service

NewTestService creates a Service backed by a temporary directory for use in tests. The service is automatically cleaned up when the test finishes.

func (*Service) Close

func (s *Service) Close() error

Close releases all resources held by the Service. Errors from individual close operations are aggregated and returned together. Close is idempotent; subsequent calls return the result of the first call.

func (*Service) Logs

func (s *Service) Logs() *ScopedRoot

Logs returns the scoped root for the logs directory.

func (*Service) PluginData

func (s *Service) PluginData(id string) (*ScopedRoot, error)

PluginData returns a scoped root for a specific plugin's data directory. The result is cached; subsequent calls for the same id return the cached instance.

func (*Service) PluginStore

func (s *Service) PluginStore(id string) (*ScopedRoot, error)

PluginStore returns a scoped root for a specific plugin's store directory. The result is cached; subsequent calls for the same id return the cached instance.

func (*Service) Plugins

func (s *Service) Plugins() *ScopedRoot

Plugins returns the scoped root for the plugins directory.

func (*Service) Root

func (s *Service) Root() string

Root returns the absolute path to the state directory.

func (*Service) RootDir

func (s *Service) RootDir() *ScopedRoot

RootDir returns the scoped root for the top-level state directory.

Jump to

Keyboard shortcuts

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