Documentation
¶
Index ¶
- Constants
- Variables
- func ApplyOnly(fls *FS, ss ...settings.Setting) error
- func ConvertExpToTesting(ll lines) lines
- func Copy(fsSrc, fsSnk *FS) error
- func IsEqualFileInfo(fi, other fs.FileInfo) bool
- func IsRoot(path string) bool
- func IsRooted(path string) bool
- func MemFS() settings.Setting
- func Register(fs *FS, oo ...settings.Setting) settings.Setting
- func TrimRoot(path string) string
- func WD(rd string) settings.Setting
- type FS
- func (fs *FS) Append(name string, perm os.FileMode) (fs.File, error)
- func (fs *FS) IsInMemory() bool
- func (fs *FS) MkdirAll(name string, perm fs.FileMode) error
- func (fs *FS) Open(name string) (fs.File, error)
- func (fs *FS) ReadDir(name string) ([]fs.DirEntry, error)
- func (fs *FS) ReadFile(name string) ([]byte, error)
- func (fls *FS) ReadFromParent(dir, name string) ([]byte, error)
- func (fs *FS) RemoveAll(name string) error
- func (fs *FS) Stat(name string) (fs.FileInfo, error)
- func (fs *FS) WD() string
- func (fs *FS) WriteFile(name string, data []byte, perm fs.FileMode) error
- type FnAppend
- type FnIsInMem
- type FnMkdirAll
- type FnOpen
- type FnReadDir
- type FnReadFile
- type FnRemoveAll
- type FnStat
- type FnWriteFile
- type MemModTimeSetter
- type MemPermissionSetter
Constants ¶
const MemWDMode = 0777
Variables ¶
var AdaptFS = struct { Open func(func(FnOpen) FnOpen) settings.Setting Append func(func(FnAppend) FnAppend) settings.Setting ReadFile func(func(FnReadFile) FnReadFile) settings.Setting Stat func(func(FnStat) FnStat) settings.Setting ReadDir func(func(FnReadDir) FnReadDir) settings.Setting WriteFile func(func(FnWriteFile) FnWriteFile) settings.Setting MkdirAll func(func(FnMkdirAll) FnMkdirAll) settings.Setting RemoveAll func(func(FnRemoveAll) FnRemoveAll) settings.Setting IsInMem func(func(FnIsInMem) FnIsInMem) settings.Setting }{ func(fn func(FnOpen) FnOpen) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.open = fn(fs.open) return nil } }, func(fn func(FnAppend) FnAppend) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.append = fn(fs.append) return nil } }, func(fn func(FnReadFile) FnReadFile) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.readFile = fn(fs.readFile) return nil } }, func(fn func(FnStat) FnStat) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.stat = fn(fs.stat) return nil } }, func(fn func(FnReadDir) FnReadDir) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.readDir = fn(fs.readDir) return nil } }, func(fn func(FnWriteFile) FnWriteFile) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.writeFile = fn(fs.writeFile) return nil } }, func(fn func(FnMkdirAll) FnMkdirAll) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.mkdirAll = fn(fs.mkdirAll) return nil } }, func(fn func(FnRemoveAll) FnRemoveAll) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.rmAll = fn(fs.rmAll) return nil } }, func(fn func(FnIsInMem) FnIsInMem) settings.Setting { return func(occ *settings.Contexts) error { fs := otx(occ) fs.ensureInitialization() fs.isInMem = fn(fs.isInMem) return nil } }, }
AdaptFS provides methods to provide options to adapt a file system's methods. NOTE if you want to adapt the methods of an in-memory file system be sure to apply first the fs.MemFS-option before applying any of the AdaptFS-options.
var ErrFlag = errors.New("fs: mem: open file: given flags are not supported")
var ErrRoot = errors.New("fs: mem: system root can't be removed")
var ErrUnrooted = errors.New("mem-fs expects file/dir to be " +
"rooted if no working-dir set")
var ErrWDMissing = errors.New("expect file system to copy to have " +
"a working dir")
var ErrWDSystemRoot = errors.New("expect file system to copy to " +
"have a more specific working dir than system root")
var ErrWriteAtInAppendMode = errors.New("os: invalid use of WriteAt on file opened with O_APPEND")
var (
RootedErr = "dir: FS: set rooted working directory"
)
var SystemRoot = func() string { return os.Getenv("SystemDrive") + string(os.PathSeparator) }()
SystemRoot is an os independent root of an os file system.
var SystemRootLower = func() string { return strings.ToLower(SystemRoot) }()
SystemRoot is an os independent root of an os file system converted to lower runes e.g.: C:\ => c:\.
Functions ¶
func ApplyOnly ¶
ApplyOnly given options oo to given file system instance fls. ApplyOnly fails if one of its option-applications fails.
func ConvertExpToTesting ¶
func ConvertExpToTesting(ll lines) lines
ConvertExpToTesting converts the exp.ASSERT(t, ...) lines of a test function to a exp := testing.ASSERT(t, ...) and exp.ASSERT(...) lines.
func Copy ¶
Copy regular files with their directories from file system fsSrc to the file system fsSnk. Copy fails if fsSrc is not in memory but has no working directory or fs.SystemRoot as working directory set. (Just as precaution; if needed an option could be added preventing this check.) It fails also if one of the file system operations on either the source or the sink fails.
func IsEqualFileInfo ¶
IsEqualFileInfo returns true if given file info fi's method values of IsDir, Mode, Name, Size and ModTime are equal to other given file info's corresponding method value.
func IsRooted ¶
IsRooted returns true if given path is either prefixed by fs.SystemRoot or by fs.SystemRootLower
Types ¶
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS is an adaptable (mockable) abstraction of an file system. Compared to "io/fs" it allows for absolute paths, i.e. new(FS).ReadFile('/Users/me/a/file') will not fail if the path exists on the system. It allows for windows paths, one can write to a path and one can adapt an FS-instance's methods. The later feature is also used internally to provide an in-memory file system see fs.MemFS.
func Apply ¶
Apply given options oo to given file system instance fls. Apply fails if one of its option-applications fails and returns otherwise fls to use Apply as sort of an constructor:
fls, err := fs.Apply(new(fs.FS), fs.MemFS)
func CopyToMem ¶
CopyToMem expects given file system fs to be rooted to a directory more specific than the fs.SystemRoot or to be an in-memory fs and returns an in-memory copy as long as fs only contains directories and regular files. Given options are applied to the copy of fs.
func (*FS) IsInMemory ¶
func (*FS) Open ¶
Open file with given name in given file system fs. File system fails with fs.NotExists if name doesn't exist in fs otherwise a fs.File instance is returned. TODO: the mem-implementation allows als to write to an opened file while the default os.Open does not. It is planned to make them behave equally. But then we don't have any way to change a file. I.e. we need to add an OpenRW-method if we want to avoid to implement all the possible flags and their combination.
func (*FS) WD ¶
WD returns a set rooted working directory which defaults to the os' working directory if fs is not an in-memory fs otherwise it defaults zero. In the later case case names are expected to be absolute paths otherwise names that are not prefixed by fs.SystemRoot are interpreted relative to WD.
type FnReadFile ¶
type FnRemoveAll ¶
type MemModTimeSetter ¶
MemModTimeSetter is an fs.FileInfo extension that allows to set the a files modification time.
type MemPermissionSetter ¶
MemPermissionSetter is an fs.FileInfo extension that allows to set the a files permission bits.