driver

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: Apache-2.0 Imports: 8 Imported by: 384

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupported = fmt.Errorf("not supported")

Functions

func ReadDir

func ReadDir(r Driver, dirname string) ([]os.FileInfo, error)

ReadDir works the same as ioutil.ReadDir with the Driver abstraction

func ReadFile

func ReadFile(r Driver, filename string) ([]byte, error)

ReadFile works the same as os.ReadFile with the Driver abstraction

func WriteFile

func WriteFile(r Driver, filename string, data []byte, perm os.FileMode) error

WriteFile works the same as os.WriteFile with the Driver abstraction

Types

type DeviceInfoDriver

type DeviceInfoDriver interface {
	DeviceInfo(fi os.FileInfo) (maj uint64, min uint64, err error)
}

type Driver

type Driver interface {
	// Note that Open() returns a File interface instead of *os.File. This
	// is because os.File is a struct, so if Open was to return *os.File,
	// the only way to fulfill the interface would be to call os.Open()
	Open(path string) (File, error)
	OpenFile(path string, flag int, perm os.FileMode) (File, error)

	Stat(path string) (os.FileInfo, error)
	Lstat(path string) (os.FileInfo, error)
	Readlink(p string) (string, error)
	Mkdir(path string, mode os.FileMode) error
	Remove(path string) error

	Link(oldname, newname string) error
	Lchmod(path string, mode os.FileMode) error
	Lchown(path string, uid, gid int64) error
	Symlink(oldname, newname string) error

	MkdirAll(path string, perm os.FileMode) error
	RemoveAll(path string) error

	// TODO(aaronl): These methods might move outside the main Driver
	// interface in the future as more platforms are added.
	Mknod(path string, mode os.FileMode, major int, minor int) error
	Mkfifo(path string, mode os.FileMode) error
}

Driver provides all of the system-level functions in a common interface. The context should call these with full paths and should never use the `os` package or any other package to access resources on the filesystem. This mechanism let's us carefully control access to the context and maintain path and resource integrity. It also gives us an interface to reason about direct resource access.

Implementations don't need to do much other than meet the interface. For example, it is not required to wrap os.FileInfo to return correct paths for the call to Name().

var LocalDriver Driver = &driver{}

LocalDriver is the exported Driver struct for convenience.

func NewSystemDriver

func NewSystemDriver() (Driver, error)

type File

type File interface {
	io.ReadWriteCloser
	io.Seeker
	Readdir(n int) ([]os.FileInfo, error)
}

File is the interface for interacting with files returned by continuity's Open This is needed since os.File is a struct, instead of an interface, so it can't be used.

type LXAttrDriver

type LXAttrDriver interface {
	// LGetxattr returns all of the extended attributes for the file at path
	// and does not follow symlinks. Typically, this takes a syscall call to
	// Llistxattr and Lgetxattr.
	LGetxattr(path string) (map[string][]byte, error)

	// LSetxattr sets all of the extended attributes on file at path, without
	// following symbolic links. All attributes on the target are replaced by
	// the values from attr. If the operation fails to set any attribute,
	// those already applied will not be rolled back.
	LSetxattr(path string, attr map[string][]byte) error
}

LXAttrDriver should be implemented by drivers on operating systems and filesystems that support setting and getting extended attributes on symbolic links. If this is not implemented, extended attributes will be ignored on symbolic links.

type XAttrDriver

type XAttrDriver interface {
	// Getxattr returns all of the extended attributes for the file at path.
	// Typically, this takes a syscall call to Listxattr and Getxattr.
	Getxattr(path string) (map[string][]byte, error)

	// Setxattr sets all of the extended attributes on file at path, following
	// any symbolic links, if necessary. All attributes on the target are
	// replaced by the values from attr. If the operation fails to set any
	// attribute, those already applied will not be rolled back.
	Setxattr(path string, attr map[string][]byte) error
}

XAttrDriver should be implemented on operation systems and filesystems that have xattr support for regular files and directories.

Jump to

Keyboard shortcuts

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