Documentation
¶
Overview ¶
Package remote is a go-filesystems filesystem served over a connection: Serve answers requests against any filesystem.Filesystem, and New is that filesystem at the other end, with the same interfaces and the same errors.
It keeps the process that touches the files apart from the process that talks to the network -- for go-fileshare/fileshare, a worker running as the person whose files they are, behind a front that holds no privilege. Neither side trusts the other's bytes: every frame and every field in it is bounded before anything is allocated for it.
Index ¶
- Constants
- func Serve(conn io.ReadWriteCloser, fsys filesystem.Filesystem) error
- type Capability
- type Error
- type FS
- func (f *FS) Can(c Capability) bool
- func (f *FS) Chmod(path string, perm os.FileMode) error
- func (f *FS) Chown(path string, uid, gid uint32) error
- func (f *FS) Chtimes(path string, atime, mtime time.Time) error
- func (f *FS) Close() error
- func (f *FS) DeleteDir(path string) error
- func (f *FS) DeleteFile(path string) error
- func (f *FS) Label() string
- func (f *FS) Link(oldPath, newPath string) error
- func (f *FS) ListDir(path string) ([]filesystem.DirEntry, error)
- func (f *FS) MkDir(path string, perm os.FileMode) error
- func (f *FS) OpenFile(path string) (filesystem.File, error)
- func (f *FS) ReadFile(path string) ([]byte, error)
- func (f *FS) ReadLink(path string) (string, error)
- func (f *FS) Rename(oldPath, newPath string) error
- func (f *FS) Stat(path string) (filesystem.Stat, error)
- func (f *FS) Symlink(target, linkPath string) error
- func (f *FS) Truncate(path string, newSize int64) error
- func (f *FS) WriteFile(path string, data []byte, perm os.FileMode) error
Constants ¶
const ( CanLabel = Capability(capLabel) CanSymlink = Capability(capSymlink) CanLink = Capability(capLink) CanTruncate = Capability(capTruncate) CanMetadata = Capability(capMetadata) CanOpen = Capability(capOpen) )
const MaxFrame = 32 << 20
MaxFrame bounds one frame: a ReadFile or WriteFile carries the whole file, so this is also the largest file those two move. Larger ones go through OpenFile, whose reads and writes are split into pieces of maxChunk.
Variables ¶
This section is empty.
Functions ¶
func Serve ¶
func Serve(conn io.ReadWriteCloser, fsys filesystem.Filesystem) error
Serve answers the requests that arrive on conn against fsys, until conn is closed. It sends the hello first, then serves up to maxInFlight requests at once. It never closes fsys -- that is its owner's -- but it closes every file its peer opened and did not close, and conn.
The peer is not trusted: a frame that does not decode, an unknown op, a reply id the server never sent, or a handle that is not open ends the connection or is refused, and nothing a frame says is allocated before it is checked against the bounds above.
Types ¶
type Capability ¶
type Capability uint64
Capability is something a server's filesystem may or may not do.
type Error ¶
type Error struct {
Msg string
// contains filtered or unexported fields
}
Error is an error the server's filesystem returned that was not an errno: its text, and the kinds it was (fs.ErrNotExist, fs.ErrPermission, ...), which errors.Is still recognises.
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS is a filesystem served by Serve at the other end of a connection. It implements filesystem.Filesystem and every optional interface a protocol server looks for -- Opener, Symlinker, HardLinker, Truncater, MetadataSetter, LabelReader. What the server's filesystem does not have answers errors.ErrUnsupported (Label: ""), so a type assertion succeeds where the server's would have failed; Can says what is really there.
Calls may be made from any number of goroutines; each waits for its own reply.
func New ¶
func New(conn io.ReadWriteCloser) (*FS, error)
New is the filesystem served at the other end of conn. It reads the server's hello before returning, so a connection that is not a remote filesystem fails here rather than at the first call.
func (*FS) Can ¶
func (f *FS) Can(c Capability) bool
Can says whether the server's filesystem has c.
func (*FS) Close ¶
Close closes the connection. The server's filesystem stays open -- it is its owner's -- and the files opened through f are closed by the server.
func (*FS) DeleteFile ¶
func (*FS) Label ¶
Label is the server's volume label, or "" when its filesystem has none to read (or the call fails: Label has no error to return).