local

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package local is a Storage Driver fronting an on-disk directory.

Path safety is two layers, and they answer different questions:

  • resolve is LEXICAL. It maps a wire path onto the root and refuses anything that leaves it by `..`. It never touches the filesystem.
  • contained is REAL. It asks the kernel whether the path — symlinks and all — still lands inside the root.

Both are needed, and until v0.43.0 only a broken version of the first existed. The lexical layer alone let `..\sibling` out on Windows (see toSlash and within); the real layer alone cannot judge a path that names nothing on disk yet, which is every upload.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEscapesRoot    = errors.New("local: path escapes root")
	ErrLinkLeavesRoot = errors.New("local: symlink target is outside the storage root")
)

The driver's two containment refusals. They are separate sentinels because they have different cures: ErrEscapesRoot is a malformed request and nobody can turn it into a legal one, while ErrLinkLeavesRoot names a real object the operator may decide to allow by switching follow_symlinks on.

Functions

This section is empty.

Types

type Driver

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

Driver implements local FS access.

func (*Driver) Capabilities

func (d *Driver) Capabilities() storage.Capabilities

Capabilities — local FS supports everything except Presign.

func (*Driver) Copy

func (d *Driver) Copy(ctx context.Context, src, dst string) error

Copy implements storage.Copier.

func (*Driver) Delete

func (d *Driver) Delete(_ context.Context, p string) error

Delete implements storage.Deleter.

func (*Driver) Init

func (d *Driver) Init(_ context.Context, cfg map[string]any) error

Init validates and stores the root directory from config["path"] (preferred) or config["root"] (legacy). Matches storage.ValidateNonRootPath's own preference order — without this fallback an operator could create a storage with {path: "/data"} via the admin API, pass validate.go cleanly, and then watch the driver init silently with an empty root because it only looked at config["root"].

func (*Driver) List

func (d *Driver) List(_ context.Context, p string) ([]storage.Object, error)

List implements storage.Driver.

func (*Driver) Mkdir

func (d *Driver) Mkdir(_ context.Context, p string) error

Mkdir implements storage.Mkdirer.

func (*Driver) Move

func (d *Driver) Move(_ context.Context, src, dst string) error

Move implements storage.Mover.

func (*Driver) Name

func (d *Driver) Name() string

Name implements storage.Driver.

func (*Driver) Read

func (d *Driver) Read(_ context.Context, p string) (io.ReadCloser, error)

Read implements storage.Driver.

func (*Driver) ReadRange

func (d *Driver) ReadRange(_ context.Context, p string, off, length int64) (io.ReadCloser, error)

ReadRange implements storage.RangeReader — a plain seek on the open file. Seeking past EOF is legal on a POSIX file and the first Read then reports io.EOF, which is exactly the documented contract.

func (*Driver) Root

func (d *Driver) Root() string

Root returns the absolute disk path — exposed so the sync worker's fsnotify watcher can attach to it.

func (*Driver) SetMtime

func (d *Driver) SetMtime(_ context.Context, p string, mtime time.Time) error

SetMtime implements storage.Toucher.

func (*Driver) Stat

func (d *Driver) Stat(_ context.Context, p string) (storage.Object, error)

Stat implements storage.Driver.

func (*Driver) Write

func (d *Driver) Write(_ context.Context, p string, r io.Reader, _ int64) error

Write implements storage.Writer.

Jump to

Keyboard shortcuts

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