fs

package
v3.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2019 License: Apache-2.0 Imports: 10 Imported by: 8

Documentation

Overview

Package fs provides a file system abstraction layer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RPath added in v3.3.0

func RPath(elem ...string) string

RPath returns a rooted path, e.g. "/hey/foo" as opposed to "hey/foo".

Types

type ConfirmedDir

type ConfirmedDir string

ConfirmedDir is a clean, absolute, delinkified path that was confirmed to point to an existing directory.

func NewTmpConfirmedDir

func NewTmpConfirmedDir() (ConfirmedDir, error)

NewTmpConfirmedDir returns a temporary dir, else error. The directory is cleaned, no symlinks, etc. so it's returned as a ConfirmedDir.

func (ConfirmedDir) HasPrefix

func (d ConfirmedDir) HasPrefix(path ConfirmedDir) bool

HasPrefix returns true if the directory argument is a prefix of self (d) from the point of view of a file system.

I.e., it's true if the argument equals or contains self (d) in a file path sense.

HasPrefix emulates the semantics of strings.HasPrefix such that the following are true:

strings.HasPrefix("foobar", "foobar")
strings.HasPrefix("foobar", "foo")
strings.HasPrefix("foobar", "")

d := fSys.ConfirmDir("/foo/bar")
d.HasPrefix("/foo/bar")
d.HasPrefix("/foo")
d.HasPrefix("/")

Not contacting a file system here to check for actual path existence.

This is tested on linux, but will have trouble on other operating systems. TODO(monopole) Refactor when #golang/go/18358 closes. See also:

https://github.com/golang/go/issues/18358
https://github.com/golang/dep/issues/296
https://github.com/golang/dep/blob/master/internal/fs/fs.go#L33
https://codereview.appspot.com/5712045

func (ConfirmedDir) Join

func (d ConfirmedDir) Join(path string) string

func (ConfirmedDir) String

func (d ConfirmedDir) String() string

type File

type File interface {
	io.ReadWriteCloser
	Stat() (os.FileInfo, error)
}

File groups the basic os.File methods.

type FileSystem

type FileSystem interface {
	// Create a file.
	Create(name string) (File, error)
	// MkDir makes a directory.
	Mkdir(path string) error
	// MkDir makes a directory path, creating intervening directories.
	MkdirAll(path string) error
	// RemoveAll removes path and any children it contains.
	RemoveAll(path string) error
	// Open opens the named file for reading.
	Open(path string) (File, error)
	// IsDir returns true if the path is a directory.
	IsDir(path string) bool
	// CleanedAbs converts the given path into a
	// directory and a file name, where the directory
	// is represented as a ConfirmedDir and all that implies.
	// If the entire path is a directory, the file component
	// is an empty string.
	CleanedAbs(path string) (ConfirmedDir, string, error)
	// Exists is true if the path exists in the file system.
	Exists(path string) bool
	// Glob returns the list of matching files
	Glob(pattern string) ([]string, error)
	// ReadFile returns the contents of the file at the given path.
	ReadFile(path string) ([]byte, error)
	// WriteFile writes the data to a file at the given path.
	WriteFile(path string, data []byte) error
	// Walk walks the file system with the given WalkFunc.
	Walk(path string, walkFn filepath.WalkFunc) error
}

FileSystem groups basic os filesystem methods.

func MakeFsInMemory added in v3.3.0

func MakeFsInMemory() FileSystem

MakeFsInMemory returns an instance of fsInMemory with no files in it.

func MakeFsOnDisk added in v3.3.0

func MakeFsOnDisk() FileSystem

MakeFsOnDisk makes an instance of fsOnDisk.

Jump to

Keyboard shortcuts

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