filesystem

package
v0.0.0-...-938d447 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Directory

type Directory interface {
	// Enter creates a derived directory handle for a subdirectory
	// of the current subtree.
	Enter(name string) (Directory, error)
	// Close any resources associated with the current directory.
	Close() error

	// Link is the equivalent of os.Link().
	Link(oldName string, newDirectory Directory, newName string) error
	// Lstat is the equivalent of os.Lstat().
	Lstat(name string) (FileInfo, error)
	// Mkdir is the equivalent of os.Mkdir().
	Mkdir(name string, perm os.FileMode) error
	// OpenFile is the equivalent of os.OpenFile().
	OpenFile(name string, flag int, perm os.FileMode) (File, error)
	// ReadDir is the equivalent of ioutil.ReadDir().
	ReadDir() ([]FileInfo, error)
	// Readlink is the equivalent of os.Readlink().
	Readlink(name string) (string, error)
	// Remove is the equivalent of os.Remove().
	Remove(name string) error
	// RemoveAll is the equivalent of os.RemoveAll().
	RemoveAll(name string) error
	// RemoveAllChildren empties out a directory, without removing
	// the directory itself.
	RemoveAllChildren() error
	// Symlink is the equivalent of os.Symlink().
	Symlink(oldName string, newName string) error
}

Directory is an abstraction for accessing a subtree of the file system. Each of the functions should be implemented in such a way that they reject access to data stored outside of the subtree. This allows for safe, race-free traversal of the file system.

By placing this in a separate interface, it's easier to stub out file system handling as part of unit tests entirely.

func NewLocalDirectory

func NewLocalDirectory(path string) (Directory, error)

NewLocalDirectory creates a directory handle that corresponds to a local path on the system.

type File

type File interface {
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	io.WriterAt
}

File is an interface for the operations that are applied on regular files opened through Directory.OpenFile().

type FileInfo

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

FileInfo is a subset of os.FileInfo, only containing the features used by the Buildbarn codebase.

func NewFileInfo

func NewFileInfo(name string, fileType FileType) FileInfo

NewFileInfo constructs a FileInfo object that returns fixed values for its methods.

func (*FileInfo) Name

func (fi *FileInfo) Name() string

Name returns the filename of the file.

func (*FileInfo) Type

func (fi *FileInfo) Type() FileType

Type returns the type of a file (e.g., regular file, directory, symlink).

type FileType

type FileType int

FileType is an enumeration of the type of a file stored on a file system.

const (
	// FileTypeRegularFile means the file is a regular file that is
	// not executable.
	FileTypeRegularFile FileType = iota
	// FileTypeExecutableFile means the file is a regular file that
	// is executable.
	FileTypeExecutableFile
	// FileTypeDirectory means the file is a directory.
	FileTypeDirectory
	// FileTypeSymlink means the file is a symbolic link.
	FileTypeSymlink
	// FileTypeOther means the file is neither a regular file, a
	// directory or symbolic link.
	FileTypeOther
)

Jump to

Keyboard shortcuts

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