localfs

package
v0.0.0-...-bb2c1c1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package localfs provides an implementation of local.FS that works on a given directory of the local file system. It also provides an in-memory mocks for tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DirFS

type DirFS string

func NewDirFS

func NewDirFS(dir string) DirFS

NewDirFS returns a local.FS that makes changes to the given Cozy directory on the local disk.

func (DirFS) Mkdir

func (dir DirFS) Mkdir(path string) error

Mkdir is required by the local.FS interface.

func (DirFS) Open

func (dir DirFS) Open(path string) (fs.File, error)

Open is required by the local.FS interface.

func (DirFS) ReadDir

func (dir DirFS) ReadDir(path string) ([]fs.DirEntry, error)

ReadDir is required by the local.FS interface.

func (DirFS) RemoveAll

func (dir DirFS) RemoveAll(path string) error

RemoveAll is required by the local.FS interface.

func (DirFS) Stat

func (dir DirFS) Stat(path string) (fs.FileInfo, error)

Stat is required by the local.FS interface.

func (DirFS) ToMemFS

func (dir DirFS) ToMemFS() (*MemFS, error)

ToMemFS will create a MemFS with the same files and directories. It can be useful for testing purpose.

type MemFS

type MemFS struct {
	ByPath map[string]*memDir
}

func NewMemFS

func NewMemFS() *MemFS

NewMemFS returns an in-memory mock of local.FS for tests. TODO use https://github.com/hack-pad/hackpadfs ?

func (*MemFS) CheckInvariants

func (mem *MemFS) CheckInvariants() error

CheckInvariants check some properties of the mock. It can be used to detect some bugs in the MemFS implementation.

func (*MemFS) Mkdir

func (mem *MemFS) Mkdir(path string) error

Mkdir is required by the local.FS interface.

func (*MemFS) NextIno

func (mem *MemFS) NextIno() uint64

NextIno returns the next free inode number that can be used.

func (*MemFS) Open

func (mem *MemFS) Open(path string) (fs.File, error)

Open is required by the local.FS interface.

func (*MemFS) ReadDir

func (mem *MemFS) ReadDir(path string) ([]fs.DirEntry, error)

ReadDir is required by the local.FS interface.

func (*MemFS) RemoveAll

func (mem *MemFS) RemoveAll(path string) error

RemoveAll is required by the local.FS interface.

func (*MemFS) Stat

func (mem *MemFS) Stat(path string) (fs.FileInfo, error)

Stat is required by the local.FS interface.

type ReadOnlyFS

type ReadOnlyFS struct {
	MemFS *MemFS
}

func NewReadOnlyFS

func NewReadOnlyFS() *ReadOnlyFS

NewMemFS returns an in-memory mock of local.FS for tests that panic if any write operation is called on it.

func (*ReadOnlyFS) Mkdir

func (ro *ReadOnlyFS) Mkdir(path string) error

Mkdir is required by the local.FS interface.

func (*ReadOnlyFS) Open

func (ro *ReadOnlyFS) Open(path string) (fs.File, error)

Open is required by the local.FS interface.

func (*ReadOnlyFS) ReadDir

func (ro *ReadOnlyFS) ReadDir(path string) ([]fs.DirEntry, error)

ReadDir is required by the local.FS interface.

func (*ReadOnlyFS) RemoveAll

func (ro *ReadOnlyFS) RemoveAll(path string) error

RemoveAll is required by the local.FS interface.

func (*ReadOnlyFS) Stat

func (ro *ReadOnlyFS) Stat(path string) (fs.FileInfo, error)

Stat is required by the local.FS interface.

Jump to

Keyboard shortcuts

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