vfs

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package vfs gives the local disk and a remote host the same file system interface, so the file manager and transfer engine treat them alike.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Sort

func Sort(entries []Entry, by SortBy)

Sort orders entries with directories first, then by the given key. Size and time sort largest/newest first.

Types

type Entry

type Entry struct {
	Name    string
	Size    int64
	Mode    fs.FileMode
	ModTime time.Time
	IsDir   bool
	Link    string // symlink target, "" if not a link
	Broken  bool   // symlink whose target can't be resolved
}

Entry is a directory entry. For symlinks, IsDir/Size describe the target and Link holds the link destination.

func (Entry) Hidden

func (e Entry) Hidden() bool

Hidden reports whether the entry is a dotfile.

type FS

type FS interface {
	// Name labels the file system in the UI ("Local" or a host name).
	Name() string
	// Remote reports whether this is a remote file system.
	Remote() bool

	ReadDir(path string) ([]Entry, error)
	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
	MkdirAll(path string) error
	// Remove deletes a file, or a directory recursively.
	Remove(path string) error
	// Rename moves from to to, replacing to if it exists.
	Rename(from, to string) error
	Chtimes(path string, mtime time.Time) error
	Chmod(path string, mode fs.FileMode) error

	Home() (string, error)
	Join(elem ...string) string
	Dir(path string) string
	Base(path string) string
}

FS is implemented by LocalFS and RemoteFS. Paths are absolute and use the file system's own separator.

type LocalFS

type LocalFS struct{}

LocalFS is the local file system.

func (LocalFS) Base

func (LocalFS) Base(path string) string

func (LocalFS) Chmod

func (LocalFS) Chmod(path string, mode fs.FileMode) error

func (LocalFS) Chtimes

func (LocalFS) Chtimes(path string, mtime time.Time) error

func (LocalFS) Create

func (LocalFS) Create(path string) (io.WriteCloser, error)

func (LocalFS) Dir

func (LocalFS) Dir(path string) string

func (LocalFS) Home

func (LocalFS) Home() (string, error)

func (LocalFS) Join

func (LocalFS) Join(elem ...string) string

func (LocalFS) Mkdir

func (LocalFS) Mkdir(path string) error

func (LocalFS) MkdirAll

func (LocalFS) MkdirAll(path string) error

func (LocalFS) Name

func (LocalFS) Name() string

func (LocalFS) Open

func (LocalFS) Open(path string) (io.ReadCloser, error)

func (LocalFS) ReadDir

func (l LocalFS) ReadDir(path string) ([]Entry, error)

func (LocalFS) Remote

func (LocalFS) Remote() bool

func (LocalFS) Remove

func (LocalFS) Remove(path string) error

func (LocalFS) Rename

func (LocalFS) Rename(from, to string) error

func (LocalFS) Stat

func (l LocalFS) Stat(path string) (Entry, error)

type RemoteFS

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

RemoteFS is a remote host's file system over SFTP. Paths are POSIX.

func NewRemoteFS

func NewRemoteFS(name string, c *sftp.Client, closer func() error) *RemoteFS

NewRemoteFS wraps an SFTP client. closer (optional) is called by Close after the client is closed, e.g. to reap the ssh process.

func (*RemoteFS) Base

func (r *RemoteFS) Base(p string) string

func (*RemoteFS) Chmod

func (r *RemoteFS) Chmod(p string, mode fs.FileMode) error

func (*RemoteFS) Chtimes

func (r *RemoteFS) Chtimes(p string, mtime time.Time) error

func (*RemoteFS) Close

func (r *RemoteFS) Close() error

Close ends the SFTP session.

func (*RemoteFS) Create

func (r *RemoteFS) Create(p string) (io.WriteCloser, error)

Create returns the *sftp.File itself so io.Copy can use its concurrent ReadFrom.

func (*RemoteFS) Dir

func (r *RemoteFS) Dir(p string) string

func (*RemoteFS) Home

func (r *RemoteFS) Home() (string, error)

func (*RemoteFS) Join

func (r *RemoteFS) Join(elem ...string) string

func (*RemoteFS) Mkdir

func (r *RemoteFS) Mkdir(p string) error

func (*RemoteFS) MkdirAll

func (r *RemoteFS) MkdirAll(p string) error

func (*RemoteFS) Name

func (r *RemoteFS) Name() string

func (*RemoteFS) Open

func (r *RemoteFS) Open(p string) (io.ReadCloser, error)

Open returns the *sftp.File itself so io.Copy can use its concurrent WriteTo.

func (*RemoteFS) ReadDir

func (r *RemoteFS) ReadDir(p string) ([]Entry, error)

func (*RemoteFS) RealPath

func (r *RemoteFS) RealPath(p string) (string, error)

RealPath resolves p (e.g. "~/site" or a relative path) on the server.

func (*RemoteFS) Remote

func (r *RemoteFS) Remote() bool

func (*RemoteFS) Remove

func (r *RemoteFS) Remove(p string) error

func (*RemoteFS) Rename

func (r *RemoteFS) Rename(from, to string) error

Rename replaces the destination atomically when the server supports the posix-rename extension (OpenSSH does), and falls back to remove+rename.

func (*RemoteFS) Resolve

func (r *RemoteFS) Resolve(p string) (string, error)

Resolve turns a user-supplied remote path into an absolute one: "" and "~" are the login directory, "~/x" and relative paths are under it.

func (*RemoteFS) Stat

func (r *RemoteFS) Stat(p string) (Entry, error)

type SortBy

type SortBy int

SortBy is a directory listing order.

const (
	SortName SortBy = iota
	SortSize
	SortTime
)

func (SortBy) String

func (s SortBy) String() string

Directories

Path Synopsis
Package vfstest provides an in-process SFTP-backed vfs.RemoteFS for tests.
Package vfstest provides an in-process SFTP-backed vfs.RemoteFS for tests.

Jump to

Keyboard shortcuts

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