remotefs

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2020 License: MIT Imports: 15 Imported by: 73

Documentation

Index

Constants

View Source
const (
	StatCmd           = "stat"
	LstatCmd          = "lstat"
	ReadlinkCmd       = "readlink"
	MkdirCmd          = "mkdir"
	MkdirAllCmd       = "mkdirall"
	RemoveCmd         = "remove"
	RemoveAllCmd      = "removeall"
	LinkCmd           = "link"
	SymlinkCmd        = "symlink"
	LchmodCmd         = "lchmod"
	LchownCmd         = "lchown"
	MknodCmd          = "mknod"
	MkfifoCmd         = "mkfifo"
	OpenFileCmd       = "openfile"
	ReadFileCmd       = "readfile"
	WriteFileCmd      = "writefile"
	ReadDirCmd        = "readdir"
	ResolvePathCmd    = "resolvepath"
	ExtractArchiveCmd = "extractarchive"
	ArchivePathCmd    = "archivepath"
)

Name of the commands when called from the cli context (remotefs <CMD> ...)

View Source
const (
	// Read request command.
	Read uint32 = iota
	// Write request command.
	Write
	// Seek request command.
	Seek
	// Close request command.
	Close
	// CmdOK is a response meaning request succeeded.
	CmdOK
	// CmdFailed is a response meaning request failed.
	CmdFailed
)
View Source
const RemotefsCmd = "remotefs"

RemotefsCmd is the name of the remotefs meta command

Variables

View Source
var Commands = map[string]Func{
	StatCmd:           Stat,
	LstatCmd:          Lstat,
	ReadlinkCmd:       Readlink,
	MkdirCmd:          Mkdir,
	MkdirAllCmd:       MkdirAll,
	RemoveCmd:         Remove,
	RemoveAllCmd:      RemoveAll,
	LinkCmd:           Link,
	SymlinkCmd:        Symlink,
	LchmodCmd:         Lchmod,
	LchownCmd:         Lchown,
	MknodCmd:          Mknod,
	MkfifoCmd:         Mkfifo,
	OpenFileCmd:       OpenFile,
	ReadFileCmd:       ReadFile,
	WriteFileCmd:      WriteFile,
	ReadDirCmd:        ReadDir,
	ResolvePathCmd:    ResolvePath,
	ExtractArchiveCmd: ExtractArchive,
	ArchivePathCmd:    ArchivePath,
}

Commands provide a string -> remotefs function mapping. This is useful for commandline programs that will receive a string as the function to execute.

View Source
var ErrInvalid = errors.New("invalid arguments")

ErrInvalid is returned if the parameters are invalid

View Source
var ErrUnknown = errors.New("unkown command")

ErrUnknown is returned for an unknown remotefs command

Functions

func ArchivePath

func ArchivePath(in io.Reader, out io.Writer, args []string) error

ArchivePath archives the given directory and writes it to out. Args: - in = size of json | json of archive.TarOptions - args[0] = source directory name Out: - out = tar file of the archive

func ExportedToError

func ExportedToError(ee *ExportedError) error

ExportedToError will convert a ExportedError to an error. It will try to match the error to any existing known error like os.ErrNotExist. Otherwise, it will just return an implementation of the error interface.

func ExtractArchive

func ExtractArchive(in io.Reader, out io.Writer, args []string) error

ExtractArchive extracts the archive read from in. Args: - in = size of json | json of archive.TarOptions | input tar stream - args[0] = extract directory name

func Lchmod

func Lchmod(in io.Reader, out io.Writer, args []string) error

Lchmod changes permission of the given file without following symlinks Args:

  • args[0] = path
  • args[1] = permission mode in octal (like 0755)

func Lchown

func Lchown(in io.Reader, out io.Writer, args []string) error

Lchown works like os.Lchown Args:

  • args[0] = path
  • args[1] = uid in base 10
  • args[2] = gid in base 10
func Link(in io.Reader, out io.Writer, args []string) error

Link works like os.Link Args:

  • args[0] = old path name (link source)
  • args[1] = new path name (link dest)

func Lstat

func Lstat(in io.Reader, out io.Writer, args []string) error

Lstat functions like os.Lstat. Args: - args[0] is the path Out: - out = FileInfo object

func Mkdir

func Mkdir(in io.Reader, out io.Writer, args []string) error

Mkdir works like os.Mkdir Args: - args[0] is the path - args[1] is the permissions in octal (like 0755)

func MkdirAll

func MkdirAll(in io.Reader, out io.Writer, args []string) error

MkdirAll works like os.MkdirAll. Args: - args[0] is the path - args[1] is the permissions in octal (like 0755)

func Mkfifo

func Mkfifo(in io.Reader, out io.Writer, args []string) error

Mkfifo creates a FIFO special file with the given path name and permissions Args:

  • args[0] = path
  • args[1] = permission mode in octal (like 0755)

func Mknod

func Mknod(in io.Reader, out io.Writer, args []string) error

Mknod works like syscall.Mknod Args:

  • args[0] = path
  • args[1] = permission mode in octal (like 0755)
  • args[2] = major device number in base 10
  • args[3] = minor device number in base 10

func OpenFile added in v0.3.3

func OpenFile(in io.Reader, out io.Writer, args []string) (err error)

OpenFile works like os.OpenFile. To manage the file pointer state, this function acts as a single file "file server" with Read/Write/Close being serialized control codes from in. Args:

  • args[0] = path
  • args[1] = flag in base 10
  • args[2] = permission mode in octal (like 0755)

func ReadDir

func ReadDir(in io.Reader, out io.Writer, args []string) error

ReadDir works like *os.File.Readdir but instead writes the result to a writer Args:

  • args[0] = path
  • args[1] = number of directory entries to return. If <= 0, return all entries in directory

func ReadFile

func ReadFile(in io.Reader, out io.Writer, args []string) error

ReadFile works like ioutil.ReadFile but instead writes the file to a writer Args:

  • args[0] = path

Out:

  • Write file contents to out

func ReadTarOptions

func ReadTarOptions(r io.Reader) (*archive.TarOptions, error)

ReadTarOptions reads from the specified reader and deserializes an archive.TarOptions struct.

func Readlink(in io.Reader, out io.Writer, args []string) error

Readlink works like os.Readlink In:

  • args[0] is path

Out:

  • Write link result to out

func Remove

func Remove(in io.Reader, out io.Writer, args []string) error

Remove works like os.Remove Args:

  • args[0] is the path

func RemoveAll

func RemoveAll(in io.Reader, out io.Writer, args []string) error

RemoveAll works like os.RemoveAll Args:

  • args[0] is the path

func ResolvePath

func ResolvePath(in io.Reader, out io.Writer, args []string) error

ResolvePath works like docker's symlink.FollowSymlinkInScope. It takens in a `path` and a `root` and evaluates symlinks in `path` as if they were scoped in `root`. `path` must be a child path of `root`. In other words, `path` must have `root` as a prefix. Example: path=/foo/bar -> /baz root=/foo, Expected result = /foo/baz

Args: - args[0] is `path` - args[1] is `root` Out: - Write resolved path to stdout

func Stat

func Stat(in io.Reader, out io.Writer, args []string) error

Stat functions like os.Stat. Args: - args[0] is the path Out: - out = FileInfo object

func Symlink(in io.Reader, out io.Writer, args []string) error

Symlink works like os.Symlink Args:

  • args[0] = old path name (link source)
  • args[1] = new path name (link dest)

func WriteError

func WriteError(err error, out io.Writer) error

WriteError is an utility function that serializes the error and writes it to the output writer.

func WriteFile

func WriteFile(in io.Reader, out io.Writer, args []string) error

WriteFile works like ioutil.WriteFile but instead reads the file from a reader Args:

  • args[0] = path
  • args[1] = permission mode in octal (like 0755)
  • input data stream from in

func WriteFileHeader added in v0.3.3

func WriteFileHeader(w io.Writer, hdr *FileHeader, extraData []byte) error

WriteFileHeader serializes a FileHeader and writes it to w, along with any extra data

func WriteTarOptions

func WriteTarOptions(w io.Writer, opts *archive.TarOptions) error

WriteTarOptions serializes a archive.TarOptions struct and writes it to the writer.

Types

type ExportedError

type ExportedError struct {
	ErrString string
	ErrNum    int `json:",omitempty"`
}

ExportedError is the serialized version of the a Go error. It also provides a trivial implementation of the error interface.

func ReadError

func ReadError(in io.Reader) (*ExportedError, error)

ReadError is an utility function that reads a serialized error from the given reader and deserializes it.

func (*ExportedError) Error

func (ee *ExportedError) Error() string

Error returns an error string

type FileHeader added in v0.3.3

type FileHeader struct {
	Cmd  uint32
	Size uint64
}

FileHeader is a header for remote *os.File operations for remotefs.OpenFile

func ReadFileHeader added in v0.3.3

func ReadFileHeader(r io.Reader) (*FileHeader, error)

ReadFileHeader reads from r and returns a deserialized FileHeader

type FileInfo

type FileInfo struct {
	NameVar    string
	SizeVar    int64
	ModeVar    os.FileMode
	ModTimeVar int64 // Serialization of time.Time breaks in travis, so use an int
	IsDirVar   bool
}

FileInfo is the stat struct returned by the remotefs system. It fulfills the os.FileInfo interface.

func (*FileInfo) IsDir

func (f *FileInfo) IsDir() bool

IsDir returns the is-directory indicator from a FileInfo structure

func (*FileInfo) ModTime

func (f *FileInfo) ModTime() time.Time

ModTime returns the modification time from a FileInfo structure

func (*FileInfo) Mode

func (f *FileInfo) Mode() os.FileMode

Mode returns the mode from a FileInfo structure

func (*FileInfo) Name

func (f *FileInfo) Name() string

Name returns the filename from a FileInfo structure

func (*FileInfo) Size

func (f *FileInfo) Size() int64

Size returns the size from a FileInfo structure

func (*FileInfo) Sys

func (f *FileInfo) Sys() interface{}

Sys provides an interface to a FileInfo structure

type Func

type Func func(stdin io.Reader, stdout io.Writer, args []string) error

Func is the function definition for a generic remote fs function The input to the function is any serialized structs / data from in and the string slice from args. The output of the function will be serialized and written to out.

type SeekHeader added in v0.3.3

type SeekHeader struct {
	Offset int64
	Whence int32
}

SeekHeader is header for the Seek operation for remotefs.OpenFile

Jump to

Keyboard shortcuts

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