Documentation ¶
Overview ¶
Package orefafs implements an Afero like in memory file system.
it supports several features :
- can emulate Linux or Windows systems regardless of the host system
- supports Hard links
Index ¶
- type Options
- type OrefaFS
- func (vfs *OrefaFS) Abs(path string) (string, error)
- func (vfs *OrefaFS) Chdir(dir string) error
- func (vfs *OrefaFS) Chmod(name string, mode fs.FileMode) error
- func (vfs *OrefaFS) Chown(name string, uid, gid int) error
- func (vfs *OrefaFS) Chtimes(name string, atime, mtime time.Time) error
- func (vfs *OrefaFS) Create(name string) (avfs.File, error)
- func (vfs *OrefaFS) CreateHomeDir(u avfs.UserReader) (string, error)
- func (vfs *OrefaFS) CreateSystemDirs(basePath string) error
- func (vfs *OrefaFS) CreateTemp(dir, pattern string) (avfs.File, error)
- func (vfs *OrefaFS) EvalSymlinks(path string) (string, error)
- func (vfs *OrefaFS) Getwd() (dir string, err error)
- func (vfs *OrefaFS) Glob(pattern string) (matches []string, err error)
- func (vfs *OrefaFS) Idm() avfs.IdentityMgr
- func (vfs *OrefaFS) Lchown(name string, uid, gid int) error
- func (vfs *OrefaFS) Link(oldname, newname string) error
- func (vfs *OrefaFS) Lstat(name string) (fs.FileInfo, error)
- func (vfs *OrefaFS) Mkdir(name string, perm fs.FileMode) error
- func (vfs *OrefaFS) MkdirAll(path string, perm fs.FileMode) error
- func (vfs *OrefaFS) MkdirTemp(dir, pattern string) (string, error)
- func (vfs *OrefaFS) Name() string
- func (vfs *OrefaFS) Open(name string) (avfs.File, error)
- func (vfs *OrefaFS) OpenFile(name string, flag int, perm fs.FileMode) (avfs.File, error)
- func (vfs *OrefaFS) ReadDir(name string) ([]fs.DirEntry, error)
- func (vfs *OrefaFS) ReadFile(name string) ([]byte, error)
- func (vfs *OrefaFS) Readlink(name string) (string, error)
- func (vfs *OrefaFS) Remove(name string) error
- func (vfs *OrefaFS) RemoveAll(path string) error
- func (vfs *OrefaFS) Rename(oldname, newname string) error
- func (vfs *OrefaFS) SameFile(fi1, fi2 fs.FileInfo) bool
- func (vfs *OrefaFS) SetUMask(mask fs.FileMode)
- func (vfs *OrefaFS) SetUser(name string) (avfs.UserReader, error)
- func (vfs *OrefaFS) Stat(path string) (fs.FileInfo, error)
- func (vfs *OrefaFS) Sub(dir string) (avfs.VFS, error)
- func (vfs *OrefaFS) Symlink(oldname, newname string) error
- func (vfs *OrefaFS) TempDir() string
- func (vfs *OrefaFS) ToSysStat(info fs.FileInfo) avfs.SysStater
- func (vfs *OrefaFS) Truncate(name string, size int64) error
- func (*OrefaFS) Type() string
- func (vfs *OrefaFS) UMask() fs.FileMode
- func (vfs *OrefaFS) User() avfs.UserReader
- func (vfs *OrefaFS) WalkDir(root string, fn fs.WalkDirFunc) error
- func (vfs *OrefaFS) WriteFile(name string, data []byte, perm fs.FileMode) error
- type OrefaFile
- func (f *OrefaFile) Chdir() error
- func (f *OrefaFile) Chmod(mode fs.FileMode) error
- func (f *OrefaFile) Chown(uid, gid int) error
- func (f *OrefaFile) Close() error
- func (f *OrefaFile) Fd() uintptr
- func (f *OrefaFile) Name() string
- func (f *OrefaFile) Read(b []byte) (n int, err error)
- func (f *OrefaFile) ReadAt(b []byte, off int64) (n int, err error)
- func (f *OrefaFile) ReadDir(n int) ([]fs.DirEntry, error)
- func (f *OrefaFile) Readdirnames(n int) (names []string, err error)
- func (f *OrefaFile) Seek(offset int64, whence int) (ret int64, err error)
- func (f *OrefaFile) Stat() (info fs.FileInfo, err error)
- func (f *OrefaFile) Sync() error
- func (f *OrefaFile) Truncate(size int64) error
- func (f *OrefaFile) Write(b []byte) (n int, err error)
- func (f *OrefaFile) WriteAt(b []byte, off int64) (n int, err error)
- func (f *OrefaFile) WriteString(s string) (n int, err error)
- type OrefaInfo
- func (info *OrefaInfo) Gid() int
- func (info *OrefaInfo) Info() (fs.FileInfo, error)
- func (info *OrefaInfo) IsDir() bool
- func (info *OrefaInfo) ModTime() time.Time
- func (info *OrefaInfo) Mode() fs.FileMode
- func (info *OrefaInfo) Name() string
- func (info *OrefaInfo) Nlink() uint64
- func (info *OrefaInfo) Size() int64
- func (info *OrefaInfo) Sys() any
- func (info *OrefaInfo) Type() fs.FileMode
- func (info *OrefaInfo) Uid() int
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct { User avfs.UserReader // User is the current user of the file system. Name string // Name is the name of the file system. OSType avfs.OSType // OSType defines the operating system type. SystemDirs bool // SystemDirs must be true to create system directories. }
Options defines the initialization options of OrefaFS.
type OrefaFS ¶
type OrefaFS struct { avfs.Utils[*OrefaFS] // utils regroups common functions used by emulated file systems. // contains filtered or unexported fields }
OrefaFS implements a memory file system using the avfs.VFS interface.
func New ¶
func New() *OrefaFS
New returns a new memory file system (OrefaFS) with the default Options.
func NewWithOptions ¶
NewWithOptions returns a new memory file system (OrefaFS) with the selected Options.
func (*OrefaFS) Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func (*OrefaFS) Chdir ¶
Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func (*OrefaFS) Chmod ¶
Chmod changes the mode of the named file to mode. If the file is a symbolic link, it changes the mode of the link's target. If there is an error, it will be of type *PathError.
A different subset of the mode bits are used, depending on the operating system.
On Unix, the mode's permission bits, ModeSetuid, ModeSetgid, and ModeSticky are used.
On Windows, only the 0200 bit (owner writable) of mode is used; it controls whether the file's read-only attribute is set or cleared. The other bits are currently unused. For compatibility with Go 1.12 and earlier, use a non-zero mode. Use mode 0400 for a read-only file and 0600 for a readable+writable file.
On Plan 9, the mode's permission bits, ModeAppend, ModeExclusive, and ModeTemporary are used.
func (*OrefaFS) Chown ¶
Chown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link's target. A uid or gid of -1 means to not change that value. If there is an error, it will be of type *PathError.
On Windows or Plan 9, Chown always returns the syscall.EWINDOWS or EPLAN9 error, wrapped in *PathError.
func (*OrefaFS) Chtimes ¶
Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.
The underlying file system may truncate or round the values to a less precise time unit. If there is an error, it will be of type *PathError.
func (*OrefaFS) Create ¶
Create creates or truncates the named file. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). If successful, methods on the returned DummyFile can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.
func (*OrefaFS) CreateHomeDir ¶
func (vfs *OrefaFS) CreateHomeDir(u avfs.UserReader) (string, error)
CreateHomeDir creates and returns the home directory of a user. If there is an error, it will be of type *PathError.
func (*OrefaFS) CreateSystemDirs ¶
CreateSystemDirs creates system directories of a file system.
func (*OrefaFS) CreateTemp ¶
CreateTemp creates a new temporary file in the directory dir, opens the file for reading and writing, and returns the resulting file. The filename is generated by taking pattern and adding a random string to the end. If pattern includes a "*", the random string replaces the last "*". If dir is the empty string, CreateTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling CreateTemp simultaneously will not choose the same file. The caller can use the file's Name method to find the pathname of the file. It is the caller's responsibility to remove the file when it is no longer needed.
func (*OrefaFS) EvalSymlinks ¶
EvalSymlinks returns the path name after the evaluation of any symbolic links. If path is relative the result will be relative to the current directory, unless one of the components is an absolute symbolic link. EvalSymlinks calls Clean on the result.
func (*OrefaFS) Getwd ¶
Getwd returns a rooted name link corresponding to the current directory. If the current directory can be reached via multiple paths (due to symbolic links), Getwd may return any one of them.
func (*OrefaFS) Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.
func (*OrefaFS) Idm ¶
func (vfs *OrefaFS) Idm() avfs.IdentityMgr
Idm returns the identity manager of the file system. If the file system does not have an identity manager, avfs.DummyIdm is returned.
func (*OrefaFS) Lchown ¶
Lchown changes the numeric uid and gid of the named file. If the file is a symbolic link, it changes the uid and gid of the link itself. If there is an error, it will be of type *PathError.
On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.
func (*OrefaFS) Link ¶
Link creates newname as a hard link to the oldname file. If there is an error, it will be of type *LinkError.
func (*OrefaFS) Lstat ¶
Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.
func (*OrefaFS) Mkdir ¶
Mkdir creates a new directory with the specified name and permission bits (before umask). If there is an error, it will be of type *PathError.
func (*OrefaFS) MkdirAll ¶
MkdirAll creates a directory named name, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm (before umask) are used for all directories that MkdirAll creates. If name is already a directory, MkdirAll does nothing and returns nil.
func (*OrefaFS) MkdirTemp ¶
MkdirTemp creates a new temporary directory in the directory dir and returns the pathname of the new directory. The new directory's name is generated by adding a random string to the end of pattern. If pattern includes a "*", the random string replaces the last "*" instead. If dir is the empty string, MkdirTemp uses the default directory for temporary files, as returned by TempDir. Multiple programs or goroutines calling MkdirTemp simultaneously will not choose the same directory. It is the caller's responsibility to remove the directory when it is no longer needed.
func (*OrefaFS) Open ¶
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. If there is an error, it will be of type *PathError.
func (*OrefaFS) OpenFile ¶
OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag is passed, it is created with mode perm (before umask). If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.
func (*OrefaFS) ReadDir ¶
ReadDir reads the named directory, returning all its directory entries sorted by filename. If an error occurs reading the directory, ReadDir returns the entries it was able to read before the error, along with the error.
func (*OrefaFS) ReadFile ¶
ReadFile reads the named file and returns the contents. A successful call returns err == nil, not err == EOF. Because ReadFile reads the whole file, it does not treat an EOF from Read as an error to be reported.
func (*OrefaFS) Readlink ¶
Readlink returns the destination of the named symbolic link. If there is an error, it will be of type *PathError.
func (*OrefaFS) Remove ¶
Remove removes the named file or (empty) directory. If there is an error, it will be of type *PathError.
func (*OrefaFS) RemoveAll ¶
RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error). If there is an error, it will be of type *PathError.
func (*OrefaFS) Rename ¶
Rename renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.
func (*OrefaFS) SameFile ¶
SameFile reports whether fi1 and fi2 describe the same file. For example, on Unix this means that the device and inode fields of the two underlying structures are identical; on other systems the decision may be based on the path names. SameFile only applies to results returned by this package's Stat. It returns false in other cases.
func (*OrefaFS) SetUser ¶
func (vfs *OrefaFS) SetUser(name string) (avfs.UserReader, error)
SetUser sets and returns the current user. If the user is not found, the returned error is of type UnknownUserError.
func (*OrefaFS) Stat ¶
Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.
func (*OrefaFS) Symlink ¶
Symlink creates newname as a symbolic link to oldname. If there is an error, it will be of type *LinkError.
func (*OrefaFS) TempDir ¶
TempDir returns the default directory to use for temporary files.
On Unix systems, it returns $TMPDIR if non-empty, else /tmp. On Windows, it uses GetTempPath, returning the first non-empty value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. On Plan 9, it returns /tmp.
The directory is neither guaranteed to exist nor have accessible permissions.
func (*OrefaFS) ToSysStat ¶
ToSysStat takes a value from fs.FileInfo.Sys() and returns a value that implements interface avfs.SysStater.
func (*OrefaFS) Truncate ¶
Truncate changes the size of the named file. If the file is a symbolic link, it changes the size of the link's target. If there is an error, it will be of type *PathError.
func (*OrefaFS) WalkDir ¶
func (vfs *OrefaFS) WalkDir(root string, fn fs.WalkDirFunc) error
WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.
All errors that arise visiting files and directories are filtered by fn: see the fs.WalkDirFunc documentation for details.
The files are walked in lexical order, which makes the output deterministic but requires WalkDir to read an entire directory into memory before proceeding to walk that directory.
WalkDir does not follow symbolic links.
type OrefaFile ¶
type OrefaFile struct {
// contains filtered or unexported fields
}
OrefaFile represents an open file descriptor.
func (*OrefaFile) Chdir ¶
Chdir changes the current working directory to the file, which must be a directory. If there is an error, it will be of type *PathError.
func (*OrefaFile) Chmod ¶
Chmod changes the mode of the file to mode. If there is an error, it will be of type *PathError.
func (*OrefaFile) Chown ¶
Chown changes the numeric uid and gid of the named file. If there is an error, it will be of type *PathError.
On Windows, it always returns the syscall.EWINDOWS error, wrapped in *PathError.
func (*OrefaFile) Close ¶
Close closes the File, rendering it unusable for I/O. On files that support SetDeadline, any pending I/O operations will be canceled and return immediately with an error.
func (*OrefaFile) Fd ¶
Fd returns the integer Unix file descriptor referencing the open file. The file descriptor is valid only until f.Close is called or f is garbage collected. On Unix systems this will cause the SetDeadline methods to stop working.
func (*OrefaFile) Read ¶
Read reads up to len(b) bytes from the OrefaFile. It returns the number of bytes read and any error encountered. At end of file, Read returns 0, io.EOF.
func (*OrefaFile) ReadAt ¶
ReadAt reads len(b) bytes from the File starting at byte offset off. It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(b). At end of file, that error is io.EOF.
func (*OrefaFile) ReadDir ¶
ReadDir reads the contents of the directory associated with the file f and returns a slice of DirEntry values in directory order. Subsequent calls on the same file will yield later DirEntry records in the directory.
If n > 0, ReadDir returns at most n DirEntry records. In this case, if ReadDir returns an empty slice, it will return an error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, ReadDir returns all the DirEntry records remaining in the directory. When it succeeds, it returns a nil error (not io.EOF).
func (*OrefaFile) Readdirnames ¶
Readdirnames reads and returns a slice of names from the directory f.
If n > 0, Readdirnames returns at most n names. In this case, if Readdirnames returns an empty slice, it will return a non-nil error explaining why. At the end of a directory, the error is io.EOF.
If n <= 0, Readdirnames returns all the names from the directory in a single slice. In this case, if Readdirnames succeeds (reads all the way to the end of the directory), it returns the slice and a nil error. If it encounters an error before the end of the directory, Readdirnames returns the names read until that point and a non-nil error.
func (*OrefaFile) Seek ¶
Seek sets the offset for the next Read or Write on file to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any. The behavior of Seek on a file opened with O_APPEND is not specified.
func (*OrefaFile) Stat ¶
Stat returns the FileInfo structure describing file. If there is an error, it will be of type *PathError.
func (*OrefaFile) Sync ¶
Sync commits the current contents of the file to stable storage. Typically, this means flushing the file system's in-memory copy of recently written data to disk.
func (*OrefaFile) Truncate ¶
Truncate changes the size of the file. It does not change the I/O offset. If there is an error, it will be of type *PathError.
func (*OrefaFile) Write ¶
Write writes len(b) bytes to the File. It returns the number of bytes written and an error, if any. Write returns a non-nil error when n != len(b).
type OrefaInfo ¶
type OrefaInfo struct {
// contains filtered or unexported fields
}
OrefaInfo is the implementation of fs.FileInfo returned by Stat and Lstat.
func (*OrefaInfo) Info ¶
Info returns the FileInfo for the file or subdirectory described by the entry. The returned FileInfo may be from the time of the original directory read or from the time of the call to Info. If the file has been removed or renamed since the directory read, Info may return an error satisfying errors.Is(err, ErrNotExist). If the entry denotes a symbolic link, Info reports the information about the link itself, not the link's target.
func (*OrefaInfo) Size ¶
Size returns the length in bytes for regular files; system-dependent for others.