fs

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package fs implements blob store structures for representing files and directories.

Index

Constants

This section is empty.

Variables

Functions

This section is empty.

Types

type Dir

type Dir schema.Map

Dir is a directory of files, symlinks, and subdirs. It is implemented as a schema.Map, with each key the name of the entry and each payload a serialized Dirent.

func NewDir

func NewDir() *Dir

NewDir produces a new, blank Dir, not yet written to a blob store.

func (*Dir) Add

func (d *Dir) Add(ctx context.Context, store bs.Store, path string) (bs.Ref, error)

Add adds the file, symlink, or dir at path to d. If path is a dir, this is recursive. It returns the possibly-updated Ref for d.

func (*Dir) AddDir

func (d *Dir) AddDir(ctx context.Context, store bs.Store, path string) (bs.Ref, error)

AddDir adds the members of the directory at path to d, recursively.

func (*Dir) Dirent

func (d *Dir) Dirent(ctx context.Context, g bs.Getter, name string) (*Dirent, error)

Dirent finds the entry in d with the given name. It returns nil if no such entry exists. It does not traverse subdirs, and name must not be a multi-segment path. For that, use Find. Note: Dirent does not understand "." and "..".

func (*Dir) Each

func (d *Dir) Each(ctx context.Context, g bs.Getter, f func(string, *Dirent) error) error

Each calls a callback on each name/Dirent pair in d (in an indeterminate order). If the callback returns an error, Each exits with that error.

func (*Dir) Find

func (d *Dir) Find(ctx context.Context, g bs.Getter, path string) (*Dirent, error)

Find resolves a path starting at d, traversing into subdirs as appropriate, and returning the entry found at the end of path. It does not resolve symlinks in its traversal. Leading path separators in `path` are ignored; traversal is always relative to d. Note: Find does not understand "." and "..".

func (*Dir) Load

func (d *Dir) Load(ctx context.Context, g bs.Getter, ref bs.Ref) error

Load loads the directory at ref into d.

func (*Dir) Ref

func (d *Dir) Ref() (bs.Ref, error)

Ref returns d's Ref.

func (*Dir) Set

func (d *Dir) Set(ctx context.Context, store bs.Store, name string, dirent *Dirent) (bs.Ref, schema.Outcome, error)

Set sets the given name in d to the given Dirent. It returns the possibly updated Ref of d and the schema.Outcome resulting from the underlying "bs/schema".Map.Set call.

type Dirent

type Dirent struct {
	Mode uint32 `protobuf:"varint,1,opt,name=mode,proto3" json:"mode,omitempty"`
	// If mode indicates this is a Dir,
	// then item is the hex ref of a serialized Dir (i.e., a schema.Map).
	// If it's a symlink,
	// then item is simply the target path.
	// If it's a plain file,
	// then item is the hex ref of the root of a split.Write tree of its contents.
	Item string `protobuf:"bytes,2,opt,name=item,proto3" json:"item,omitempty"`
	// contains filtered or unexported fields
}

func (*Dirent) Descriptor deprecated

func (*Dirent) Descriptor() ([]byte, []int)

Deprecated: Use Dirent.ProtoReflect.Descriptor instead.

func (*Dirent) Dir

func (d *Dirent) Dir(ctx context.Context, g bs.Getter) (*Dir, error)

Dir returns the directory referred to by d. It is an error to call this when !d.IsDir().

func (*Dirent) GetItem

func (x *Dirent) GetItem() string

func (*Dirent) GetMode

func (x *Dirent) GetMode() uint32

func (*Dirent) IsDir

func (d *Dirent) IsDir() bool

IsDir tells whether d refers to a directory.

func (d *Dirent) IsLink() bool

IsLink tells whether d refers to a symlink. If it does, then d.Item is the target of the link.

func (*Dirent) ProtoMessage

func (*Dirent) ProtoMessage()

func (*Dirent) ProtoReflect

func (x *Dirent) ProtoReflect() protoreflect.Message

func (*Dirent) Reset

func (x *Dirent) Reset()

func (*Dirent) Size

func (d *Dirent) Size(ctx context.Context, g bs.Getter) (int64, error)

Size returns the size of the file represented by the given entry. This is 0 for directories and symlinks. TODO: this should not be 0 for directories and symlinks.

func (*Dirent) String

func (x *Dirent) String() string

type FS

type FS struct {
	Ctx context.Context
	// contains filtered or unexported fields
}

FS implements io/fs.FS.

func NewFS

func NewFS(ctx context.Context, g bs.Getter, rootRef bs.Ref) *FS

NewFS created a new *FS reading from the given bs.Getter and rooted at the given ref. The given context object is stored in the FS and used in subsequent calls to Open, Stat, ReadDir, etc. This is an antipattern but acceptable when an object must adhere to a context-free stdlib interface (https://github.com/golang/go/wiki/CodeReviewComments#contexts). Callers may replace the context object during the lifetime of the FS as needed.

func (*FS) Open

func (f *FS) Open(name string) (result fs.File, err error)

Open opens the file at the given path in FS.

TODO: This presently handles only plain files, but should handle directories and symlinks as well.

TODO: Symlinks in the given path should be traversed but are not at the moment.

func (*FS) ReadDir

func (f *FS) ReadDir(name string) (result []fs.DirEntry, err error)

ReadDir implements io/fs.ReadDirFS.

func (*FS) Stat

func (f *FS) Stat(name string) (result fs.FileInfo, err error)

Stat implements io/fs.StatFS.

Jump to

Keyboard shortcuts

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