Documentation ¶
Index ¶
- Variables
- func Glob(fs VFS, pattern string) (matches []string, err error)
- func IsErrNotInsideBaseDir(err error) bool
- type BoundOS
- func (fs *BoundOS) Create(filename string) (*os.File, error)
- func (fs *BoundOS) Join(elem ...string) string
- func (fs *BoundOS) Lstat(filename string) (os.FileInfo, error)
- func (fs *BoundOS) MkdirAll(path string, perm os.FileMode) error
- func (fs *BoundOS) Open(filename string) (*os.File, error)
- func (fs *BoundOS) OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error)
- func (fs *BoundOS) ReadDir(path string) ([]os.DirEntry, error)
- func (fs *BoundOS) Readlink(link string) (string, error)
- func (fs *BoundOS) Remove(filename string) error
- func (fs *BoundOS) RemoveAll(path string) error
- func (fs *BoundOS) Rename(from, to string) error
- func (fs *BoundOS) Root() string
- func (fs *BoundOS) Stat(filename string) (os.FileInfo, error)
- func (fs *BoundOS) Symlink(target, link string) error
- type ErrNotInsideBaseDir
- type VFS
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrPathOutsideBase = errors.New("path outside base dir")
)
Functions ¶
func Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.
Function originally from https://golang.org/src/path/filepath/match_test.go
func IsErrNotInsideBaseDir ¶
Types ¶
type BoundOS ¶
type BoundOS struct {
// contains filtered or unexported fields
}
BoundOS is a fs implementation based on the OS filesystem which is bound to a base dir. Prefer this fs implementation over ChrootOS.
Behaviours of note:
- Read and write operations can only be directed to files which descends from the base dir.
- Symlinks don't have their targets modified, and therefore can point to locations outside the base dir or to non-existent paths.
- Readlink and Lstat ensures that the link file is located within the base dir, evaluating any symlinks that file or base dir may contain.
type ErrNotInsideBaseDir ¶
func (*ErrNotInsideBaseDir) Error ¶
func (e *ErrNotInsideBaseDir) Error() string
type VFS ¶
type VFS interface { // Create creates the named file with mode 0666 (before umask), truncating // it if it already exists. If successful, methods on the returned File can // be used for I/O; the associated file descriptor has mode O_RDWR. Create(filename string) (*os.File, error) // Open opens the named file for reading. If successful, methods on the // returned file can be used for reading; the associated file descriptor has // mode O_RDONLY. Open(filename string) (*os.File, error) // OpenFile is the generalized open call; most users will use Open or Create // instead. It opens the named file with specified flag (O_RDONLY etc.) and // perm, (0666 etc.) if applicable. If successful, methods on the returned // File can be used for I/O. OpenFile(filename string, flag int, perm os.FileMode) (*os.File, error) // Stat returns a FileInfo describing the named file. Stat(filename string) (os.FileInfo, error) // Rename renames (moves) oldpath to newpath. If newpath already exists and // is not a directory, Rename replaces it. OS-specific restrictions may // apply when oldpath and newpath are in different directories. Rename(oldpath, newpath string) error // Remove removes the named file or directory. Remove(filename string) error // RemoveAll removes path and any children it contains. // It removes everything it can but returns the first error // it encounters. If the path does not exist, RemoveAll // returns nil (no error). // If there is an error, it will be of type *PathError. RemoveAll(path string) error // Join joins any number of path elements into a single path, adding a // Separator if necessary. Join calls filepath.Clean on the result; in // particular, all empty strings are ignored. On Windows, the result is a // UNC path if and only if the first path element is a UNC path. Join(elem ...string) string // ReadDir reads the directory named by dirname and returns a list of // directory entries sorted by filename. ReadDir(path string) ([]fs.DirEntry, error) // MkdirAll creates a directory named path, along with any necessary // parents, and returns nil, or else returns an error. The permission bits // perm are used for all directories that MkdirAll creates. If path is/ // already a directory, MkdirAll does nothing and returns nil. MkdirAll(filename string, perm os.FileMode) error // Lstat returns a FileInfo describing the named file. If the file is a // symbolic link, the returned FileInfo describes the symbolic link. Lstat // makes no attempt to follow the link. Lstat(filename string) (os.FileInfo, error) // Symlink creates a symbolic-link from link to target. target may be an // absolute or relative path, and need not refer to an existing node. // Parent directories of link are created as necessary. Symlink(target, link string) error // Readlink returns the target path of link. Readlink(link string) (string, error) }
Click to show internal directories.
Click to hide internal directories.