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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
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.