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 ¶
- Variables
- type Driver
- func (d *Driver) Capabilities() storage.Capabilities
- func (d *Driver) Copy(ctx context.Context, src, dst string) error
- func (d *Driver) Delete(_ context.Context, p string) error
- func (d *Driver) Init(_ context.Context, cfg map[string]any) error
- func (d *Driver) List(_ context.Context, p string) ([]storage.Object, error)
- func (d *Driver) Mkdir(_ context.Context, p string) error
- func (d *Driver) Move(_ context.Context, src, dst string) error
- func (d *Driver) Name() string
- func (d *Driver) Read(_ context.Context, p string) (io.ReadCloser, error)
- func (d *Driver) ReadRange(_ context.Context, p string, off, length int64) (io.ReadCloser, error)
- func (d *Driver) Root() string
- func (d *Driver) SetMtime(_ context.Context, p string, mtime time.Time) error
- func (d *Driver) Stat(_ context.Context, p string) (storage.Object, error)
- func (d *Driver) Write(_ context.Context, p string, r io.Reader, _ int64) error
Constants ¶
This section is empty.
Variables ¶
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) Init ¶
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) ReadRange ¶
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 ¶
Root returns the absolute disk path — exposed so the sync worker's fsnotify watcher can attach to it.