hostfiles

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: GPL-3.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hostfiles lets a client browse files on the Core host without ever naming an absolute path. Core offers a fixed set of roots; a client names a root by ID and a path under it, and every path is resolved against its root again, symlinks included, before anything is listed or read.

Index

Constants

View Source
const (
	// MaxDirEntries caps how many entries of one folder are read. A larger
	// folder is listed in part and reported as truncated.
	MaxDirEntries = 10000
	// ReadTimeout bounds one request's filesystem work, waiting for a slot
	// included, so a share that stopped answering fails the request instead
	// of holding it.
	ReadTimeout = 5 * time.Second

	// ImagesRootID is the ID of the root for Core's image folder.
	ImagesRootID = "images"
)

Variables

View Source
var (
	ErrUnknownRoot = errors.New("unknown root")
	ErrInvalidPath = errors.New("path must be relative to its root and stay inside it")
	ErrNotFound    = errors.New("no such file or folder")
	ErrNotDir      = errors.New("path is not a folder")
	ErrNotFile     = errors.New("path is not a file of the requested kind")
	ErrBusy        = errors.New("too many folders are being read; try again")
	ErrTimeout     = errors.New("the folder did not answer in time")
)

Functions

func IsImageName

func IsImageName(name string) bool

IsImageName reports whether a file name has an image extension.

Types

type Browser

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

Browser resolves and lists paths under a set of roots. Every method that touches the filesystem runs it under ReadTimeout and a read slot.

func NewBrowser

func NewBrowser(indexRoots []string, imageDir string) *Browser

NewBrowser returns a browser over the index roots and Core's image folder. A folder named twice appears once. It does not touch the filesystem: Roots leaves out the folders that do not exist.

func (*Browser) ListImages

func (b *Browser) ListImages(ctx context.Context, id, rel string) (Listing, error)

ListImages lists the folders and image files of one folder under a root, folders first, each group by name. Hidden entries and anything a symlink leads out of the root are left out. The folder is read through the root, so a folder swapped for a link after the check cannot lead outside.

func (*Browser) OpenImage

func (b *Browser) OpenImage(ctx context.Context, id, rel string) (*Image, error)

OpenImage opens a regular file with an image extension under the root with the given ID. rel uses forward slashes. A path that leaves its root, by ".." or through a symlink, is refused, and the file is opened through the root, so a folder swapped for a link after the check cannot lead outside.

func (*Browser) Roots

func (b *Browser) Roots(ctx context.Context) []Root

Roots returns the folders a client may browse: those that exist and answered in time. Each is checked on its own, so one that stopped answering is left out without holding up the rest.

type Entry

type Entry struct {
	Modified time.Time
	Name     string
	// Path is the entry's path under its root, with forward slashes.
	Path  string
	Size  int64
	IsDir bool
}

Entry is one folder or file in a listing.

type Image

type Image struct {
	Info os.FileInfo
	File *os.File
	// Path is the file's real path when it was opened, for naming it. Read
	// the file through File: Path is not checked again.
	Path string
}

Image is an image file opened under a browse root. The caller closes File.

type Listing

type Listing struct {
	Entries []Entry
	// Truncated reports a folder with more entries than were read.
	Truncated bool
}

Listing is one folder's entries of the requested kind, folders first.

type Root

type Root struct {
	ID   string
	Name string
	Path string
}

Root is one folder a client may browse.

Jump to

Keyboard shortcuts

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