posixfs

package
v0.0.0-...-36bb858 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2023 License: MPL-2.0 Imports: 13 Imported by: 17

Documentation

Index

Constants

View Source
const (
	O_RDONLY = os.O_RDONLY
	O_WRONLY = os.O_WRONLY
	O_EXCL   = os.O_EXCL
	O_APPEND = os.O_APPEND
	O_CREATE = os.O_CREATE
	O_TRUNC  = os.O_TRUNC
)
View Source
const Sep = "/"

Variables

View Source
var (
	ErrExist    = gofs.ErrExist
	ErrNotExist = gofs.ErrNotExist
	ErrClosed   = gofs.ErrClosed
)

Functions

func AppendFile

func AppendFile(ctx context.Context, fs FS, p string, perm os.FileMode, data []byte) error

func DeleteFile

func DeleteFile(ctx context.Context, fs FS, p string) error

DeleteFile is an idempotent delete operation. It calls remove, but does not error if the path is already gone

func IsErrExist

func IsErrExist(err error) bool

func IsErrNotExist

func IsErrNotExist(err error) bool

func MkdirAll

func MkdirAll(x FS, p string, perm FileMode) error

MkdirAll creates all of the directories from the root of x, down to p

func PutFile

func PutFile(ctx context.Context, fs FS, p string, perm os.FileMode, r io.Reader) error

PutFile opens the file in fs at path p, truncates it, and writes from r until io.EOF

func ReadFile

func ReadFile(ctx context.Context, fs FS, p string) ([]byte, error)

ReadFile reads an entire file into memory and returns it.

func WalkLeaves

func WalkLeaves(ctx context.Context, x FS, p string, fn func(string, DirEnt) error) error

WalkLeaves walks fsx starting at path p, and calls fn for every non-dir file encountered. The first argument to fn will be the path of the file. The second argument to fn will be its DirEnt in its immediate parent in the walk.

func WalkLeavesSpan

func WalkLeavesSpan(ctx context.Context, x FS, p string, span state.Span[string], fn func(string, DirEnt) error) error

WalkLeavesSpan walks the leaves in x which are contained in the span. WalkLeavesSpan emits paths in sorted order.

Types

type DirEnt

type DirEnt struct {
	Name string
	Mode FileMode
}

func ReadDir

func ReadDir(fs FS, p string) ([]DirEnt, error)

ReadDir returns all the children of the directory at p

type ErrReadOnly

type ErrReadOnly struct {
	Op string
}

ErrReadOnly is returns by ReadOnly when an operation would mutate the underlying filesystem

func (ErrReadOnly) Error

func (e ErrReadOnly) Error() string

type FS

type FS interface {
	OpenFile(p string, flag int, perm os.FileMode) (File, error)
	Mkdir(p string, perm os.FileMode) error
	Rmdir(p string) error
	Remove(p string) error
	Rename(oldPath, newPath string) error
	Stat(p string) (FileInfo, error)
	Symlink(target, link string) error
}

func NewDirFS

func NewDirFS(p string) FS

NewDirFS creates an OS backed FS rooted at p

func NewFiltered

func NewFiltered(x FS, predicate func(string) bool) FS

NewFiltered returns a filesystem with some paths filtered.

func NewOSFS

func NewOSFS() FS

NewOSFS creates a new filesystem backed by the operating system

func NewPrefixed

func NewPrefixed(x FS, prefix string) FS

func NewTestFS

func NewTestFS(t testing.TB) FS

type File

type File interface {
	Stat() (FileInfo, error)
	Sync() error
	io.Closer
	io.Reader
	io.Writer
	io.Seeker

	ReadDir(n int) ([]DirEnt, error)
}

type FileInfo

type FileInfo = gofs.FileInfo

type FileMode

type FileMode = gofs.FileMode

type ReadOnly

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

ReadOnly is a read only filesystem

func NewReadOnly

func NewReadOnly(x FS) ReadOnly

NewReadOnly returns a version of x which is read only

func (ReadOnly) Mkdir

func (fs ReadOnly) Mkdir(p string, perm os.FileMode) error

func (ReadOnly) OpenFile

func (fs ReadOnly) OpenFile(p string, flags int, mode FileMode) (File, error)

func (ReadOnly) Remove

func (fs ReadOnly) Remove(p string) error

func (ReadOnly) Rename

func (fs ReadOnly) Rename(oldPath, newPath string) error

func (ReadOnly) Rmdir

func (fs ReadOnly) Rmdir(p string) error

func (ReadOnly) Stat

func (fs ReadOnly) Stat(p string) (FileInfo, error)
func (fs ReadOnly) Symlink(oldp, newp string) error

Jump to

Keyboard shortcuts

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