Documentation
¶
Index ¶
- Constants
- func ConcatFiles(fs FS, sources []string, target string) (err error)
- func CopyDir(vfs FS, srcRoot, destRoot string, recursive bool, ...) error
- func CopyFile(fs FS, source string, target string) error
- func DirSize(fs FS, path string, excludes ...string) (int64, error)
- func DirSizeMB(fs FS, path string, excludes ...string) (uint, error)
- func Exists(fs FS, path string, follow ...bool) (bool, error)
- func FindFile(vfs FS, rootDir string, patterns ...string) (string, error)
- func FindFiles(vfs FS, rootDir string, pattern string) ([]string, error)
- func FindKernel(fs FS, rootDir string) (string, string, error)
- func FindKernelHmac(fs FS, kernel string) (string, error)
- func ForceRemoveAll(vfs FS, path string) error
- func IsDir(f FS, path string, follow ...bool) (bool, error)
- func LoadEnvFile(fs FS, file string) (map[string]string, error)
- func MkdirAll(fileSystem FS, path string, perm fs.FileMode) error
- func ReadLink(fs FS, name string) (string, error)
- func ResolveLink(vfs FS, path string, rootDir string, depth int) (string, error)
- func TempDir(fs FS, dir, prefix string) (name string, err error)
- func TempFile(fs FS, dir, pattern string) (f *os.File, err error)
- func WalkDirFs(fs FS, root string, fn fs.WalkDirFunc) error
- func WriteEnvFile(fs FS, envs map[string]string, filename string) error
- type FS
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func ConcatFiles ¶
ConcatFiles copies source files to a target file using the FS interface. Source files are concatenated into the target file in the given order. If the target is a directory, the source is copied into that directory using the name of the first source file. The result keeps the file mode of the first source.
func CopyDir ¶
func CopyDir(vfs FS, srcRoot, destRoot string, recursive bool, onCopy func(destPath string) error) error
CopyDir walks over the provided source directory and copies each file under the destination directory. Optionally, a callback function may be executed for each destination path.
Does nothing if the source directory is an empty string or contains no files.
func CopyFile ¶
CopyFile copies source file to a target file using the FS interface. If the target is a directory, the source is copied into that directory using a source name file. File mode is preserved.
func DirSize ¶
DirSize returns the accumulated size of all files in a directory. The result is in bytes.
func DirSizeMB ¶
DirSizeMB returns the accumulated size of all files in a directory. The result is in megabytes.
func Exists ¶
Exists verifies if a file or directory exists. Optionally, a follow parameter may be provided to follow symlinks.
func FindFile ¶
FindFile attempts to find a file from a list of patterns on top of a given root path. Returns first match if any and returns error otherwise.
func FindFiles ¶
FindFiles attempts to find files from a given pattern on top of a root path. Returns empty list if no files are found.
func FindKernel ¶
FindKernel finds for kernel files inside a given root tree path. Returns kernel file and version. It assumes kernel files match certain patterns
func FindKernelHmac ¶
FindKernelHmac returns the path to an existing kernel .hmac file
func ForceRemoveAll ¶
ForceRemoveAll removes the specified path.
If it fails to remove some paths, it tries to reset the write permission for all files and directories and attempts a removal again.
func IsDir ¶
IsDir checks if a given path is a directory. Optionally, a follow parameter may be provided to follow symlinks.
func LoadEnvFile ¶
LoadEnvFile parses a file and constructs a map with the respective key-value pairs.
func MkdirAll ¶
MkdirAll is equivalent to os.MkdirAll but operates on an FS. Code ported from go-vfs library.
func ResolveLink ¶
ResolveLink attempts to resolve a symlink, if any. Returns the original path if not a symlink or if it can't be resolved.
func TempDir ¶
TempDir creates a temporary directory in the virtual fs dir defines the parent directory to create into, if empty it relies on the OS default TMP directory. The prefix is used to name new temporary directory.
func TempFile ¶
TempFile creates a temp file in the virtual FS. Took from afero.FS code and adapted.
Types ¶
type FS ¶
type FS interface {
Chmod(name string, mode fs.FileMode) error
Create(name string) (*os.File, error)
Link(oldname, newname string) error
Lstat(name string) (fs.FileInfo, error)
Mkdir(name string, perm fs.FileMode) error
Open(name string) (fs.File, error)
OpenFile(name string, flag int, perm fs.FileMode) (*os.File, error)
RawPath(name string) (string, error)
ReadDir(dirname string) ([]fs.DirEntry, error)
ReadFile(filename string) ([]byte, error)
Readlink(name string) (string, error)
Remove(name string) error
RemoveAll(name string) error
Rename(oldpath, newpath string) error
Stat(name string) (fs.FileInfo, error)
Symlink(oldname, newname string) error
WriteFile(filename string, data []byte, perm fs.FileMode) error
}