Documentation
¶
Overview ¶
Package transfer packs a folder for copying between machines and unpacks it at the other end, and picks the name a copy lands under. Both ends use it: the server for fs.upload and fs.download, the client for the same from this side.
An archive is gzipped tar with paths relative to the folder packed — no top folder of its own, since the receiving end decides what the copy is called. Unpacking takes the archive as untrusted: a sandbox is somebody else's machine, and what comes from it must not write outside the folder it was asked into.
Index ¶
- func FreeName(dir, name string) string
- func FreeNameFS(fsys FS, dir, name string) string
- func Pack(w io.Writer, src string) error
- func PackFS(w io.Writer, fsys FS, src string) error
- func SafeName(name string) string
- func Unpack(r io.Reader, dest string, replace bool) error
- func UnpackFS(r io.Reader, fsys FS, dest string, replace bool) error
- type FS
- type File
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FreeName ¶
FreeName is name in dir, or when that is taken the first of "name 2", "name 3", … that is not, keeping the extension: a copy never lands on something already there unless asked to.
func FreeNameFS ¶
FreeNameFS is FreeName for a folder in fsys.
func Pack ¶
Pack writes the folder src to w as a gzipped tar: folders, files and symlinks (as links, never followed). Sockets, devices and the like are left out.
func SafeName ¶
SafeName makes a name from the other end safe to create here: its last path element, without control characters, and never empty, "." or "..".
func Unpack ¶
Unpack extracts an archive Pack wrote into dest, which must exist. With replace, files already there are written over (folders are merged); without it, a name that is taken is an error. Nothing is written outside dest: a path that leaves it is refused, and so is going through a symlink, since one could lead anywhere.
Types ¶
type FS ¶
type FS interface {
Stat(name string) (fs.FileInfo, error)
Lstat(name string) (fs.FileInfo, error)
// ReadDir is a folder's entries as Lstat sees them, sorted by name.
ReadDir(name string) ([]fs.FileInfo, error)
// Open is a file to read. It must not wait on a fifo.
Open(name string) (File, error)
// Create makes a new file to write, refusing a name already taken.
Create(name string, perm fs.FileMode) (File, error)
Mkdir(name string, perm fs.FileMode) error
Chmod(name string, mode fs.FileMode) error
// Rename moves oldname to newname, replacing a file already there.
Rename(oldname, newname string) error
Remove(name string) error
RemoveAll(name string) error
Symlink(target, name string) error
Readlink(name string) (string, error)
// Home is where ~ is.
Home() (string, error)
}
FS is the files a copy reads and writes: this machine's (Local), or a host's that a terminal is logged in to, through sftp. It is what the two have in common, with paths always slash-separated and absolute — conch runs on macOS and Linux, and sftp speaks POSIX paths.
var Local FS = localFS{}
Local is this machine's files.