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 ¶
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).
var ErrNotFound = errors.New("path not found")
ErrNotFound is returned when the resolved path does not exist on disk.
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Roots returns the configured roots (copy). Exposed for the /v1/list handler to enumerate the synthetic top-level in multi-root mode.