vfs

package
v0.0.0-...-8b65fed Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: GPL-3.0 Imports: 27 Imported by: 1

Documentation

Index

Constants

View Source
const ModeFileRO = fs.FileMode(0555)

readonly

View Source
const Separator = "/"

Variables

View Source
var ErrNotExist = fs.ErrNotExist
View Source
var ErrNotImplemented = errors.New("not implemented")
View Source
var ErrOsHashLen = errors.New("oshash: buffer length must be a multiple of 8")

Functions

func AbsPath

func AbsPath(p string) string

func AddTrailSlash

func AddTrailSlash(p string) string

func IsRoot

func IsRoot(filename string) bool

func ListDirFromFiles

func ListDirFromFiles[F File](m map[string]F, name string) ([]fs.DirEntry, error)

func ListDirFromInfo

func ListDirFromInfo(m map[string]fs.FileInfo, name string) ([]fs.DirEntry, error)

func NewDirInfo

func NewDirInfo(name string, modTime time.Time) *fileInfo

func NewFileInfo

func NewFileInfo(name string, size int64, modTime time.Time) *fileInfo

func OnceValueWOErr

func OnceValueWOErr[T any](f func() (T, error)) func() (T, error)

OnceValueWOErr returns a function that invokes f only once and returns the value returned by f . The returned function may be called concurrently.

If f panics, the returned function will panic with the same value on every call.

func RelPath

func RelPath(p string) string

func RemoveTrailingSlash

func RemoveTrailingSlash(p string) string

func Walk

func Walk(ctx context.Context, vfs Filesystem, root string, walkFn filepath.WalkFunc) error

Types

type CtxBillyFile

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

func NewCtxBillyFile

func NewCtxBillyFile(info fs.FileInfo, bf ctxbilly.File) *CtxBillyFile

func (*CtxBillyFile) Close

func (c *CtxBillyFile) Close(ctx context.Context) error

Close implements File.

func (*CtxBillyFile) Info

func (c *CtxBillyFile) Info() (fs.FileInfo, error)

Info implements File.

func (*CtxBillyFile) IsDir

func (c *CtxBillyFile) IsDir() bool

IsDir implements File.

func (*CtxBillyFile) Name

func (c *CtxBillyFile) Name() string

Name implements File.

func (*CtxBillyFile) Read

func (c *CtxBillyFile) Read(ctx context.Context, p []byte) (n int, err error)

Read implements File.

func (*CtxBillyFile) ReadAt

func (c *CtxBillyFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

ReadAt implements File.

func (*CtxBillyFile) Seek

func (c *CtxBillyFile) Seek(offset int64, whence int) (int64, error)

Seek implements File.

func (*CtxBillyFile) Size

func (c *CtxBillyFile) Size() int64

Size implements File.

func (*CtxBillyFile) Type

func (c *CtxBillyFile) Type() fs.FileMode

Type implements File.

type CtxBillyFs

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

func NewCtxBillyFs

func NewCtxBillyFs(name string, fs ctxbilly.Filesystem) *CtxBillyFs

func (*CtxBillyFs) Info

func (c *CtxBillyFs) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*CtxBillyFs) IsDir

func (c *CtxBillyFs) IsDir() bool

IsDir implements Filesystem.

func (*CtxBillyFs) Name

func (c *CtxBillyFs) Name() string

Name implements Filesystem.

func (*CtxBillyFs) Open

func (c *CtxBillyFs) Open(ctx context.Context, filename string) (File, error)

Open implements Filesystem.

func (*CtxBillyFs) ReadDir

func (c *CtxBillyFs) ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error)

ReadDir implements Filesystem.

func (*CtxBillyFs) Rename

func (c *CtxBillyFs) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*CtxBillyFs) Stat

func (c *CtxBillyFs) Stat(ctx context.Context, filename string) (fs.FileInfo, error)

Stat implements Filesystem.

func (*CtxBillyFs) Type

func (c *CtxBillyFs) Type() fs.FileMode

Type implements Filesystem.

func (c *CtxBillyFs) Unlink(ctx context.Context, filename string) error

Unlink implements Filesystem.

type DefaultFS

type DefaultFS string

func (DefaultFS) Info

func (d DefaultFS) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (DefaultFS) IsDir

func (d DefaultFS) IsDir() bool

IsDir implements Filesystem.

func (DefaultFS) Name

func (d DefaultFS) Name() string

Name implements Filesystem.

func (*DefaultFS) Type

func (d *DefaultFS) Type() fs.FileMode

Type implements Filesystem.

type DummyFile

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

func (*DummyFile) Close

func (d *DummyFile) Close(ctx context.Context) error

func (*DummyFile) Info

func (d *DummyFile) Info() (fs.FileInfo, error)

Stat implements File.

func (*DummyFile) IsDir

func (d *DummyFile) IsDir() bool

func (*DummyFile) Name

func (d *DummyFile) Name() string

Name implements File.

func (*DummyFile) Read

func (d *DummyFile) Read(ctx context.Context, p []byte) (n int, err error)

func (*DummyFile) ReadAt

func (d *DummyFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

func (*DummyFile) Seek

func (d *DummyFile) Seek(offset int64, whence int) (int64, error)

Seek implements File.

func (*DummyFile) Size

func (d *DummyFile) Size() int64

func (*DummyFile) Type

func (d *DummyFile) Type() fs.FileMode

Type implements File.

type DummyFs

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

func (*DummyFs) FsName

func (d *DummyFs) FsName() string

FsName implements Filesystem.

func (*DummyFs) Info

func (d *DummyFs) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*DummyFs) IsDir

func (d *DummyFs) IsDir() bool

IsDir implements Filesystem.

func (*DummyFs) ModTime

func (d *DummyFs) ModTime() time.Time

ModTime implements Filesystem.

func (*DummyFs) Mode

func (d *DummyFs) Mode() fs.FileMode

Mode implements Filesystem.

func (*DummyFs) Name

func (d *DummyFs) Name() string

Name implements Filesystem.

func (*DummyFs) Open

func (d *DummyFs) Open(ctx context.Context, filename string) (File, error)

func (*DummyFs) ReadDir

func (d *DummyFs) ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error)

func (*DummyFs) Rename

func (d *DummyFs) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*DummyFs) Stat

func (*DummyFs) Stat(ctx context.Context, filename string) (fs.FileInfo, error)

Stat implements Filesystem.

func (*DummyFs) Type

func (d *DummyFs) Type() fs.FileMode

Type implements Filesystem.

func (d *DummyFs) Unlink(ctx context.Context, filename string) error

type File

type File interface {
	IsDir() bool
	Size() int64

	fs.DirEntry

	ctxio.Reader
	ctxio.ReaderAt
	ctxio.Closer
	ctxio.Seeker
}

func GetFile

func GetFile[F File](m map[string]F, name string) (File, error)

func NewDirFile

func NewDirFile(name string) File

type Filesystem

type Filesystem interface {
	// Open opens the named file for reading. If successful, methods on the
	// returned file can be used for reading; the associated file descriptor has
	// mode O_RDONLY.
	Open(ctx context.Context, filename string) (File, error)

	// ReadDir reads the directory named by dirname and returns a list of
	// directory entries.
	ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error)

	Stat(ctx context.Context, filename string) (fs.FileInfo, error)
	Unlink(ctx context.Context, filename string) error

	Rename(ctx context.Context, oldpath, newpath string) error

	// As filesystem mounted to some path, make sense to have the filesystem implement DirEntry
	fs.DirEntry
}

type FilesystemPrototype

type FilesystemPrototype string

func (FilesystemPrototype) Info

func (p FilesystemPrototype) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (FilesystemPrototype) IsDir

func (p FilesystemPrototype) IsDir() bool

IsDir implements Filesystem.

func (FilesystemPrototype) Name

func (p FilesystemPrototype) Name() string

Name implements Filesystem.

func (FilesystemPrototype) Type

func (p FilesystemPrototype) Type() fs.FileMode

Type implements Filesystem.

type FsFactory

type FsFactory func(ctx context.Context, sourcePath string, f File) (Filesystem, error)

It factory responsobility to close file

type Hash

type Hash string

func FileHash

func FileHash(ctx context.Context, f File) (Hash, error)

type LazyOsFile

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

func NewLazyOsFile

func NewLazyOsFile(path string) (*LazyOsFile, error)

func (*LazyOsFile) Close

func (f *LazyOsFile) Close(ctx context.Context) error

Close implements File.

func (*LazyOsFile) Info

func (f *LazyOsFile) Info() (fs.FileInfo, error)

func (*LazyOsFile) IsDir

func (f *LazyOsFile) IsDir() bool

IsDir implements File.

func (*LazyOsFile) Name

func (f *LazyOsFile) Name() string

Name implements File.

func (*LazyOsFile) Read

func (f *LazyOsFile) Read(ctx context.Context, p []byte) (n int, err error)

Read implements File.

func (*LazyOsFile) ReadAt

func (f *LazyOsFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

ReadAt implements File.

func (*LazyOsFile) Seek

func (f *LazyOsFile) Seek(offset int64, whence int) (int64, error)

Seek implements File.

func (*LazyOsFile) Size

func (f *LazyOsFile) Size() int64

Size implements File.

func (*LazyOsFile) Type

func (f *LazyOsFile) Type() fs.FileMode

Type implements File.

type LogFS

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

func WrapLogFS

func WrapLogFS(vfs Filesystem) (*LogFS, error)

func (*LogFS) FsName

func (fs *LogFS) FsName() string

func (*LogFS) Info

func (fs *LogFS) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*LogFS) IsDir

func (fs *LogFS) IsDir() bool

IsDir implements Filesystem.

func (*LogFS) ModTime

func (lfs *LogFS) ModTime() time.Time

ModTime implements Filesystem.

func (*LogFS) Mode

func (lfs *LogFS) Mode() fs.FileMode

Mode implements Filesystem.

func (*LogFS) Name

func (fs *LogFS) Name() string

Name implements Filesystem.

func (*LogFS) Open

func (fs *LogFS) Open(ctx context.Context, filename string) (file File, err error)

Open implements Filesystem.

func (*LogFS) ReadDir

func (fs *LogFS) ReadDir(ctx context.Context, path string) (entries []fs.DirEntry, err error)

ReadDir implements Filesystem.

func (*LogFS) Rename

func (lfs *LogFS) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*LogFS) Size

func (lfs *LogFS) Size() int64

Size implements Filesystem.

func (*LogFS) Stat

func (lfs *LogFS) Stat(ctx context.Context, filename string) (info fs.FileInfo, err error)

Stat implements Filesystem.

func (*LogFS) Sys

func (lfs *LogFS) Sys() any

Sys implements Filesystem.

func (*LogFS) Type

func (fs *LogFS) Type() fs.FileMode

Type implements Filesystem.

func (fs *LogFS) Unlink(ctx context.Context, filename string) (err error)

Unlink implements Filesystem.

type LogFile

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

func WrapLogFile

func WrapLogFile(f File, filename string, log *rlog.Logger, timeout time.Duration, tel *fsTelemetry) *LogFile

func (*LogFile) Close

func (f *LogFile) Close(ctx context.Context) (err error)

Close implements File.

func (*LogFile) Info

func (f *LogFile) Info() (fs.FileInfo, error)

Stat implements File.

func (*LogFile) IsDir

func (f *LogFile) IsDir() bool

IsDir implements File.

func (*LogFile) Name

func (f *LogFile) Name() string

Name implements File.

func (*LogFile) Read

func (f *LogFile) Read(ctx context.Context, p []byte) (n int, err error)

Read implements File.

func (*LogFile) ReadAt

func (f *LogFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

ReadAt implements File.

func (*LogFile) Seek

func (f *LogFile) Seek(offset int64, whence int) (int64, error)

Seek implements File.

func (*LogFile) Size

func (f *LogFile) Size() int64

Size implements File.

func (*LogFile) Type

func (f *LogFile) Type() fs.FileMode

Type implements File.

type MemoryFile

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

func NewMemoryFile

func NewMemoryFile(name string, data []byte) *MemoryFile

func (*MemoryFile) Close

func (d *MemoryFile) Close(ctx context.Context) (err error)

func (*MemoryFile) Info

func (d *MemoryFile) Info() (fs.FileInfo, error)

func (*MemoryFile) IsDir

func (d *MemoryFile) IsDir() bool

func (*MemoryFile) Name

func (d *MemoryFile) Name() string

Name implements File.

func (*MemoryFile) Read

func (d *MemoryFile) Read(ctx context.Context, p []byte) (n int, err error)

Read implements File.

func (*MemoryFile) ReadAt

func (d *MemoryFile) ReadAt(ctx context.Context, p []byte, off int64) (n int, err error)

ReadAt implements File.

func (*MemoryFile) Seek

func (d *MemoryFile) Seek(offset int64, whence int) (int64, error)

Seek implements File.

func (*MemoryFile) Size

func (d *MemoryFile) Size() int64

func (*MemoryFile) Type

func (d *MemoryFile) Type() fs.FileMode

Type implements File.

type MemoryFs

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

func NewMemoryFS

func NewMemoryFS(name string, files map[string]*MemoryFile) *MemoryFs

func (*MemoryFs) FsName

func (fs *MemoryFs) FsName() string

FsKind implements Filesystem.

func (*MemoryFs) Info

func (fs *MemoryFs) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*MemoryFs) IsDir

func (fs *MemoryFs) IsDir() bool

IsDir implements Filesystem.

func (*MemoryFs) ModTime

func (mfs *MemoryFs) ModTime() time.Time

ModTime implements Filesystem.

func (*MemoryFs) Mode

func (mfs *MemoryFs) Mode() fs.FileMode

Mode implements Filesystem.

func (*MemoryFs) Name

func (fs *MemoryFs) Name() string

Name implements Filesystem.

func (*MemoryFs) Open

func (m *MemoryFs) Open(ctx context.Context, filename string) (File, error)

func (*MemoryFs) ReadDir

func (fs *MemoryFs) ReadDir(ctx context.Context, path string) ([]fs.DirEntry, error)

func (*MemoryFs) Rename

func (mfs *MemoryFs) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*MemoryFs) Size

func (fs *MemoryFs) Size() int64

Size implements Filesystem.

func (*MemoryFs) Stat

func (mfs *MemoryFs) Stat(ctx context.Context, filename string) (fs.FileInfo, error)

Stat implements Filesystem.

func (*MemoryFs) Sys

func (fs *MemoryFs) Sys() any

Sys implements Filesystem.

func (*MemoryFs) Type

func (mfs *MemoryFs) Type() fs.FileMode

Type implements Filesystem.

func (fs *MemoryFs) Unlink(ctx context.Context, filename string) error

Unlink implements Filesystem.

type OsFS

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

func NewOsFs

func NewOsFs(osDir string) *OsFS

func (*OsFS) Info

func (fs *OsFS) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*OsFS) IsDir

func (fs *OsFS) IsDir() bool

IsDir implements Filesystem.

func (*OsFS) Name

func (fs *OsFS) Name() string

Name implements Filesystem.

func (*OsFS) Open

func (fs *OsFS) Open(ctx context.Context, filename string) (File, error)

Open implements Filesystem.

func (*OsFS) ReadDir

func (o *OsFS) ReadDir(ctx context.Context, dir string) ([]fs.DirEntry, error)

ReadDir implements Filesystem.

func (*OsFS) Rename

func (fs *OsFS) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*OsFS) Stat

func (fs *OsFS) Stat(ctx context.Context, filename string) (fs.FileInfo, error)

Stat implements Filesystem.

func (*OsFS) Type

func (ofs *OsFS) Type() fs.FileMode

Type implements Filesystem.

func (fs *OsFS) Unlink(ctx context.Context, filename string) error

Unlink implements Filesystem.

type Resolver

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

func NewResolver

func NewResolver(factories map[string]FsFactory) *Resolver

func (*Resolver) IsNestedFs

func (r *Resolver) IsNestedFs(f string) bool

func (*Resolver) ResolvePath

func (r *Resolver) ResolvePath(ctx context.Context, name string, rawOpen openFile) (fsPath string, nestedFs Filesystem, nestedFsPath string, err error)

open requeue raw open, without resolver call

type ResolverFS

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

func NewResolveFS

func NewResolveFS(rootFs Filesystem, factories map[string]FsFactory) *ResolverFS

func (*ResolverFS) FsName

func (r *ResolverFS) FsName() string

FsName implements Filesystem.

func (*ResolverFS) Info

func (r *ResolverFS) Info() (fs.FileInfo, error)

Info implements Filesystem.

func (*ResolverFS) IsDir

func (r *ResolverFS) IsDir() bool

IsDir implements Filesystem.

func (*ResolverFS) ModTime

func (r *ResolverFS) ModTime() time.Time

ModTime implements Filesystem.

func (*ResolverFS) Mode

func (r *ResolverFS) Mode() fs.FileMode

Mode implements Filesystem.

func (*ResolverFS) Name

func (r *ResolverFS) Name() string

Name implements Filesystem.

func (*ResolverFS) Open

func (r *ResolverFS) Open(ctx context.Context, filename string) (File, error)

Open implements Filesystem.

func (*ResolverFS) ReadDir

func (r *ResolverFS) ReadDir(ctx context.Context, name string) ([]fs.DirEntry, error)

ReadDir implements Filesystem.

func (*ResolverFS) Rename

func (r *ResolverFS) Rename(ctx context.Context, oldpath string, newpath string) error

Rename implements Filesystem.

func (*ResolverFS) ResolvablesExtensions

func (r *ResolverFS) ResolvablesExtensions() []string

func (*ResolverFS) Size

func (r *ResolverFS) Size() int64

Size implements Filesystem.

func (*ResolverFS) Stat

func (r *ResolverFS) Stat(ctx context.Context, filename string) (fs.FileInfo, error)

Stat implements Filesystem.

func (*ResolverFS) Sys

func (r *ResolverFS) Sys() any

Sys implements Filesystem.

func (*ResolverFS) Type

func (r *ResolverFS) Type() fs.FileMode

Type implements Filesystem.

func (r *ResolverFS) Unlink(ctx context.Context, filename string) error

Unlink implements Filesystem.

Jump to

Keyboard shortcuts

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