fs

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package fs resolves client-supplied relative paths against a configured library root and rejects traversal (`..`, absolute paths, symlink escapes).

Wire convention (see PROTOCOL.md): client paths are always forward-slash separated regardless of the server OS. The resolver maps to the native separator internally. With a single library root, the whole path is relative to it. With multiple roots, the first path segment must be the basename of one of the configured roots.

Index

Constants

This section is empty.

Variables

View Source
var ErrBadPath = errors.New("path is not a valid library-relative path")

ErrBadPath is returned when a client-supplied path fails a safety check (absolute, `..`, NUL byte, or escapes the library root).

View Source
var ErrNotFound = errors.New("path not found")

ErrNotFound is returned when the resolved path does not exist on disk.

View Source
var ErrUnknownRoot = errors.New("unknown library root")

ErrUnknownRoot is returned (multi-root mode only) when the path's first segment doesn't match any configured root basename.

Functions

func ValidateRoots

func ValidateRoots(roots []string) error

ValidateRoots returns a descriptive error if two library roots share a basename. The multi-root listing protocol keys each top-level entry by basename (e.g. /data/Music and /archive/Music both present as "Music"), so a collision makes one root unreachable. cmd/bridge calls this after config.Load so misconfiguration surfaces at startup rather than as a silent 404 from /v1/list.

Types

type Resolver

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

Resolver maps a client path to an absolute on-disk path, enforcing root-scoping. Safe for concurrent use; roots can be hot-swapped at runtime via SetRoots so the admin console can add or remove a library root without a server restart.

func New

func New(roots []string) *Resolver

New returns a Resolver for the given library roots. The roots must be absolute paths (config.Load enforces this). Callers that want to reject duplicate basenames early should call ValidateRoots first; when two roots share a basename, New keeps the last one (the older behavior) to avoid panicking deep inside api.New.

func (*Resolver) Resolve

func (r *Resolver) Resolve(clientPath string) (string, error)

Resolve maps a client-supplied relative path to an absolute server path. It guarantees the returned path is within one of the configured roots. The existence of the path is NOT checked here — callers that care can os.Stat after; Resolve is a pure safety / routing operation.

func (*Resolver) ResolveChecked

func (r *Resolver) ResolveChecked(clientPath string) (string, os.FileInfo, error)

ResolveChecked is Resolve plus an os.Stat; it returns ErrNotFound if the path does not exist. Convenient for handlers that need both.

func (*Resolver) Roots

func (r *Resolver) Roots() []string

Roots returns the configured roots (copy). Exposed for the /v1/list handler to enumerate the synthetic top-level in multi-root mode.

func (*Resolver) SetRoots

func (r *Resolver) SetRoots(roots []string)

SetRoots atomically replaces the Resolver's root list. In-flight Resolve calls complete against their original snapshot; calls that start after SetRoots returns see the new list. The admin console calls this after adding or removing a library root.

Jump to

Keyboard shortcuts

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