volumefiles

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package volumefiles browses and edits single files inside a named volume's host directory, confined to that directory by os.Root so traversal and symlink escapes fail in the kernel-facing layer rather than by string checks.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPathEscapes is returned for any path that leaves the volume root.
	ErrPathEscapes = errors.New("volumefiles: path escapes the volume")
	// ErrNotFound means the path does not exist inside the volume.
	ErrNotFound = errors.New("volumefiles: no such file")
	// ErrIsDirectory means a file operation was aimed at a directory.
	ErrIsDirectory = errors.New("volumefiles: path is a directory")
	// ErrNotRegular means the path is a device, socket, fifo or similar.
	ErrNotRegular = errors.New("volumefiles: path is not a regular file")
	// ErrTooLarge means an upload exceeded the configured cap.
	ErrTooLarge = errors.New("volumefiles: upload exceeds the size limit")
)

Functions

func Classify

func Classify(err error) error

Classify recovers a sentinel from an error that crossed the agent wire as text.

func Clean

func Clean(p string) (string, error)

Clean maps a user path to a slash-separated path relative to the volume root, rejecting NUL bytes and any ".." component. "" and "/" mean the root.

func EffectiveLimit

func EffectiveLimit(requested int) int

EffectiveLimit returns the smaller positive of requested and the env cap.

func EffectiveMax

func EffectiveMax(requested int64) int64

EffectiveMax returns the smaller positive of requested and the env cap.

func EncodeEntries

func EncodeEntries(w io.Writer, entries []Entry, truncated bool) error

EncodeEntries writes entries as JSON lines, plus a final truncated marker.

func ListLimit

func ListLimit() int

ListLimit is the per-directory entry cap from APP_VOLUME_FILE_LIST_LIMIT.

func MaxUploadBytes

func MaxUploadBytes() int64

MaxUploadBytes is the per-file upload cap from APP_VOLUME_FILE_MAX_UPLOAD_MB.

Types

type Entry

type Entry struct {
	Name      string `json:"name"`
	Path      string `json:"path"`
	Type      string `json:"type"`
	Size      int64  `json:"size"`
	Mode      string `json:"mode"`
	ModTime   string `json:"mod_time"`
	Truncated bool   `json:"truncated,omitempty"`
}

Entry is one item in a directory listing.

func DecodeEntries

func DecodeEntries(r io.Reader) ([]Entry, bool, error)

DecodeEntries is the inverse of EncodeEntries.

type Store

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

Store performs file operations strictly inside one volume directory.

func Open

func Open(dir string) (*Store, error)

Open confines operations to dir, normally a volume's host mountpoint.

func (*Store) Close

func (s *Store) Close() error

Close releases the root handle.

func (*Store) List

func (s *Store) List(p string, limit int) ([]Entry, bool, error)

List returns up to limit entries of the directory at p, directories first, and whether more existed. Symlinks are listed, never followed.

func (*Store) Read

func (s *Store) Read(p string) (io.ReadCloser, int64, error)

Read opens the regular file at p. The caller closes it.

func (*Store) Remove

func (s *Store) Remove(p string) error

Remove deletes exactly one non-directory entry; a symlink is removed, not followed.

func (*Store) Write

func (s *Store) Write(p string, r io.Reader, maxBytes int64) (int64, error)

Write stores r at p through a temp file and a rename, so a failed or oversized upload never leaves a partial file. Existing ownership and mode are kept so the app keeps access to what it owns.

func (*Store) WriteMode

func (s *Store) WriteMode(p string, r io.Reader, maxBytes int64, want fs.FileMode) (int64, error)

WriteMode is Write with a requested permission for the file. A zero mode keeps Write's behaviour; otherwise the result is never wider than mode, nor than the file it replaces.

Jump to

Keyboard shortcuts

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