Documentation
¶
Index ¶
- type FileSystem
- type OsFS
- func (fs *OsFS) AppendFile(path string, data []byte, perm os.FileMode) error
- func (fs *OsFS) AtomicWriteFile(path string, data []byte, perm os.FileMode) error
- func (fs *OsFS) Chmod(path string, mode os.FileMode) error
- func (fs *OsFS) Chown(path string, uid, gid int) error
- func (fs *OsFS) Chtimes(path string, atime, mtime time.Time) error
- func (fs *OsFS) GetJail() string
- func (fs *OsFS) Getwd() (string, error)
- func (fs *OsFS) Glob(pattern string) ([]string, error)
- func (fs *OsFS) Lchown(path string, uid, gid int) error
- func (fs *OsFS) Mkdir(path string, perm os.FileMode, all bool) error
- func (fs *OsFS) OpenFile(path string, flag int, perm os.FileMode) (io.WriteCloser, error)
- func (fs *OsFS) ReadDir(path string) ([]os.DirEntry, error)
- func (fs *OsFS) ReadFile(path string) ([]byte, error)
- func (fs *OsFS) Rel(basePath, targetPath string) (string, error)
- func (fs *OsFS) Remove(path string, all bool) error
- func (fs *OsFS) Rename(src, dst string) error
- func (fs *OsFS) ResolvePath(path string, followSymlinks bool) (string, error)
- func (fs *OsFS) SetJail(jailPath string) error
- func (fs *OsFS) Setwd(path string) error
- func (fs *OsFS) Stat(path string, followSymlinks bool) (os.FileInfo, error)
- func (fs *OsFS) Symlink(oldname, newname string) error
- func (fs *OsFS) WriteFile(path string, data []byte, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FileSystem ¶
type FileSystem interface {
jail.Jailed
// ReadFile reads the contents of the file at path.
// Relative paths are resolved from the current working directory.
ReadFile(path string) ([]byte, error)
// WriteFile writes data to path with the provided permissions.
// Relative paths are resolved from the current working directory.
WriteFile(path string, data []byte, perm os.FileMode) error
// Mkdir creates a directory at path, using MkdirAll when all is true.
// Relative paths are resolved from the current working directory.
Mkdir(path string, perm os.FileMode, all bool) error
// Remove deletes path, using recursive removal when all is true.
// Relative paths are resolved from the current working directory.
Remove(path string, all bool) error
// Rename moves or renames src to dst.
// Relative src and dst paths are resolved from the current working directory.
Rename(src, dst string) error
// Stat returns file metadata for path, following symlinks when requested.
// Relative paths are resolved from the current working directory.
Stat(path string, followSymlinks bool) (os.FileInfo, error)
// ReadDir reads and returns directory entries for path.
// Relative paths are resolved from the current working directory.
ReadDir(path string) ([]os.DirEntry, error)
// Symlink creates newname as a symbolic link to oldname.
// Relative oldname and newname paths are resolved from the current working directory.
Symlink(oldname, newname string) error
// Glob returns paths matching the provided pattern.
// Relative patterns are evaluated from the current working directory.
Glob(pattern string) ([]string, error)
// AppendFile appends data to path, creating the file if it does not exist.
// Relative paths are resolved from the current working directory.
AppendFile(path string, data []byte, perm os.FileMode) error
// OpenFile opens the file at path with the given flags and permissions,
// returning an io.WriteCloser. Callers must close the returned writer.
// Relative paths are resolved from the current working directory.
OpenFile(path string, flag int, perm os.FileMode) (io.WriteCloser, error)
// Chmod changes the mode of the file at path to mode.
// Relative paths are resolved from the current working directory.
// On Windows only the read-only bit is honored, matching the
// behavior of WriteFile's perm argument.
Chmod(path string, mode os.FileMode) error
// Chown changes the numeric uid and gid of the file at path.
// Relative paths are resolved from the current working directory.
// On Windows this is a no-op.
Chown(path string, uid, gid int) error
// Lchown is like Chown but does not follow symlinks.
// Relative paths are resolved from the current working directory.
// On Windows this is a no-op.
Lchown(path string, uid, gid int) error
// Chtimes changes the access and modification times of the file at path.
// Relative paths are resolved from the current working directory.
// On Windows the resolution of access time is filesystem-dependent
// (e.g. FAT32 truncates to 2-second granularity).
Chtimes(path string, atime, mtime time.Time) error
// AtomicWriteFile writes data to path atomically with the provided permissions.
// Relative paths are resolved from the current working directory.
AtomicWriteFile(path string, data []byte, perm os.FileMode) error
// Rel returns a relative path from basePath to targetPath.
// Relative paths are resolved from the current working directory.
Rel(basePath, targetPath string) (string, error)
// Getwd returns the current working directory used for relative path resolution.
Getwd() (string, error)
// Setwd sets the current working directory to path.
// Relative paths are resolved from the current working directory.
Setwd(path string) error
// ResolvePath resolves path to an absolute normalized path, optionally following symlinks.
// Relative paths are resolved from the current working directory.
ResolvePath(path string, followSymlinks bool) (string, error)
}
FileSystem defines the contract for filesystem operations operating on resolved/host filesystem paths.
Path and pattern inputs may be absolute or relative. Relative inputs are resolved against the implementation's current working directory as reported by Getwd and changed by Setwd.
type OsFS ¶
type OsFS struct {
// contains filtered or unexported fields
}
OsFS is the canonical FileSystem implementation for host and jailed access.
When jail is empty, paths resolve against the host filesystem. When jail is set, all virtual absolute paths are mapped under jail on the host.
func NewOsFS ¶
NewOsFS constructs an OsFS with optional jail and initial working directory.
If wd is empty and jail is set, wd defaults to "/". If wd is empty and jail is not set, wd defaults to the process working directory.