Documentation
¶
Overview ¶
Package vfs defines the file system abstraction that lets the UI browse and transfer between local and remote locations with the same code.
Index ¶
- Variables
- func CheckName(name string) error
- func LooksBinary(data []byte) bool
- func ReadHead(fsys FS, path string, n int) (data []byte, truncated bool, err error)
- func RemoveAll(fsys FS, path string) error
- func RemoveAllFunc(fsys FS, path string, removed func(path string)) error
- func Sanitize(s string) string
- type Entry
- type FS
- type Local
- func (Local) Base(path string) string
- func (Local) Chmod(path string, mode fs.FileMode) error
- func (Local) Chtimes(path string, mtime time.Time) error
- func (Local) Create(path string) (io.WriteCloser, error)
- func (Local) Dir(path string) string
- func (Local) Home() (string, error)
- func (Local) IsRoot(path string) bool
- func (Local) Join(elem ...string) string
- func (Local) Label() string
- func (Local) Mkdir(path string) error
- func (Local) Open(path string) (io.ReadCloser, error)
- func (Local) ReadDir(path string) ([]Entry, error)
- func (Local) Remove(path string) error
- func (Local) Rename(oldPath, newPath string) error
- func (Local) Stat(path string) (Entry, error)
- type SFTP
- func (*SFTP) Base(p string) string
- func (s *SFTP) Chmod(p string, mode fs.FileMode) error
- func (s *SFTP) Chtimes(p string, mtime time.Time) error
- func (s *SFTP) Create(p string) (io.WriteCloser, error)
- func (*SFTP) Dir(p string) string
- func (s *SFTP) Home() (string, error)
- func (*SFTP) IsRoot(p string) bool
- func (*SFTP) Join(elem ...string) string
- func (s *SFTP) Label() string
- func (s *SFTP) Mkdir(p string) error
- func (s *SFTP) Open(p string) (io.ReadCloser, error)
- func (s *SFTP) ReadDir(p string) ([]Entry, error)
- func (s *SFTP) Remove(p string) error
- func (s *SFTP) Rename(oldPath, newPath string) error
- func (s *SFTP) Stat(p string) (Entry, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnsafeName = errors.New("unsafe file name")
ErrUnsafeName is returned for names that could escape their directory or that the local system can't store.
Functions ¶
func CheckName ¶
CheckName validates a single path element, as listed by a (possibly hostile) server or typed by the user. It rejects anything that could traverse directories ("..", separators), NUL bytes, and control characters.
func LooksBinary ¶
LooksBinary guesses whether data is binary rather than text.
func ReadHead ¶
ReadHead reads up to n bytes from the start of a file, reporting whether the file was longer.
func RemoveAll ¶
RemoveAll deletes path and, for directories, everything inside it. Directory symlinks are removed as links, never followed.
func RemoveAllFunc ¶ added in v0.2.0
RemoveAllFunc is RemoveAll, calling removed (if not nil) with the path of each file and directory after it is deleted, so callers can show progress.
Types ¶
type Entry ¶
type Entry struct {
Name string
Size int64
Mode fs.FileMode
ModTime time.Time
// IsDir is true for directories and for symlinks that point to one, so
// links to directories can be navigated into.
IsDir bool
IsLink bool
}
Entry describes one item in a directory listing.
func FromFileInfo ¶
FromFileInfo converts info (from an lstat-style call) into an Entry. For symlinks, stat is used to resolve the target so IsDir and Size describe what the link points to; a broken link is reported as a non-directory.
func (Entry) Executable ¶
Executable reports whether any execute bit is set on a regular file.
type FS ¶
type FS interface {
// Label is a short human-readable name, e.g. "Local" or "jsd@nas".
Label() string
// Home returns the starting directory for this file system.
Home() (string, error)
ReadDir(path string) ([]Entry, error)
// Stat describes path without following a final symlink, except to
// fill in IsDir for links to directories.
Stat(path string) (Entry, error)
Open(path string) (io.ReadCloser, error)
// Create creates or truncates a file for writing.
Create(path string) (io.WriteCloser, error)
Mkdir(path string) error
// Remove deletes a file or an empty directory.
Remove(path string) error
Rename(oldPath, newPath string) error
// Chtimes sets the modification (and access) time.
Chtimes(path string, mtime time.Time) error
// Chmod sets permission bits.
Chmod(path string, mode fs.FileMode) error
Join(elem ...string) string
Dir(path string) string
Base(path string) string
IsRoot(path string) bool
}
FS is a browsable file system. Paths are absolute and use the file system's own conventions (local paths on Windows use backslashes, SFTP paths always use forward slashes), so callers must use the FS's path helpers rather than path or path/filepath directly.
type Local ¶
type Local struct{}
Local is the machine's own file system.
func (Local) Create ¶
func (Local) Create(path string) (io.WriteCloser, error)
Create implements FS.
type SFTP ¶
type SFTP struct {
// contains filtered or unexported fields
}
SFTP is a remote file system over an SFTP session. Paths always use forward slashes.