fs_ns

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 47 Imported by: 0

README

Filesystem Namespace

This package implements the functions provided by the fs namespace (available by default in the global scope).

This package also contains several implementations of afs.Filesystem:

File watching is implemented in watcher_unix.go and vfs_watcher.go.

Documentation

Index

Constants

View Source
const (
	FS_WRITE_LIMIT_NAME          = "fs/write"
	FS_READ_LIMIT_NAME           = "fs/read"
	FS_TOTAL_NEW_FILE_LIMIT_NAME = "fs/total-new-files"
	FS_NEW_FILE_RATE_LIMIT_NAME  = "fs/create-file"

	FS_WRITE_MIN_CHUNK_SIZE = 100_000
	FS_READ_MIN_CHUNK_SIZE  = 1_000_000
	DEFAULT_R_FILE_FMODE    = fs.FileMode(0o400)
	DEFAULT_FILE_FMODE      = fs.FileMode(0o600)
	DEFAULT_DIR_FMODE       = fs.FileMode(0o700)
)
View Source
const (
	METAFS_UNDERLYING_FILE_PROPNAME = "underlying-file"
	METAFS_FILE_MODE_PROPNAME       = "file-mode"
	METAFS_CREATION_TIME_PROPNAME   = "creation-time"
	METAFS_MODIF_TIME_PROPNAME      = "modification-time"
	METAFS_SYMLINK_TARGET_PROPNAME  = "symlink-target"
	METAFS_CHILDREN_PROPNAME        = "children"

	METAFS_UNDERLYING_UNDERLYING_FILE_PERM = 0600
	METAFS_AUTO_CREATED_DIR_PERM           = fs.FileMode(0700)

	METAFS_FILES_KEY   = "/files"
	METAFS_KV_FILENAME = "metadata.kv"

	METAFS_MIN_USABLE_SPACE                             = 10_000_000
	METAFS_USED_SPACE_CHECK_INTERVAL                    = time.Second / 2
	METAFS_ALWAYS_CHECK_USED_SPACE_BYTE_COUNT_THRESHOLD = 100_000
	METAFS_DEFAULT_MAX_FILE_COUNT                       = 1000
	METAFS_DEFAULT_MAX_PARALLEL_FILE_CREATION_COUNT     = 10

	METAFS_MAX_SNAPSHOTABLE_SIZE                 = core.ByteCount(100_000_000)
	METAFS_DEFAULT_MAX_UNTRACK_CLOSED_FILE_COUNT = 10
)
View Source
const (
	MAX_SMALL_CHANGE_SIZE = 1000 //byte count

	META_FS_FILE_SNAPSHOTING_WAIT_TIMEOUT = 100 * time.Millisecond
)
View Source
const (
	WATCHER_MANAGEMENT_TICK_INTERVAL = 25 * time.Millisecond
	OLD_EVENT_MIN_AGE                = max(50*time.Millisecond, 2*WATCHER_MANAGEMENT_TICK_INTERVAL)
)
View Source
const (
	FS_SNAPSHOT_SYMB_DESC_FILES_PROPNAME = "files"
)
View Source
const (
	MAX_FILE_HIERARCHY_DEPTH = 5
)
View Source
const (
	PROCESS_TEMP_DIR_PREFIX = "inoxlangprocess"
)
View Source
const (
	TRUE_MAX_IN_MEM_STORAGE = core.ByteCount(100_000_000)
)

Variables

View Source
var (
	ErrCannotOpenDir                 = errors.New("cannot open directory")
	ErrClosedFilesystem              = errors.New("closed filesystem")
	ErrMaxFileNumberAlreadyReached   = errors.New("the maximum number of files in the filesystem has already been reached")
	ErrTooManyParallelFileCreation   = errors.New("too many files are being created in parallel")
	ErrNoRemainingSpaceUsableByFS    = errors.New("no remaining space usable by filesystem")
	ErrNoRemainingSpaceToApplyChange = errors.New("no remaining space to apply change")
	ErrMaxUsableSpaceTooSmall        = errors.New("the given usable space value is too small")
)
View Source
var (
	ErrTooDeepFileHierarchy = errors.New("file hierarchy is too deep")

	MKDIR_ARG_NAMES   = []string{"dirpath", "content"}
	MKDIR_SYMB_PARAMS = &[]symbolic.Value{symbolic.ANY_DIR_PATH, symbolic.ANY_DICT}

	MKFILE_ARG_NAMES   = []string{"filepath", "content"}
	MKFILE_SYMB_PARAMS = &[]symbolic.Value{symbolic.ANY_NON_DIR_PATH, symbolic.ANY_READABLE}
)
View Source
var (
	READFILE_ARG_NAMES   = []string{"filepath"}
	READFILE_SYMB_PARAMS = &[]symbolic.Value{symbolic.ANY_DIR_PATH}

	LISTFILES_ARG_NAMES   = []string{"path-or-pattern"}
	LISTFILES_SYMB_PARAMS = &[]symbolic.Value{symbolic.NewMultivalue(symbolic.ANY_PATH, symbolic.ANY_PATH_PATTERN)}
)
View Source
var (
	NEW_FS_SNAPSHOT_DESC = symbolic.NewInexactObject2(map[string]symbolic.Serializable{
		FS_SNAPSHOT_SYMB_DESC_FILES_PROPNAME: symbolic.ANY_DICT,
	})

	NEW_FS_SNAPSHOT_SYMB_ARGS      = &[]symbolic.Value{NEW_FS_SNAPSHOT_DESC}
	NEW_FS_SNAPSHOT_SYMB_ARG_NAMES = []string{"description"}

	ErrFileBeingSnapshoted = errors.New("file is being snapshoted")
)
View Source
var (
	ErrInMemoryStorageLimitExceededDuringWrite = errors.New("in-memory file storage limit exceeded during write operation")
)
View Source
var (
	ErrOsFilesystemNotAvailable = errors.New("os filesystem not available")
)
View Source
var (
	ErrTimeInfoNotAvailable = errors.New("time information of file is not available")
)

Functions

func AppendToFile

func AppendToFile(ctx *core.Context, args ...core.Value) error

func Copy

func Copy(ctx *core.Context, args ...core.Value) error

Copy copy a single file or copy a list of files in destination directory. arguments: ./src ./copy -> copy the ./src file into ./copy that SHOULD NOT exist. arguments [./file, ./dir] ./dest_dir -> copy the provided files into ./dest_dir. Copy never overwrites a file or directory and returns an error if there is already a file at any destination path.

func CreateDirInProcessTempDir

func CreateDirInProcessTempDir(namePrefix string) core.Path

CreateTempdir creates a directory with permissions o700 in the process's temporary directory in the OS's filesystem. The process's temporary directory is created if necessary.

func DeleteDeadProcessTempDirs

func DeleteDeadProcessTempDirs(logger zerolog.Logger, maxDuration time.Duration)

func DeleteDirInProcessTempDir

func DeleteDirInProcessTempDir(path core.Path) error

func DeleteProcessTempDir

func DeleteProcessTempDir()

func Exists

func Exists(ctx *core.Context, pth core.Path) core.Bool

func Find

func Find(ctx *core.Context, dir core.Path, filters ...core.Pattern) (*core.List, error)

func GetCreateProcessTempDir

func GetCreateProcessTempDir() core.Path

func GetCreationAndModifTime

func GetCreationAndModifTime(i fs.FileInfo) (time.Time, time.Time, error)

GetCreationAndModifTime returns the creation time & content modification time.

func GetTreeData

func GetTreeData(ctx *core.Context, path core.Path) *core.Treedata

func Glob

func Glob(ctx *core.Context, patt core.PathPattern) []core.Path

Glob is the implementation of the fs.glob function, it calls the internal glob function.

func IsAppend

func IsAppend(flag int) bool

func IsCreate

func IsCreate(flag int) bool

func IsDir

func IsDir(ctx *core.Context, pth core.Path) core.Bool

func IsExclusive

func IsExclusive(flag int) bool

func IsFile

func IsFile(ctx *core.Context, pth core.Path) core.Bool

func IsReadAndWrite

func IsReadAndWrite(flag int) bool

func IsReadOnly

func IsReadOnly(flag int) bool

func IsTruncate

func IsTruncate(flag int) bool

func ListFiles

func ListFiles(ctx *core.Context, pathOrPatt *core.OptionalParam[core.Value]) ([]core.FileInfo, error)

func Mkdir

func Mkdir(ctx *core.Context, dirpath core.Path, content *core.OptionalParam[*core.Dictionary]) error

Mkdir expects a core.Path argument and creates a directory. If a dictionary is passed a file hiearchy will also be created.

func Mkfile

func Mkfile(ctx *core.Context, fpath core.Path, args ...core.Value) error

Mkfile creates a regular file, if an additional argument is passed it will be used as the content of the file.

func NewFilesystemSnapshot

func NewFilesystemSnapshot(ctx *core.Context, desc *core.Object) *core.FilesystemSnapshotIL

func NewFsNamespace

func NewFsNamespace() *core.Namespace

func NormalizeAsAbsolute

func NormalizeAsAbsolute(path string) string

func Read

func Read(ctx *core.Context, path core.Path, args ...core.Value) (result core.Value, finalErr error)

func ReadDir

func ReadDir(ctx *core.Context, pth core.Path) ([]fs.DirEntry, error)

func ReadEntireFile

func ReadEntireFile(ctx *core.Context, fpath core.Path) ([]byte, error)

func ReadFile

func ReadFile(ctx *core.Context, fpath core.Path) (*core.ByteSlice, error)

ReadFile expects a core.Path argument, it reads the whole content of a file.

func Remove

func Remove(ctx *core.Context, args ...core.Value) error

func Rename

func Rename(ctx *core.Context, old, new core.Path) error

Rename renames a file, it returns an error if the renamed file does not exist or it a file already has the new name.

func ReplaceFileContent

func ReplaceFileContent(ctx *core.Context, args ...core.Value) error

Types

type AddressableContentBytes

type AddressableContentBytes struct {
	Sha256 [32]byte
	Data   []byte
}

func (AddressableContentBytes) ChecksumSHA256

func (b AddressableContentBytes) ChecksumSHA256() [32]byte

func (AddressableContentBytes) Reader

func (b AddressableContentBytes) Reader() io.Reader

type AppendBytesToFile

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

func (*AppendBytesToFile) Apply

func (e *AppendBytesToFile) Apply(ctx *core.Context) error

func (AppendBytesToFile) CheckPermissions

func (e AppendBytesToFile) CheckPermissions(ctx *core.Context) error

func (AppendBytesToFile) IsApplied

func (e AppendBytesToFile) IsApplied() bool

func (AppendBytesToFile) IsApplying

func (e AppendBytesToFile) IsApplying() bool

func (AppendBytesToFile) PermissionKind

func (e AppendBytesToFile) PermissionKind() core.PermissionKind

func (AppendBytesToFile) Resources

func (e AppendBytesToFile) Resources() []core.ResourceName

func (AppendBytesToFile) Reversability

func (e AppendBytesToFile) Reversability(*core.Context) core.Reversability

func (AppendBytesToFile) Reverse

func (e AppendBytesToFile) Reverse(ctx *core.Context) error

type BasicTestSuite

type BasicTestSuite struct {
	FS billy.Basic
}

BasicTestSuite is a convenient test suite to validate any implementation of billy.Basic

func (*BasicTestSuite) TestCreate

func (s *BasicTestSuite) TestCreate(c *check.C)

func (*BasicTestSuite) TestCreateAndClose

func (s *BasicTestSuite) TestCreateAndClose(c *check.C)

func (*BasicTestSuite) TestCreateDepth

func (s *BasicTestSuite) TestCreateDepth(c *check.C)

func (*BasicTestSuite) TestCreateDepthAbsolute

func (s *BasicTestSuite) TestCreateDepthAbsolute(c *check.C)

func (*BasicTestSuite) TestCreateOverwrite

func (s *BasicTestSuite) TestCreateOverwrite(c *check.C)

func (*BasicTestSuite) TestFileCloseTwice

func (s *BasicTestSuite) TestFileCloseTwice(c *check.C)

func (*BasicTestSuite) TestFileClosed

func (s *BasicTestSuite) TestFileClosed(c *check.C)

func (*BasicTestSuite) TestFileNonRead

func (s *BasicTestSuite) TestFileNonRead(c *check.C)

func (*BasicTestSuite) TestFileRead

func (s *BasicTestSuite) TestFileRead(c *check.C)

func (*BasicTestSuite) TestFileSeekClosed

func (s *BasicTestSuite) TestFileSeekClosed(c *check.C)

func (*BasicTestSuite) TestFileSeekCurrent

func (s *BasicTestSuite) TestFileSeekCurrent(c *check.C)

func (*BasicTestSuite) TestFileSeekEnd

func (s *BasicTestSuite) TestFileSeekEnd(c *check.C)

func (*BasicTestSuite) TestFileSeekstart

func (s *BasicTestSuite) TestFileSeekstart(c *check.C)

func (*BasicTestSuite) TestFileWrite

func (s *BasicTestSuite) TestFileWrite(c *check.C)

func (*BasicTestSuite) TestFileWriteClose

func (s *BasicTestSuite) TestFileWriteClose(c *check.C)

func (*BasicTestSuite) TestJoin

func (s *BasicTestSuite) TestJoin(c *check.C)

func (*BasicTestSuite) TestOpen

func (s *BasicTestSuite) TestOpen(c *check.C)

func (*BasicTestSuite) TestOpenAndStat

func (s *BasicTestSuite) TestOpenAndStat(c *check.C)

func (*BasicTestSuite) TestOpenAndWrite

func (s *BasicTestSuite) TestOpenAndWrite(c *check.C)

func (*BasicTestSuite) TestOpenFile

func (s *BasicTestSuite) TestOpenFile(c *check.C)

func (*BasicTestSuite) TestOpenFileAppend

func (s *BasicTestSuite) TestOpenFileAppend(c *check.C)

func (*BasicTestSuite) TestOpenFileNoTruncate

func (s *BasicTestSuite) TestOpenFileNoTruncate(c *check.C)

func (*BasicTestSuite) TestOpenFileReadAfterRemoval

func (s *BasicTestSuite) TestOpenFileReadAfterRemoval(c *check.C)

func (*BasicTestSuite) TestOpenFileReadWrite

func (s *BasicTestSuite) TestOpenFileReadWrite(c *check.C)

func (*BasicTestSuite) TestOpenFileReadWriteAfterRemoval

func (s *BasicTestSuite) TestOpenFileReadWriteAfterRemoval(c *check.C)

func (*BasicTestSuite) TestOpenFileWithModes

func (s *BasicTestSuite) TestOpenFileWithModes(c *check.C)

func (*BasicTestSuite) TestOpenNotExists

func (s *BasicTestSuite) TestOpenNotExists(c *check.C)

func (*BasicTestSuite) TestReadAtEOF

func (s *BasicTestSuite) TestReadAtEOF(c *check.C)

func (*BasicTestSuite) TestReadAtOffset

func (s *BasicTestSuite) TestReadAtOffset(c *check.C)

func (*BasicTestSuite) TestReadAtOnReadOnly

func (s *BasicTestSuite) TestReadAtOnReadOnly(c *check.C)

func (*BasicTestSuite) TestReadAtOnReadWrite

func (s *BasicTestSuite) TestReadAtOnReadWrite(c *check.C)

func (*BasicTestSuite) TestReadWriteLargeFile

func (s *BasicTestSuite) TestReadWriteLargeFile(c *check.C)

func (*BasicTestSuite) TestRemove

func (s *BasicTestSuite) TestRemove(c *check.C)

func (*BasicTestSuite) TestRemoveNonExisting

func (s *BasicTestSuite) TestRemoveNonExisting(c *check.C)

func (*BasicTestSuite) TestRemoveNotEmptyDir

func (s *BasicTestSuite) TestRemoveNotEmptyDir(c *check.C)

func (*BasicTestSuite) TestRename

func (s *BasicTestSuite) TestRename(c *check.C)

func (*BasicTestSuite) TestSeekToEndAndWrite

func (s *BasicTestSuite) TestSeekToEndAndWrite(c *check.C)

func (*BasicTestSuite) TestStat

func (s *BasicTestSuite) TestStat(c *check.C)

func (*BasicTestSuite) TestStatDeep

func (s *BasicTestSuite) TestStatDeep(c *check.C)

func (*BasicTestSuite) TestStatNonExistent

func (s *BasicTestSuite) TestStatNonExistent(c *check.C)

func (*BasicTestSuite) TestTruncate

func (s *BasicTestSuite) TestTruncate(c *check.C)

func (*BasicTestSuite) TestWriteFile

func (s *BasicTestSuite) TestWriteFile(c *check.C)

type ClosableFilesystem

type ClosableFilesystem interface {
	afs.Filesystem
	Close(ctx *core.Context) error
}

type CreateDir

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

func (*CreateDir) Apply

func (e *CreateDir) Apply(ctx *core.Context) error

func (CreateDir) CheckPermissions

func (e CreateDir) CheckPermissions(ctx *core.Context) error

func (CreateDir) IsApplied

func (e CreateDir) IsApplied() bool

func (CreateDir) IsApplying

func (e CreateDir) IsApplying() bool

func (CreateDir) PermissionKind

func (e CreateDir) PermissionKind() core.PermissionKind

func (CreateDir) Resources

func (e CreateDir) Resources() []core.ResourceName

func (CreateDir) Reversability

func (e CreateDir) Reversability(*core.Context) core.Reversability

func (CreateDir) Reverse

func (e CreateDir) Reverse(ctx *core.Context) error

type CreateFile

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

func (*CreateFile) Apply

func (e *CreateFile) Apply(ctx *core.Context) error

func (CreateFile) CheckPermissions

func (e CreateFile) CheckPermissions(ctx *core.Context) error

func (CreateFile) IsApplied

func (e CreateFile) IsApplied() bool

func (CreateFile) IsApplying

func (e CreateFile) IsApplying() bool

func (CreateFile) PermissionKind

func (e CreateFile) PermissionKind() core.PermissionKind

func (CreateFile) Resources

func (e CreateFile) Resources() []core.ResourceName

func (CreateFile) Reversability

func (e CreateFile) Reversability(*core.Context) core.Reversability

func (CreateFile) Reverse

func (e CreateFile) Reverse(ctx *core.Context) error

type DirTestSuite

type DirTestSuite struct {
	FS interface {
		billy.Basic
		billy.Dir
	}
}

DirTestSuite is a convenient test suite to validate any implementation of billy.Dir

func (*DirTestSuite) TestCreateFileInDir

func (s *DirTestSuite) TestCreateFileInDir(c *check.C)

func (*DirTestSuite) TestMkdirAll

func (s *DirTestSuite) TestMkdirAll(c *check.C)

func (*DirTestSuite) TestMkdirAllAndCreate

func (s *DirTestSuite) TestMkdirAllAndCreate(c *check.C)

func (*DirTestSuite) TestMkdirAllIdempotent

func (s *DirTestSuite) TestMkdirAllIdempotent(c *check.C)

func (*DirTestSuite) TestMkdirAllNested

func (s *DirTestSuite) TestMkdirAllNested(c *check.C)

func (*DirTestSuite) TestMkdirAllWithExistingFile

func (s *DirTestSuite) TestMkdirAllWithExistingFile(c *check.C)

func (*DirTestSuite) TestOpenDir

func (s *DirTestSuite) TestOpenDir(c *check.C)

func (*DirTestSuite) TestReadDir

func (s *DirTestSuite) TestReadDir(c *check.C)

func (*DirTestSuite) TestReadDirAfterFileRename

func (s *DirTestSuite) TestReadDirAfterFileRename(c *check.C)

func (*DirTestSuite) TestReadDirFileInfo

func (s *DirTestSuite) TestReadDirFileInfo(c *check.C)

func (*DirTestSuite) TestReadDirFileInfoDirs

func (s *DirTestSuite) TestReadDirFileInfoDirs(c *check.C)

func (*DirTestSuite) TestReadDirNested

func (s *DirTestSuite) TestReadDirNested(c *check.C)

func (*DirTestSuite) TestReadDirWithMkDirAll

func (s *DirTestSuite) TestReadDirWithMkDirAll(c *check.C)

func (*DirTestSuite) TestRemoveFileFromDir

func (s *DirTestSuite) TestRemoveFileFromDir(c *check.C)

func (*DirTestSuite) TestRemoveNonEmptyDir

func (s *DirTestSuite) TestRemoveNonEmptyDir(c *check.C)

func (*DirTestSuite) TestRenameDir

func (s *DirTestSuite) TestRenameDir(c *check.C)

func (*DirTestSuite) TestRenameFileInsideDir

func (s *DirTestSuite) TestRenameFileInsideDir(c *check.C)

func (*DirTestSuite) TestRenameToDir

func (s *DirTestSuite) TestRenameToDir(c *check.C)

func (*DirTestSuite) TestStatDir

func (s *DirTestSuite) TestStatDir(c *check.C)

func (*DirTestSuite) TestStatRootDir

func (s *DirTestSuite) TestStatRootDir(c *check.C)

type Event

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

func (Event) CreateCoreEvent

func (e Event) CreateCoreEvent() *core.Event

func (Event) HasChmodOp

func (e Event) HasChmodOp() bool

func (Event) HasCreateOp

func (e Event) HasCreateOp() bool

func (Event) HasRemoveOp

func (e Event) HasRemoveOp() bool

func (Event) HasRenameOp

func (e Event) HasRenameOp() bool

func (Event) HasWriteOp

func (e Event) HasWriteOp() bool

func (Event) IsStructureChange

func (e Event) IsStructureChange() bool

IsStructureChange() returns true if e.HasCreateOp() || e.HasRenameOp() || e.HasRemoveOp()

func (Event) IsStructureOrContentChange

func (e Event) IsStructureOrContentChange() bool

IsStructureOrContentChange() returns true if e.HasCreateOp() || e.HasRenameOp() || e.HasRemoveOp() || e.HasWriteOp()

func (Event) Path

func (e Event) Path() core.Path

func (Event) Time

func (e Event) Time() core.DateTime

type File

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

func OpenExisting

func OpenExisting(ctx *core.Context, args ...core.Value) (*File, error)

OpenExisting is the implementation of fs.open, it calls the internal openExistingFile function.

func (*File) Equal

func (f *File) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*File) GetGoMethod

func (f *File) GetGoMethod(name string) (*core.GoFunction, bool)

func (*File) IsMutable

func (f *File) IsMutable() bool

func (*File) PrettyPrint

func (f *File) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*File) Prop

func (f *File) Prop(ctx *core.Context, name string) core.Value

func (*File) PropertyNames

func (*File) PropertyNames(ctx *core.Context) []string

func (*File) SetProp

func (*File) SetProp(ctx *core.Context, name string, value core.Value) error

func (*File) ToSymbolicValue

func (f *File) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type FilesystemEventSource

type FilesystemEventSource struct {
	core.EventSourceBase
	// contains filtered or unexported fields
}

func NewEventSource

func NewEventSource(ctx *core.Context, resourceNameOrPattern core.Value) (*FilesystemEventSource, error)

NewEventSource calls NewEventSourceWithFilesystem with ctx's filesystem.

func NewEventSourceWithFilesystem

func NewEventSourceWithFilesystem(ctx *core.Context, fls afs.Filesystem, resourceNameOrPattern core.Value) (*FilesystemEventSource, error)

func (*FilesystemEventSource) Close

func (evs *FilesystemEventSource) Close()

func (*FilesystemEventSource) Equal

func (evs *FilesystemEventSource) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*FilesystemEventSource) GetFilter

func (evs *FilesystemEventSource) GetFilter() core.PathPattern

func (*FilesystemEventSource) GetGoMethod

func (evs *FilesystemEventSource) GetGoMethod(name string) (*core.GoFunction, bool)

func (*FilesystemEventSource) GetPath

func (evs *FilesystemEventSource) GetPath() core.Path

func (*FilesystemEventSource) IsClosed

func (evs *FilesystemEventSource) IsClosed() bool

func (*FilesystemEventSource) IsMutable

func (evs *FilesystemEventSource) IsMutable() bool

func (*FilesystemEventSource) Iterator

func (*FilesystemEventSource) PrettyPrint

func (evs *FilesystemEventSource) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*FilesystemEventSource) Prop

func (evs *FilesystemEventSource) Prop(ctx *core.Context, name string) core.Value

func (*FilesystemEventSource) PropertyNames

func (*FilesystemEventSource) PropertyNames(ctx *core.Context) []string

func (*FilesystemEventSource) SetProp

func (*FilesystemEventSource) SetProp(ctx *core.Context, name string, value core.Value) error

func (*FilesystemEventSource) ToSymbolicValue

func (evs *FilesystemEventSource) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type FilesystemIL

type FilesystemIL struct {
	afs.Filesystem
}

func NewMemFilesystemIL

func NewMemFilesystemIL(maxTotalStorageSize core.ByteCount) *FilesystemIL

func (*FilesystemIL) Equal

func (fls *FilesystemIL) Equal(ctx *core.Context, other core.Value, alreadyCompared map[uintptr]uintptr, depth int) bool

func (*FilesystemIL) IsMutable

func (evs *FilesystemIL) IsMutable() bool

func (*FilesystemIL) PrettyPrint

func (fls *FilesystemIL) PrettyPrint(w *bufio.Writer, config *core.PrettyPrintConfig, depth int, parentIndentCount int)

func (*FilesystemIL) ToSymbolicValue

func (evs *FilesystemIL) ToSymbolicValue(ctx *core.Context, encountered map[uintptr]symbolic.Value) (symbolic.Value, error)

type GenericBasic

type GenericBasic struct {
	CreateFn   func(filename string) (afs.File, error)
	OpenFn     func(filename string) (afs.File, error)
	OpenFileFn func(filename string, flag int, perm os.FileMode) (afs.File, error)
	StatFn     func(filename string) (os.FileInfo, error)
	RenameFn   func(oldpath, newpath string) error
	RemoveFn   func(filename string) error
	JoinFn     func(elem ...string) string
}

GenericBasic is an implementation of billy.Basic. All the fields are optional: for example if .CreateFn is not provided the Create method will always return billy.ErrNotSupported.

func (GenericBasic) Create

func (i GenericBasic) Create(filename string) (afs.File, error)

func (GenericBasic) Join

func (i GenericBasic) Join(elem ...string) string

func (GenericBasic) Open

func (i GenericBasic) Open(filename string) (afs.File, error)

func (GenericBasic) OpenFile

func (i GenericBasic) OpenFile(filename string, flag int, perm os.FileMode) (afs.File, error)

func (GenericBasic) Remove

func (i GenericBasic) Remove(filename string) error

func (GenericBasic) Rename

func (i GenericBasic) Rename(oldpath, newpath string) error

func (GenericBasic) Stat

func (i GenericBasic) Stat(filename string) (os.FileInfo, error)

type GenericFile

type GenericFile struct {
	Filename   string
	WriteFn    func(p []byte) (n int, err error)
	ReadFn     func(p []byte) (n int, err error)
	ReadAtFn   func(p []byte, off int64) (n int, err error)
	SeekFn     func(offset int64, whence int) (int64, error)
	CloseFn    func() error
	LockFn     func() error
	UnlockFn   func() error
	TruncateFn func(size int64) error
}

GenericFile is an implementation of billy.File. All the fields are optional: for example if .WriteFn is not provided the Write method will always return billy.ErrNotSupported.

func (*GenericFile) Close

func (f *GenericFile) Close() error

func (*GenericFile) Lock

func (f *GenericFile) Lock() error

func (*GenericFile) Name

func (f *GenericFile) Name() string

func (*GenericFile) Read

func (f *GenericFile) Read(p []byte) (n int, err error)

func (*GenericFile) ReadAt

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

func (*GenericFile) Seek

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

func (*GenericFile) Truncate

func (f *GenericFile) Truncate(size int64) error

func (*GenericFile) Unlock

func (f *GenericFile) Unlock() error

func (*GenericFile) Write

func (f *GenericFile) Write(p []byte) (n int, err error)

type InMemFileContent

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

func NewInMemFileContent

func NewInMemFileContent(
	name string,
	content []byte,
	creationTime time.Time,
	maxStorage int64, storageSize *atomic.Int64,
) *InMemFileContent

func (*InMemFileContent) IsDirty

func (c *InMemFileContent) IsDirty() bool

func (*InMemFileContent) Len

func (c *InMemFileContent) Len() int

func (*InMemFileContent) ModifTime

func (c *InMemFileContent) ModifTime() time.Time

func (*InMemFileContent) Persist

func (c *InMemFileContent) Persist(persistFn func(p []byte) error) (finalErr error)

If the file is not dirty Persist snapshots the content of the file & invokes persistFn, if persistFn returns an error or panics an error is returned.

func (*InMemFileContent) ReadAt

func (c *InMemFileContent) ReadAt(b []byte, off int64) (n int, err error)

func (*InMemFileContent) ShouldBePersisted

func (c *InMemFileContent) ShouldBePersisted() bool

ShouldBePersisted returns true if the content is dirty AND is not being persisted.

func (*InMemFileContent) Truncate

func (c *InMemFileContent) Truncate(size int64) error

func (*InMemFileContent) WriteAt

func (c *InMemFileContent) WriteAt(p []byte, off int64) (int, error)

type InMemfile

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

func (*InMemfile) Close

func (f *InMemfile) Close() error

func (*InMemfile) Duplicate

func (f *InMemfile) Duplicate(originalPath string, mode os.FileMode, flag int) billy.File

func (*InMemfile) FileInfo

func (f *InMemfile) FileInfo() core.FileInfo

func (*InMemfile) FileInfoContentNotLocked

func (f *InMemfile) FileInfoContentNotLocked() core.FileInfo

func (*InMemfile) Lock

func (f *InMemfile) Lock() error

Lock is a no-op in memfs.

func (*InMemfile) Name

func (f *InMemfile) Name() string

func (*InMemfile) Read

func (f *InMemfile) Read(b []byte) (int, error)

func (*InMemfile) ReadAt

func (f *InMemfile) ReadAt(b []byte, off int64) (int, error)

func (*InMemfile) Seek

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

func (*InMemfile) Stat

func (f *InMemfile) Stat() (os.FileInfo, error)

func (*InMemfile) Sync

func (*InMemfile) Sync() error

func (*InMemfile) Truncate

func (f *InMemfile) Truncate(size int64) error

func (*InMemfile) Unlock

func (f *InMemfile) Unlock() error

Unlock is a no-op in memfs.

func (*InMemfile) Write

func (f *InMemfile) Write(p []byte) (int, error)

type InMemorySnapshot

type InMemorySnapshot struct {
	MetadataMap  map[string]*core.EntrySnapshotMetadata
	FileContents map[string]core.AddressableContent
}

An InMemorySnapshot is an implementation of FilesystemSnapshot that stores all the data & metadata in memory.

func (*InMemorySnapshot) Content

func (s *InMemorySnapshot) Content(path string) (core.AddressableContent, error)

func (*InMemorySnapshot) ForEachEntry

func (s *InMemorySnapshot) ForEachEntry(fn func(m core.EntrySnapshotMetadata) error) error

func (*InMemorySnapshot) IsStoredLocally

func (s *InMemorySnapshot) IsStoredLocally() bool

func (*InMemorySnapshot) Metadata

func (*InMemorySnapshot) NewAdaptedFilesystem

func (s *InMemorySnapshot) NewAdaptedFilesystem(maxTotalStorageSizeHint core.ByteCount) (core.SnapshotableFilesystem, error)

func (*InMemorySnapshot) RootDirEntries

func (s *InMemorySnapshot) RootDirEntries() []string

func (*InMemorySnapshot) WriteTo

type MemFilesystem

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

func NewMemFilesystem

func NewMemFilesystem(maxTotalStorageSize core.ByteCount) *MemFilesystem

func NewMemFilesystemFromSnapshot

func NewMemFilesystemFromSnapshot(snapshot core.FilesystemSnapshot, maxTotalStorageSize core.ByteCount) *MemFilesystem

func (*MemFilesystem) Absolute

func (fs *MemFilesystem) Absolute(path string) (string, error)

func (*MemFilesystem) Capabilities

func (fs *MemFilesystem) Capabilities() billy.Capability

Capabilities implements the Capable interface.

func (*MemFilesystem) Chroot

func (fs *MemFilesystem) Chroot(path string) (billy.Filesystem, error)

func (*MemFilesystem) Close

func (fls *MemFilesystem) Close(ctx *core.Context) error

func (*MemFilesystem) Create

func (fs *MemFilesystem) Create(filename string) (billy.File, error)

func (*MemFilesystem) Events

func (fls *MemFilesystem) Events() *memds.TSArrayQueue[Event]

func (*MemFilesystem) GetWatchers

func (fls *MemFilesystem) GetWatchers() []*VirtualFilesystemWatcher

func (*MemFilesystem) Join

func (fs *MemFilesystem) Join(elem ...string) string

func (*MemFilesystem) Lstat

func (fs *MemFilesystem) Lstat(filename string) (os.FileInfo, error)

func (*MemFilesystem) MkdirAll

func (fs *MemFilesystem) MkdirAll(path string, perm os.FileMode) error

func (*MemFilesystem) Open

func (fs *MemFilesystem) Open(filename string) (billy.File, error)

func (*MemFilesystem) OpenFile

func (fs *MemFilesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

func (*MemFilesystem) ReadDir

func (fs *MemFilesystem) ReadDir(path string) ([]os.FileInfo, error)
func (fs *MemFilesystem) Readlink(link string) (string, error)

func (*MemFilesystem) Remove

func (fs *MemFilesystem) Remove(filename string) error

func (*MemFilesystem) Rename

func (fs *MemFilesystem) Rename(from, to string) error

func (*MemFilesystem) Root

func (fs *MemFilesystem) Root() string

func (*MemFilesystem) Stat

func (fs *MemFilesystem) Stat(filename string) (os.FileInfo, error)
func (fs *MemFilesystem) Symlink(target, link string) error

func (*MemFilesystem) TakeFilesystemSnapshot

func (fs *MemFilesystem) TakeFilesystemSnapshot(config core.FilesystemSnapshotConfig) (core.FilesystemSnapshot, error)

func (*MemFilesystem) TempFile

func (fs *MemFilesystem) TempFile(dir, prefix string) (billy.File, error)

func (*MemFilesystem) Watcher

type MetaFilesystem

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

MetaFilesystem is a filesystem that works on top of another filesystem, it stores its metadata in a file and file contents in regular files.

func OpenMetaFilesystem

func OpenMetaFilesystem(ctx *core.Context, underlying billy.Basic, opts MetaFilesystemParams) (*MetaFilesystem, error)

func (*MetaFilesystem) Absolute

func (fls *MetaFilesystem) Absolute(path string) (string, error)

func (*MetaFilesystem) Chroot

func (fls *MetaFilesystem) Chroot(path string) (billy.Filesystem, error)

func (*MetaFilesystem) Close

func (fls *MetaFilesystem) Close(ctx *core.Context) error

func (*MetaFilesystem) Create

func (fls *MetaFilesystem) Create(filename string) (billy.File, error)

func (*MetaFilesystem) DoWithContext

func (fls *MetaFilesystem) DoWithContext(ctx *core.Context, fn func() error) error

DoWithContext implements core.IDoWithContext.

func (*MetaFilesystem) Events

func (fls *MetaFilesystem) Events() *memds.TSArrayQueue[Event]

func (*MetaFilesystem) GetWatchers

func (fls *MetaFilesystem) GetWatchers() []*VirtualFilesystemWatcher

func (*MetaFilesystem) Join

func (fls *MetaFilesystem) Join(elem ...string) string

func (*MetaFilesystem) Lstat

func (fls *MetaFilesystem) Lstat(filename string) (os.FileInfo, error)

func (*MetaFilesystem) MkdirAll

func (fls *MetaFilesystem) MkdirAll(path string, perm os.FileMode) error

func (*MetaFilesystem) MkdirAllNoLock

func (fls *MetaFilesystem) MkdirAllNoLock(path string, perm os.FileMode) error

func (*MetaFilesystem) MkdirAllNoLock_

func (fls *MetaFilesystem) MkdirAllNoLock_(path string, perm os.FileMode, tx *buntdb.Tx) error

func (*MetaFilesystem) Open

func (fls *MetaFilesystem) Open(filename string) (billy.File, error)

func (*MetaFilesystem) OpenFile

func (fls *MetaFilesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

func (*MetaFilesystem) ReadDir

func (fls *MetaFilesystem) ReadDir(path string) ([]os.FileInfo, error)
func (fls *MetaFilesystem) Readlink(link string) (string, error)

func (*MetaFilesystem) Remove

func (fls *MetaFilesystem) Remove(filename string) error

func (*MetaFilesystem) Rename

func (fls *MetaFilesystem) Rename(from, to string) error

func (*MetaFilesystem) Root

func (fls *MetaFilesystem) Root() string

func (*MetaFilesystem) Stat

func (fls *MetaFilesystem) Stat(filename string) (os.FileInfo, error)
func (fls *MetaFilesystem) Symlink(target, link string) error

func (*MetaFilesystem) TakeFilesystemSnapshot

func (fls *MetaFilesystem) TakeFilesystemSnapshot(config core.FilesystemSnapshotConfig) (core.FilesystemSnapshot, error)

func (*MetaFilesystem) TempFile

func (fls *MetaFilesystem) TempFile(dir, prefix string) (billy.File, error)

func (*MetaFilesystem) Walk

func (fls *MetaFilesystem) Walk(visit func(normalizedPath string, path core.Path, metadata *metaFsFileMetadata) error) error

func (*MetaFilesystem) Watcher

type MetaFilesystemParams

type MetaFilesystemParams struct {
	//used if underlying is a filesystem
	Dir string

	//maximum space usable in the underlying filesystem, ignored if dir is false.
	//The value should be greater or equal to METAFS_MIN_USABLE_SPACE, it defaults to METAFS_MIN_USABLE_SPACE.
	MaxUsableSpace core.ByteCount

	//The value defaults to METAFS_DEFAULT_MAX_FILE_COUNT, ignored if dir is false.
	MaxFileCount int32

	//The value defaults to METAFS_DEFAULT_MAX_PARALLEL_FILE_CREATION_COUNT, ignored if dir is false.
	MaxParallelCreationCount int16
}

type OsFilesystem

type OsFilesystem struct {
	osfs.OS
	// contains filtered or unexported fields
}

func GetOsFilesystem

func GetOsFilesystem() *OsFilesystem

func (OsFilesystem) Absolute

func (fs OsFilesystem) Absolute(path string) (string, error)

func (OsFilesystem) Chroot

func (fs OsFilesystem) Chroot(path string) (billy.Filesystem, error)

func (*OsFilesystem) Create

func (fs *OsFilesystem) Create(filename string) (billy.File, error)

func (*OsFilesystem) Lstat

func (fs *OsFilesystem) Lstat(filename string) (fs.FileInfo, error)

func (*OsFilesystem) MkdirAll

func (fs *OsFilesystem) MkdirAll(filename string, perm fs.FileMode) error

func (*OsFilesystem) Open

func (fs *OsFilesystem) Open(filename string) (billy.File, error)

func (*OsFilesystem) OpenFile

func (fs *OsFilesystem) OpenFile(filename string, flag int, perm fs.FileMode) (billy.File, error)

func (*OsFilesystem) OsFs

func (fs *OsFilesystem) OsFs()

func (*OsFilesystem) ReadDir

func (fs *OsFilesystem) ReadDir(path string) ([]fs.FileInfo, error)
func (fs *OsFilesystem) Readlink(link string) (string, error)

func (*OsFilesystem) Remove

func (fs *OsFilesystem) Remove(filename string) error

func (*OsFilesystem) Rename

func (fs *OsFilesystem) Rename(from, to string) error

we override Rename because osfs.OS.Rename is not the same as os.Rename

func (OsFilesystem) Root

func (fs OsFilesystem) Root() string

func (*OsFilesystem) Stat

func (fs *OsFilesystem) Stat(filename string) (fs.FileInfo, error)
func (fs *OsFilesystem) Symlink(target string, link string) error

func (*OsFilesystem) TempFile

func (fs *OsFilesystem) TempFile(dir string, prefix string) (billy.File, error)

func (*OsFilesystem) WithSecondaryContext

func (fs *OsFilesystem) WithSecondaryContext(ctx *core.Context) any

func (*OsFilesystem) WithoutSecondaryContext

func (fs *OsFilesystem) WithoutSecondaryContext() any

type RemoveFile

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

RemoveFile is an effect removing a file (regular file, directory, ...).

func (*RemoveFile) Apply

func (e *RemoveFile) Apply(ctx *core.Context) (finalErr error)

func (RemoveFile) CheckPermissions

func (e RemoveFile) CheckPermissions(ctx *core.Context) error

func (RemoveFile) IsApplied

func (e RemoveFile) IsApplied() bool

func (RemoveFile) IsApplying

func (e RemoveFile) IsApplying() bool

func (RemoveFile) PermissionKind

func (e RemoveFile) PermissionKind() core.PermissionKind

func (RemoveFile) Resources

func (e RemoveFile) Resources() []core.ResourceName

func (RemoveFile) Reversability

func (e RemoveFile) Reversability(*core.Context) core.Reversability

func (*RemoveFile) Reverse

func (e *RemoveFile) Reverse(ctx *core.Context) error

type RenameFile

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

func (*RenameFile) Apply

func (e *RenameFile) Apply(ctx *core.Context) error

func (RenameFile) CheckPermissions

func (e RenameFile) CheckPermissions(ctx *core.Context) error

func (RenameFile) IsApplied

func (e RenameFile) IsApplied() bool

func (RenameFile) IsApplying

func (e RenameFile) IsApplying() bool

func (RenameFile) PermissionKind

func (e RenameFile) PermissionKind() core.PermissionKind

func (RenameFile) Resources

func (e RenameFile) Resources() []core.ResourceName

func (RenameFile) Reversability

func (e RenameFile) Reversability(*core.Context) core.Reversability

func (RenameFile) Reverse

func (e RenameFile) Reverse(ctx *core.Context) error

type SortableFileInfo

type SortableFileInfo []os.FileInfo

func (SortableFileInfo) Len

func (a SortableFileInfo) Len() int

func (SortableFileInfo) Less

func (a SortableFileInfo) Less(i, j int) bool

func (SortableFileInfo) Swap

func (a SortableFileInfo) Swap(i, j int)

type VirtualFilesystemWatcher

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

func (*VirtualFilesystemWatcher) Close

func (w *VirtualFilesystemWatcher) Close() error

type WatchableVirtualFilesystem

type WatchableVirtualFilesystem interface {
	ClosableFilesystem

	//Watcher creates a new Watcher.
	Watcher(evs *FilesystemEventSource) *VirtualFilesystemWatcher

	//GetWatchers returns a copy of the list of current watchers, it is preferrable to not return
	//stopped watchers.
	GetWatchers() []*VirtualFilesystemWatcher

	//Events() returns the ACTUAL queue of Events.
	//If the filesystem is properly added to the watchedVirtualFilesystems, it is periodically emptied by the watcher managing goroutine.
	//Wathever it is watched, the filesystem is responsible for removing old Events, especially after a recent event.
	//Old is specified as being >= OLD_EVENT_MIN_AGE.
	Events() *memds.TSArrayQueue[Event]
}

WatchableVirtualFilesystem is implemented by non-OS filesystems that can track FS events.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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