overlayfs

package module
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 7 Imported by: 33

README

Tests on Linux, MacOS and Windows Go Report Card GoDoc

overlayfs is a composite filesystem (currently only) for Afero with similar but different semantics compared to Afero's copyOnWriteFs. See the GoDoc for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dir

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

Dir is an afero.File that represents list of directories that will be merged in Readdir and Readdirnames.

func OpenDir added in v0.8.0

func OpenDir(
	merge DirsMerger,

	info func() (os.FileInfo, error),

	dirOpeners ...func() (afero.File, error),
) (*Dir, error)

OpenDir opens a new Dir with dirs to be merged by the given merge func. If merge is nil, a default DirsMerger is used.

func (*Dir) Close

func (d *Dir) Close() error

Close implements afero.File.Close. Note that d must not be used after it is closed, as the object may be reused.

func (*Dir) Name

func (d *Dir) Name() string

Name implements afero.File.Name.

func (*Dir) Read

func (d *Dir) Read(p []byte) (n int, err error)

Read is not supported.

func (*Dir) ReadAt

func (d *Dir) ReadAt(p []byte, off int64) (n int, err error)

ReadAt is not supported.

func (*Dir) ReadDir added in v0.7.0

func (d *Dir) ReadDir(n int) ([]fs.DirEntry, error)

ReadDir implements fs.ReadDirFile.

func (*Dir) Readdir

func (d *Dir) Readdir(n int) ([]os.FileInfo, error)

Readdir implements afero.File.Readdir. If n > 0, Readdir returns at most n. Note that Dir also implements fs.ReadDirFile, which is more efficient.

func (*Dir) Readdirnames

func (d *Dir) Readdirnames(n int) ([]string, error)

Readdirnames implements afero.File.Readdirnames. If n > 0, Readdirnames returns at most n.

func (*Dir) Seek

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

Seek is not supported.

func (*Dir) Stat

func (d *Dir) Stat() (os.FileInfo, error)

Stat implements afero.File.Stat.

func (*Dir) Sync

func (d *Dir) Sync() error

Sync is not supported.

func (*Dir) Truncate

func (d *Dir) Truncate(size int64) error

Truncate is not supported.

func (*Dir) Write

func (d *Dir) Write(p []byte) (n int, err error)

Write is not supported.

func (*Dir) WriteAt

func (d *Dir) WriteAt(p []byte, off int64) (n int, err error)

WriteAt is not supported.

func (*Dir) WriteString

func (d *Dir) WriteString(s string) (ret int, err error)

WriteString is not supported.

type DirsMerger

type DirsMerger func(lofi, bofi []fs.DirEntry) []fs.DirEntry

DirsMerger is used to merge two directories.

type FilesystemIterator

type FilesystemIterator interface {
	Filesystem(i int) afero.Fs
	NumFilesystems() int
}

FilesystemIterator is an interface for iterating over the wrapped filesystems in order.

type Options

type Options struct {
	// The filesystems to overlay ordered in priority from left to right.
	Fss []afero.Fs

	// The OverlayFs is by default read-only, but you can nominate the first filesystem to be writable.
	FirstWritable bool

	// The DirsMerger is used to merge the contents of two directories.
	// If not provided, the defaultDirMerger is used.
	DirsMerger DirsMerger
}

Options for the OverlayFs.

type OverlayFs

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

OverlayFs is a filesystem that overlays multiple filesystems. It's by default a read-only filesystem, but you can nominate the first filesystem to be writable. For all operations, the filesystems are checked in order until found. If a filesystem implementes FilesystemIterator, those filesystems will be checked before continuing.

func New

func New(opts Options) *OverlayFs

New creates a new OverlayFs with the given options.

func (OverlayFs) Append

func (ofs OverlayFs) Append(fss ...afero.Fs) *OverlayFs

Append creates a shallow copy of the filesystem and appends the given filesystems to it.

func (*OverlayFs) Chmod

func (ofs *OverlayFs) Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func (*OverlayFs) Chown

func (ofs *OverlayFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*OverlayFs) Chtimes

func (ofs *OverlayFs) Chtimes(name string, atime, mtime time.Time) error

Chtimes changes the access and modification times of the named file

func (*OverlayFs) Create

func (ofs *OverlayFs) Create(name string) (afero.File, error)

Create creates a file in the filesystem, returning the file and an error, if any happens.

func (*OverlayFs) Filesystem

func (ofs *OverlayFs) Filesystem(i int) afero.Fs

Filesystem returns filesystem with index i, nil if not found.

func (*OverlayFs) LstatIfPossible

func (ofs *OverlayFs) LstatIfPossible(name string) (os.FileInfo, bool, error)

LstatIfPossible will call Lstat if the filesystem iself is, or it delegates to, the os filesystem. Else it will call Stat.

func (*OverlayFs) Mkdir

func (ofs *OverlayFs) Mkdir(name string, perm os.FileMode) error

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*OverlayFs) MkdirAll

func (ofs *OverlayFs) MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory path and all parents that does not exist yet.

func (*OverlayFs) Name

func (ofs *OverlayFs) Name() string

Name returns the name of this filesystem.

func (*OverlayFs) NumFilesystems

func (ofs *OverlayFs) NumFilesystems() int

NumFilesystems returns the number of filesystems in this composite filesystem.

func (*OverlayFs) Open

func (ofs *OverlayFs) Open(name string) (afero.File, error)

Open opens a file, returning it or an error, if any happens. If name is a directory, a *Dir is returned representing all directories matching name. Note that a *Dir must not be used after it's closed.

func (*OverlayFs) OpenFile

func (ofs *OverlayFs) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error)

OpenFile opens a file using the given flags and the given mode.

func (*OverlayFs) Remove

func (ofs *OverlayFs) Remove(name string) error

Remove removes a file identified by name, returning an error, if any happens.

func (*OverlayFs) RemoveAll

func (ofs *OverlayFs) RemoveAll(path string) error

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*OverlayFs) Rename

func (ofs *OverlayFs) Rename(oldname, newname string) error

Rename renames a file.

func (*OverlayFs) Stat

func (ofs *OverlayFs) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

func (OverlayFs) WithDirsMerger added in v0.9.0

func (ofs OverlayFs) WithDirsMerger(d DirsMerger) *OverlayFs

WithDirsMerger creates a shallow copy of the filesystem and sets the DirsMerger.

Jump to

Keyboard shortcuts

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