filesystem

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 43 Imported by: 2

Documentation

Overview

  • Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

  • Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.

  • SPDX-License-Identifier: Apache-2.0

Package filesystem defines utilities with regards to filesystem access./*

Distributed lock using lock files https://fileinfo.com/extension/lock

Index

Constants

View Source
const LockFilePrefix = "lockfile"
View Source
const (
	UnsetFileHandle = ^uint64(0)
)

Variables

View Source
var (
	ErrLinkNotImplemented  = fmt.Errorf("link not implemented: %w", commonerrors.ErrNotImplemented)
	ErrChownNotImplemented = fmt.Errorf("chown not implemented: %w", commonerrors.ErrNotImplemented)
	ErrPathNotExist        = errors.New("readdirent: no such file or directory")
)
View Source
var (
	// ZipFileExtensions returns a list of commonly used extensions to describe zip archive files
	// This list was populated from [Wikipedia](https://en.wikipedia.org/wiki/List_of_archive_formats)
	ZipFileExtensions = []string{zipExt, zipxExt, sevenzipExt, sevenzipmacExt, gzipExt, targzExt, targz2Ext, xzExt, lzipExt, lzmaExt, rzipExt, packExt, compressExt, jarExt}
	// ZipMimeTypes returns a list of MIME types describing zip archive files.
	ZipMimeTypes = []string{zipMimeType, zipxMimeType, zipCompressedMimeType, jarMimeType, epubMimeType}
)
View Source
var (
	FileSystemTypes = []FilesystemType{StandardFS, InMemoryFS}
)

Functions

func Chmod added in v1.54.0

func Chmod(name string, mode os.FileMode) error

Chmod changes the file mode of a filesystem item.

func CleanDir

func CleanDir(dir string) (err error)

func ConvertFileSystemError added in v1.38.0

func ConvertFileSystemError(err error) error

ConvertFileSystemError converts file system error into common errors

func ConvertToIOFilesystem added in v1.39.0

func ConvertToIOFilesystem(filesystem FS) (fs.FS, error)

ConvertToIOFilesystem converts a filesystem FS to a io/fs FS

func ConvertToOSFile added in v1.59.0

func ConvertToOSFile(f File) (osFile *os.File)

ConvertToOSFile converts a file to a `os` implementation of a file for certain use-cases where functions have not moved to using `fs.File`.

func Copy

func Copy(src string, dest string) (err error)

func CopyBetweenFS

func CopyBetweenFS(ctx context.Context, srcFs FS, src string, destFs FS, dest string) (err error)

func CopyBetweenFSWithExclusionPatterns added in v1.20.0

func CopyBetweenFSWithExclusionPatterns(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionPatterns ...string) (err error)

func CopyBetweenFSWithExclusionRegexes added in v1.20.0

func CopyBetweenFSWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, exclusionSrcFsRegexes []*regexp.Regexp, exclusionDestFsRegexes []*regexp.Regexp) (err error)

func CopyToDirectory added in v1.26.0

func CopyToDirectory(src, destDirectory string) error

CopyToDirectory copies a src to a directory destDirectory which will be created as such if not present.

func CopyToDirectoryWithContext added in v1.26.0

func CopyToDirectoryWithContext(ctx context.Context, src, destDirectory string) error

CopyToDirectoryWithContext copies a src to a directory destDirectory which will be created as such if not present.

func CopyToFile added in v1.26.0

func CopyToFile(srcFile, destFile string) error

CopyToFile copies a file into another file

func CopyToFileWithContext added in v1.26.0

func CopyToFileWithContext(ctx context.Context, srcFile, destFile string) error

CopyToFileWithContext copies a file into another file

func CurrentDirectory

func CurrentDirectory() (string, error)

func EndsWithPathSeparator added in v1.26.0

func EndsWithPathSeparator(fs FS, filePath string) bool

EndsWithPathSeparator states whether a path is ending with a path separator of not

func ExcludeAll

func ExcludeAll(files []string, exclusionPatterns ...string) ([]string, error)

ExcludeAll excludes files

func ExcludeFiles added in v1.20.0

func ExcludeFiles(files []string, regexes []*regexp.Regexp) (cleansedList []string, err error)

func Exists

func Exists(path string) bool

Exists checks if a file or folder exists

func FileTreeDepth added in v1.24.0

func FileTreeDepth(fs FS, root, filePath string) (depth int64, err error)

FileTreeDepth returns the depth of a file in a tree starting from root

func FilepathStem added in v1.13.0

func FilepathStem(fp string) string

FilepathStem returns the final path component, without its suffix.

func FindAll

func FindAll(dir string, extensions ...string) (files []string, err error)

FindAll finds all the files with extensions

func GenerateTestFileTree added in v1.25.1

func GenerateTestFileTree(t *testing.T, fs FS, testDir, basePath string, withLinks bool, fileModTime time.Time, fileAccessTime time.Time) []string

GenerateTestFileTree generates a file tree for testing purposes and returns a list of all the files and filesystem items created. testDir corresponds to the folder where the tree is createed basePath corresponds to the base path for sym links fileModTime, fileAccessTime are for specifying created files ch times

func GetFileSize

func GetFileSize(name string) (size int64, err error)

func Glob added in v1.54.0

func Glob(pattern string) ([]string, error)

Glob returns the names of all files matching pattern with support for "doublestar" (aka globstar: **) patterns You can find the children with patterns such as: **/child*, grandparent/**/child?, **/parent/*, or even just ** by itself (which will return all files and directories recursively).

func IdentityPathConverterFunc

func IdentityPathConverterFunc(path string) string

func IsDir

func IsDir(path string) (result bool, err error)

IsDir states whether it is a directory or not

func IsDirectory

func IsDirectory(fi os.FileInfo) bool

func IsEmpty

func IsEmpty(name string) (empty bool, err error)

IsEmpty checks whether a path is empty or not

func IsFile

func IsFile(path string) (result bool, err error)

IsFile states whether it is a file or not

func IsFileHandleUnset

func IsFileHandleUnset(fh uintptr) bool

func IsPathExcluded added in v1.20.0

func IsPathExcluded(path string, exclusionPatterns ...*regexp.Regexp) bool

func IsPathExcludedFromPatterns added in v1.20.0

func IsPathExcludedFromPatterns(path string, pathSeparator rune, exclusionPatterns ...string) bool

func IsPathNotExist

func IsPathNotExist(err error) bool

func IsRegularFile

func IsRegularFile(fi os.FileInfo) bool
func IsSymLink(fi os.FileInfo) bool

func ListDirTree

func ListDirTree(dirPath string, list *[]string) error

ListDirTree returns a list of files and directories recursively available under specified path

func ListDirTreeWithContextAndExclusionPatterns added in v1.20.0

func ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, fs FS, dirPath string, list *[]string, regexes []*regexp.Regexp) (err error)

func Ls

func Ls(dir string) (files []string, err error)

func LsWithExclusionPatterns added in v1.20.0

func LsWithExclusionPatterns(fs FS, dir string, regexes []*regexp.Regexp) (names []string, err error)

func Lstat

func Lstat(name string) (fileInfo os.FileInfo, err error)

func MkDir

func MkDir(dir string) (err error)

MkDir makes directory (equivalent to mkdir -p)

func Move

func Move(src string, dest string) error

Move moves a file (equivalent to mv)

func MoveBetweenFS

func MoveBetweenFS(ctx context.Context, srcFs FS, src string, destFs FS, dest string) (err error)

func NewExclusionRegexList added in v1.20.0

func NewExclusionRegexList(pathSeparator rune, exclusionPatterns ...string) ([]*regexp.Regexp, error)

func NewExtendedOsFs

func NewExtendedOsFs() afero.Fs

func NewOSPathExistRule added in v1.58.0

func NewOSPathExistRule(when bool) validation.Rule

NewOSPathExistRule returns a validation rule to use in configuration. The rule checks whether a string is a valid path for the Operating system's filesystem and actually exists. `when` describes whether the rule is enforced or not.

func NewOSPathValidationRule added in v1.58.0

func NewOSPathValidationRule(when bool) validation.Rule

NewOSPathValidationRule returns a validation rule to use in configuration. The rule checks whether a string is a valid path for the Operating System's filesystem. `when` describes whether the rule is enforced or not

func NewPathExistRule added in v1.58.0

func NewPathExistRule(filesystem FS, when bool) validation.Rule

NewPathExistRule returns a validation rule to use in configuration. The rule checks whether a string is a valid not empty path and actually exists. `when` describes whether the rule is enforced or not.

func NewPathValidationRule added in v1.58.0

func NewPathValidationRule(filesystem FS, when bool) validation.Rule

NewPathValidationRule returns a validation rule to use in configuration. The rule checks whether a string is a valid not empty path. `when` describes whether the rule is enforced or not

func NewZipFileSystem added in v1.42.0

func NewZipFileSystem(fs FS, source string, limits ILimits) (zipFs ICloseableFS, zipFile File, err error)

NewZipFileSystem returns a filesystem over the contents of a .zip file. Warning: After use of the filesystem, it is crucial to close the zip file (zipFile) which has been opened from source for the entirety of the filesystem use session. fs corresponds to the filesystem to use to find the zip file.

func NewZipFileSystemFromStandardFileSystem added in v1.42.0

func NewZipFileSystemFromStandardFileSystem(source string, limits ILimits) (ICloseableFS, File, error)

NewZipFileSystemFromStandardFileSystem returns a zip filesystem similar to NewZipFileSystem but assumes the zip file described by source can be found on the standard file system.

func PathSeparator

func PathSeparator() rune

func ReadFile

func ReadFile(name string) ([]byte, error)

func ReadFileContent added in v1.38.0

func ReadFileContent(ctx context.Context, file File) ([]byte, error)

ReadFileContent reads the file content.

func ReadFileWithLimits added in v1.15.0

func ReadFileWithLimits(filename string, limits ILimits) ([]byte, error)

func RemoveWithPrivileges added in v1.50.0

func RemoveWithPrivileges(ctx context.Context, dir string) error

RemoveWithPrivileges removes any directory (equivalent to `sudo rm -rf`)

func Rm

func Rm(dir string) error

func Stat

func Stat(name string) (os.FileInfo, error)

func SubDirectories

func SubDirectories(directory string) ([]string, error)

func TempDir

func TempDir(dir string, prefix string) (name string, err error)

func TempDirInTempDir

func TempDirInTempDir(prefix string) (name string, err error)

func TempDirectory

func TempDirectory() string

func TouchTempFile added in v1.54.0

func TouchTempFile(dir string, prefix string) (filename string, err error)

TouchTempFile creates an empty file in `dir` and returns it filename

func TouchTempFileInTempDir added in v1.54.0

func TouchTempFileInTempDir(prefix string) (filename string, err error)

TouchTempFileInTempDir creates an empty file in temp directory and returns it filename

func Unzip

func Unzip(source, destination string) ([]string, error)

Unzip unzips an source archive file into destination.

func UnzipWithContextAndLimits added in v1.24.0

func UnzipWithContextAndLimits(ctx context.Context, source string, destination string, limits ILimits) ([]string, error)

UnzipWithContextAndLimits unzips an source archive file into destination.

func WriteFile added in v1.27.0

func WriteFile(filename string, data []byte, perm os.FileMode) error

WriteFile writes data to a file

func Zip

func Zip(source string, destination string) error

Zip zips a source directory into a destination archive

Types

type DiskUsage

type DiskUsage interface {
	GetTotal() uint64
	GetFree() uint64
	GetUsed() uint64
	GetUsedPercent() float64
	GetInodesTotal() uint64
	GetInodesUsed() uint64
	GetInodesFree() uint64
	GetInodesUsedPercent() float64
}

type ExtendedOsFs

type ExtendedOsFs struct {
	afero.OsFs
}

ExtendedOsFs extends afero.OsFs and is a Fs implementation that uses functions provided by the os package.

func (*ExtendedOsFs) ChownIfPossible

func (c *ExtendedOsFs) ChownIfPossible(name string, uid int, gid int) error

func (*ExtendedOsFs) ForceRemoveIfPossible added in v1.50.0

func (c *ExtendedOsFs) ForceRemoveIfPossible(path string) error

func (*ExtendedOsFs) LinkIfPossible

func (c *ExtendedOsFs) LinkIfPossible(oldname, newname string) (err error)

type FS

type FS interface {
	// Open opens a file. The following is for being able to use `doublestar`. Use GenericOpen instead.
	Open(name string) (doublestar.File, error)
	// GenericOpen opens a file for reading. It opens the named file with specified flag (O_RDONLY etc.).
	// See os.Open()
	GenericOpen(name string) (File, error)
	// OpenFile opens a file using the given flags and the given mode.
	// OpenFile is the generalized open call
	// most users will use GenericOpen or Create instead.
	// See os.OpenFile
	OpenFile(name string, flag int, perm os.FileMode) (File, error)
	// CreateFile creates a file.
	CreateFile(name string) (File, error)
	// PathSeparator returns the path separator character.
	PathSeparator() rune
	Stat(name string) (os.FileInfo, error)
	Lstat(name string) (os.FileInfo, error)
	// StatTimes returns file time information.
	StatTimes(name string) (FileTimeInfo, error)
	// GetType returns the type of the file system.
	GetType() FilesystemType
	// CleanDir removes all the files in a directory (equivalent rm -rf .../*)
	CleanDir(dir string) (err error)
	// CleanDirWithContext removes all the files in a directory (equivalent rm -rf .../*)
	CleanDirWithContext(ctx context.Context, dir string) (err error)
	// CleanDirWithContextAndExclusionPatterns removes all the files in a directory (equivalent rm -rf .../*) unless they match some exclusion pattern.
	CleanDirWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)
	// Exists checks whether a file or folder exists
	Exists(path string) bool
	// Rm removes directory (equivalent to rm -rf)
	Rm(dir string) (err error)
	// RemoveWithContext removes directory (equivalent to rm -rf)
	RemoveWithContext(ctx context.Context, dir string) (err error)
	// RemoveWithContextAndExclusionPatterns removes directory (equivalent to rm -rf) unless they match some exclusion pattern.
	RemoveWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)
	// RemoveWithPrivileges removes a directory even if it is not owned by user (equivalent to sudo rm -rf). It expects the current user to be a superuser.
	RemoveWithPrivileges(ctx context.Context, dir string) (err error)
	// IsFile states whether it is a file or not
	IsFile(path string) (result bool, err error)
	// IsDir states whether it is a directory or not
	IsDir(path string) (result bool, err error)
	// IsLink states whether it is a link or not
	IsLink(path string) (result bool, err error)
	// IsEmpty checks whether a path is empty or not
	IsEmpty(name string) (empty bool, err error)
	// MkDir makes directory (equivalent to mkdir -p)
	MkDir(dir string) (err error)
	// MkDirAll makes directory (equivalent to mkdir -p)
	MkDirAll(dir string, perm os.FileMode) (err error)
	// ExcludeAll returns the list without the path matching the exclusion patterns.
	ExcludeAll(files []string, exclusionPatterns ...string) ([]string, error)
	// Glob returns the paths of all files matching pattern with support for "doublestar" (aka globstar: **) patterns.
	Glob(pattern string) ([]string, error)
	// FindAll finds all the files with extensions
	FindAll(dir string, extensions ...string) (files []string, err error)
	// Walk walks  the file tree rooted at root, calling fn for each file or
	// directory in the tree, including root. See https://golang.org/pkg/path/filepath/#WalkDir
	Walk(root string, fn filepath.WalkFunc) error
	// WalkWithContext walks  the file tree rooted at root, calling fn for each file or
	// directory in the tree, including root. See https://golang.org/pkg/path/filepath/#WalkDir
	WalkWithContext(ctx context.Context, root string, fn filepath.WalkFunc) error
	// WalkWithContextAndExclusionPatterns walks through the file tree rooted at root, calling fn for each file or
	// directory in the tree as long as they do not match an exclusion pattern.
	WalkWithContextAndExclusionPatterns(ctx context.Context, root string, fn filepath.WalkFunc, exclusionPatterns ...string) error
	// Ls lists all files and directory (equivalent to ls)
	Ls(dir string) (files []string, err error)
	// LsWithExclusionPatterns lists all files and directory (equivalent to ls) but exclude the ones matching the exclusion patterns.
	LsWithExclusionPatterns(dir string, exclusionPatterns ...string) (files []string, err error)
	// LsFromOpenedDirectory lists all files and directory (equivalent to ls)
	LsFromOpenedDirectory(dir File) (files []string, err error)
	// Lls lists all files and directory (equivalent to ls -l)
	Lls(dir string) (files []os.FileInfo, err error)
	// LlsFromOpenedDirectory lists all files and directory (equivalent to ls -l)
	LlsFromOpenedDirectory(dir File) (files []os.FileInfo, err error)
	// CopyToFile copies a file to another file.
	CopyToFile(srcFile, destFile string) error
	// CopyToFileWithContext copies a file to another file similarly to CopyToFile.
	CopyToFileWithContext(ctx context.Context, srcFile, destFile string) error
	// CopyToDirectory copies a src to a directory  destDirectory which will be created as such if not present.
	CopyToDirectory(src, destDirectory string) error
	// CopyToDirectoryWithContext copies a src to a directory similarly to CopyToDirectory.
	CopyToDirectoryWithContext(ctx context.Context, src, destDirectory string) error
	// Copy copies files and directory (equivalent to [POSIX cp -r](https://www.unix.com/man-page/posix/1P/cp/) or DOS `copy` or `shutil.copy()`/`shutil.copytree()` in [python](https://docs.python.org/3/library/shutil.html#shutil.copy))
	// It should be noted that although the behaviour should match `cp -r` in most cases, there may be some corner cases in which the behaviour of Copy may differ slightly.
	// For instance, if the destination `dest` does not exist and the source is a file, then the destination will be a file unless the destination ends with a path separator and thus, the intention was to consider it as a folder.
	Copy(src string, dest string) (err error)
	// CopyWithContext copies files and directory similar to Copy.
	// Nonetheless, this function should be preferred over Copy as it is context aware, meaning it is possible to stop the copy if it is taking too long or if context is cancelled.
	CopyWithContext(ctx context.Context, src string, dest string) (err error)
	// CopyWithContextAndExclusionPatterns copies files and directory like CopyWithContext but ignores any file matching the exclusion pattern.
	CopyWithContextAndExclusionPatterns(ctx context.Context, src string, dest string, exclusionPatterns ...string) (err error)
	// Move moves a file (equivalent to mv)
	Move(src string, dest string) (err error)
	// MoveWithContext moves a file (equivalent to mv)
	MoveWithContext(ctx context.Context, src string, dest string) (err error)
	// TempDir creates a temp directory
	TempDir(dir string, prefix string) (name string, err error)
	// TempDirInTempDir creates a temp directory in temp directory.
	TempDirInTempDir(prefix string) (name string, err error)
	// TempFile creates a temp file
	TempFile(dir string, pattern string) (f File, err error)
	// TouchTempFile creates an empty temporary file in dir and returns its path.
	TouchTempFile(dir string, pattern string) (filename string, err error)
	// TempFileInTempDir creates a temp file in temp directory.
	TempFileInTempDir(pattern string) (f File, err error)
	// TouchTempFileInTempDir creates an empty temporary  in temp directory and returns its path.
	TouchTempFileInTempDir(pattern string) (filename string, err error)
	// TempDirectory returns the temp directory.
	TempDirectory() string
	// CurrentDirectory returns current directory.
	CurrentDirectory() (string, error)
	// ReadFile reads a file and returns its content.
	ReadFile(filename string) ([]byte, error)
	// ReadFileWithContext reads a file but with control of a context and returns its content.
	ReadFileWithContext(ctx context.Context, filename string) ([]byte, error)
	// ReadFileWithLimits reads a file and returns its content. Nonetheless, it stops with EOF after FileSystemLimits are exceeded.
	ReadFileWithLimits(filename string, limits ILimits) ([]byte, error)
	// ReadFileWithContextAndLimits reads a file and returns its content. Limits and context are taken into account during the reading process.
	ReadFileWithContextAndLimits(ctx context.Context, filename string, limits ILimits) ([]byte, error)
	// ReadFileContent reads a file and returns its content. Limits and context are taken into account during the reading process.
	ReadFileContent(ctx context.Context, file File, limits ILimits) ([]byte, error)
	// WriteFile writes data to a file named by filename.
	// If the file does not exist, WriteFile creates it with permissions perm;
	// otherwise WriteFile truncates it before writing.
	WriteFile(filename string, data []byte, perm os.FileMode) error
	// WriteFileWithContext writes data to a file named by filename.
	// It works like WriteFile but is also controlled by a context.
	WriteFileWithContext(ctx context.Context, filename string, data []byte, perm os.FileMode) error
	// WriteToFile writes data from a reader to a file named by filename.
	// If the file does not exist, WriteToFile creates it with permissions perm;
	// otherwise WriteFile truncates it before writing.
	// It returns the number of bytes written.
	WriteToFile(ctx context.Context, filename string, reader io.Reader, perm os.FileMode) (written int64, err error)
	// GarbageCollect runs the Garbage collector on the filesystem (removes any file which has not been accessed for a certain duration)
	GarbageCollect(root string, durationSinceLastAccess time.Duration) error
	// GarbageCollectWithContext runs the Garbage collector on the filesystem (removes any file which has not been accessed for a certain duration)
	GarbageCollectWithContext(ctx context.Context, root string, durationSinceLastAccess time.Duration) error
	// Chmod changes the mode of the named file to mode.
	Chmod(name string, mode os.FileMode) error
	// ChmodRecursively changes the mode of anything within the `path`.
	ChmodRecursively(ctx context.Context, path string, mode os.FileMode) error
	// Chtimes changes the access and modification times of the named file
	Chtimes(name string, atime time.Time, mtime time.Time) error
	// Chown changes the numeric uid and gid of the named file.
	Chown(name string, uid, gid int) error
	// ChownRecursively changes recursively the numeric uid and gid of any sub items of `path`.
	ChownRecursively(ctx context.Context, path string, uid, gid int) error
	// ChangeOwnership changes the ownership of the named file.
	ChangeOwnership(name string, owner *user.User) error
	// ChangeOwnershipRecursively changes the ownership anything within the path.
	ChangeOwnershipRecursively(ctx context.Context, path string, owner *user.User) error
	// FetchOwners returns the numeric uid and gid of the named file
	FetchOwners(name string) (uid, gid int, err error)
	// FetchFileOwner returns the owner of the named file.
	FetchFileOwner(name string) (owner *user.User, err error)
	// Link creates newname as a hard link to the oldname file
	Link(oldname, newname string) error
	// Readlink returns the destination of the named symbolic link.
	Readlink(name string) (string, error)
	// Symlink creates newname as a symbolic link to oldname.
	Symlink(oldname string, newname string) error
	// DiskUsage determines Disk usage
	DiskUsage(name string) (DiskUsage, error)
	// GetFileSize gets file size
	GetFileSize(filename string) (int64, error)
	// SubDirectories returns a list of all subdirectories names. Any "hidden" directory (i.e. starting with `.`) is ignored.
	SubDirectories(directory string) ([]string, error)
	// SubDirectoriesWithContext returns a list of all subdirectories which are not hidden
	SubDirectoriesWithContext(ctx context.Context, directory string) ([]string, error)
	// SubDirectoriesWithContextAndExclusionPatterns returns a list of all subdirectories but ignores any file matching the exclusion pattern.
	// Note: all folders are returned whether they are hidden or not unless matching an exclusion pattern.
	SubDirectoriesWithContextAndExclusionPatterns(ctx context.Context, directory string, exclusionPatterns ...string) ([]string, error)
	// Touch is a command used to update the access date and/or modification date of a computer file or directory (equivalent to posix touch).
	Touch(path string) error
	// ListDirTree lists the content of directory recursively
	ListDirTree(dirPath string, list *[]string) error
	// ListDirTreeWithContext lists the content of directory recursively
	ListDirTreeWithContext(ctx context.Context, dirPath string, list *[]string) error
	// ListDirTreeWithContextAndExclusionPatterns lists the content of directory recursively but ignores any file matching the exclusion pattern.
	ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, dirPath string, list *[]string, exclusionPatterns ...string) error
	// ConvertFilePath gets FS file path instead of real file path. In most cases, returned file path
	// should be identical however this may not be true for some particular file systems e.g. for base FS, file path
	// returned will have any base prefix removed.
	ConvertFilePath(name string) string
	// ConvertToRelativePath converts a list of paths to relative paths
	ConvertToRelativePath(rootPath string, paths ...string) ([]string, error)
	// ConvertToAbsolutePath converts a list of paths to relative paths
	ConvertToAbsolutePath(rootPath string, paths ...string) ([]string, error)
	// NewRemoteLockFile creates a lock file on a remote location (NFS)
	NewRemoteLockFile(id string, dirToLock string) ILock
	// Zip compresses a file tree (source) into a zip file (destination)
	Zip(source string, destination string) error
	// ZipWithContext compresses a file tree (source) into a zip file (destination)
	ZipWithContext(ctx context.Context, source string, destination string) error
	// ZipWithContextAndLimits compresses a file tree (source) into a zip file (destination) .Nonetheless, if FileSystemLimits are exceeded, an error will be returned and the process will be stopped.
	// It is however the responsibility of the caller to clean any partially created zipped archive if error occurs.
	ZipWithContextAndLimits(ctx context.Context, source string, destination string, limits ILimits) error
	// ZipWithContextAndLimitsAndExclusionPatterns compresses a file tree (source) into a zip file (destination) but ignores any file/folder matching an exclusion pattern.
	ZipWithContextAndLimitsAndExclusionPatterns(ctx context.Context, source string, destination string, limits ILimits, exclusionPatterns ...string) error
	// Unzip decompresses a source zip archive into the destination
	Unzip(source string, destination string) ([]string, error)
	// UnzipWithContext decompresses a source zip archive into the destination
	UnzipWithContext(ctx context.Context, source string, destination string) ([]string, error)
	// UnzipWithContextAndLimits decompresses a source zip archive into the destination. Nonetheless, if FileSystemLimits are exceeded, an error will be returned and the process will be stopped.
	// It is however the responsibility of the caller to clean any partially unzipped archive if error occurs.
	UnzipWithContextAndLimits(ctx context.Context, source string, destination string, limits ILimits) (fileList []string, err error)
	// FileHash calculates file hash
	FileHash(hashAlgo string, path string) (string, error)
	// FileHashWithContext calculates file hash
	FileHashWithContext(ctx context.Context, hashAlgo string, path string) (string, error)
	// IsZip states whether a file is a zip file or not. If the file does not exist, it will state whether the filename has a zip extension or not.
	IsZip(filepath string) bool
	// IsZipWithContext states whether a file is a zip file or not. Since the process can take some time (i.e type detection with sniffers such as http.DetectContentType), it is controlled by a context.
	IsZipWithContext(ctx context.Context, filepath string) (bool, error)
}

FS defines all the methods a file system should provide. Note: When an API accepting exclusion patterns, it means its processing will not be applied on path matching an exclusion pattern An exclusion pattern correspond to a regex string following the syntax defined in the regexp(https://pkg.go.dev/regexp) module.

func ConvertFromIOFilesystem added in v1.39.0

func ConvertFromIOFilesystem(filesystem fs.FS) (FS, error)

ConvertFromIOFilesystem converts an io/fs FS into a FS

func GetGlobalFileSystem

func GetGlobalFileSystem() FS

func NewEmbedFileSystem added in v1.38.0

func NewEmbedFileSystem(fs *embed.FS) (FS, error)

func NewFs

func NewFs(fsType FilesystemType) FS

func NewInMemoryFileSystem

func NewInMemoryFileSystem() FS

func NewStandardFileSystem

func NewStandardFileSystem() FS

func NewVirtualFileSystem

func NewVirtualFileSystem(vfs afero.Fs, fsType FilesystemType, pathConverter func(path string) string) FS

NewVirtualFileSystem returns a virtual filesystem similarly to NewCloseableVirtualFileSystem

type File

type File interface {
	afero.File
	Fd() uintptr
}

func CreateFile

func CreateFile(name string) (File, error)

func GenericOpen

func GenericOpen(name string) (File, error)

func OpenFile added in v1.5.0

func OpenFile(name string, flag int, perm os.FileMode) (File, error)

func TempFile

func TempFile(dir string, pattern string) (f File, err error)

func TempFileInTempDir

func TempFileInTempDir(pattern string) (f File, err error)

type FileTimeInfo

type FileTimeInfo interface {
	ModTime() time.Time
	AccessTime() time.Time
	ChangeTime() time.Time
	BirthTime() time.Time
	HasChangeTime() bool
	HasBirthTime() bool
	HasAccessTime() bool
}

func DetermineFileTimes

func DetermineFileTimes(info os.FileInfo) (times FileTimeInfo, err error)

type FilesystemType added in v1.18.0

type FilesystemType int
const (
	StandardFS FilesystemType = iota
	InMemoryFS
	Embed
	Custom
	ZipFS
)

func GetType

func GetType() FilesystemType

type IChowner added in v1.54.0

type IChowner interface {
	// ChownIfPossible will change the file ownership
	ChownIfPossible(name string, uid int, gid int) error
}

IChowner is an Optional interface. It is only implemented by the filesystems saying so.

type ICloseableFS added in v1.42.0

type ICloseableFS interface {
	FS
	io.Closer
}

ICloseableFS is a filesystem which utilises resources which must be closed when it is no longer used, such as open files. The close method is invoked to release resources that the object is holding.

func NewCloseableVirtualFileSystem added in v1.42.0

func NewCloseableVirtualFileSystem(vfs afero.Fs, fsType FilesystemType, resourceInUse io.Closer, resourceInUseDescription string, pathConverter func(path string) string) ICloseableFS

NewCloseableVirtualFileSystem returns a virtual filesystem which requires closing after use. It is a wrapper over afero.FS virtual filesystem and tends to define common filesystem utilities as the ones available in posix.

type IFileHash

type IFileHash interface {
	Calculate(f File) (string, error)
	CalculateWithContext(ctx context.Context, f File) (string, error)
	CalculateFile(fs FS, path string) (string, error)
	CalculateFileWithContext(ctx context.Context, fs FS, path string) (string, error)
	GetType() string
}

IFileHash defines a file hash. For reference. https://stackoverflow.com/questions/1761607/what-is-the-fastest-hash-algorithm-to-check-if-two-files-are-equal

func NewFileHash

func NewFileHash(hashType string) (IFileHash, error)

type IForceRemover added in v1.50.0

type IForceRemover interface {
	// ForceRemoveIfPossible will remove an item with escalated permissions if need be (equivalent to sudo rm -rf)
	ForceRemoveIfPossible(name string) error
}

IForceRemover is an Optional interface. It is only implemented by the filesystems saying so.

type ILimits added in v1.15.0

type ILimits interface {
	config.IServiceConfiguration
	// Apply states whether the limit should be applied
	Apply() bool
	// GetMaxFileSize returns the maximum size in byte a file can have on a file system
	GetMaxFileSize() int64
	// GetMaxTotalSize returns the maximum size in byte a location can have on a file system (whether it is a file or a folder)
	GetMaxTotalSize() uint64
	// GetMaxFileCount returns the maximum files in byte a file can have on a file system
	GetMaxFileCount() int64
	// GetMaxDepth returns the maximum depth of directory tree allowed (set to a negative number if disabled)
	GetMaxDepth() int64
	// ApplyRecursively specifies whether recursive action should be applied or not e.g. expand zip within zips during unzipping
	ApplyRecursively() bool
}

ILimits defines general FileSystemLimits for actions performed on the filesystem

func DefaultLimits added in v1.15.0

func DefaultLimits() ILimits

DefaultLimits defines default file system limits

func DefaultNonRecursiveZipLimits added in v1.24.0

func DefaultNonRecursiveZipLimits() ILimits

DefaultNonRecursiveZipLimits defines default file system limits for handling zips

func DefaultZipLimits added in v1.24.0

func DefaultZipLimits() ILimits

DefaultZipLimits defines default file system limits for handling zips

func NewLimits added in v1.15.0

func NewLimits(maxFileSize int64, maxTotalSize uint64, maxFileCount int64, maxDepth int64, recursive bool) ILimits

NewLimits defines file system FileSystemLimits.

func NoLimits added in v1.15.0

func NoLimits() ILimits

NoLimits defines no file system FileSystemLimits

func RecursiveZipLimits added in v1.24.0

func RecursiveZipLimits(maxDepth int64) ILimits

RecursiveZipLimits defines file system limits for handling zips recursively

type ILinkReader added in v1.54.0

type ILinkReader interface {
	ReadlinkIfPossible(string) (string, error)
}

ILinkReader is an Optional interface. It is only implemented by the filesystems saying so.

type ILinker added in v1.54.0

type ILinker interface {
	// LinkIfPossible creates a hard link between oldname and new name.
	LinkIfPossible(oldname, newname string) error
}

ILinker is an Optional interface. It is only implemented by the filesystems saying so.

type ILock

type ILock interface {
	// Lock locks the lock. This call will wait (i.e. block) until the lock is available.
	Lock(ctx context.Context) error
	// LockWithTimeout tries to lock the lock until the timeout expires. If the timeout expires, this method will return commonerror.ErrTimeout.
	LockWithTimeout(ctx context.Context, timeout time.Duration) error
	// TryLock attempts to lock the lock instantly. This method will return commonerrors.ErrLocked immediately if the lock cannot be acquired straight away.
	TryLock(ctx context.Context) error
	// IsStale determines whether a lock is stale (the owner forgot to release it or is dead) or not.
	IsStale() bool
	// Unlock releases the lock. This takes precedence over any current lock.
	Unlock(ctx context.Context) error
	// ReleaseIfStale forces the lock to be released if it is considered as stale.
	ReleaseIfStale(ctx context.Context) error
	// MakeStale makes the lock stale. This is mostly for testing purposes.
	MakeStale(ctx context.Context) error
}

ILock defines a generic lock using the file system. FIXME it should be noted that despite being possible to use the lock with an in-memory filesystem, it should be avoided at all cost. The implementation of the in-memory FS used (afero) has shown several thread safety issues (e.g. https://github.com/spf13/afero/issues/298) and therefore, should not be used for scenarios involving concurrency until it is fixed.

func NewGenericRemoteLockFile

func NewGenericRemoteLockFile(fs *VFS, lockID string, dirPath string, overrideStaleLock bool) ILock

NewGenericRemoteLockFile creates a new remote lock using the file system.

func NewRemoteLockFile

func NewRemoteLockFile(fs *VFS, lockID string, dirPath string) ILock

NewRemoteLockFile creates a new remote lock using the file system. lockID Id for the lock. dirPath path where the lock should be applied to.

type IStater added in v1.54.0

type IStater interface {
	// LstatIfPossible returns file information about an item.
	LstatIfPossible(string) (os.FileInfo, bool, error)
}

IStater is an Optional interface. It is only implemented by the filesystems saying so.

type ISymLinker added in v1.54.0

type ISymLinker interface {
	SymlinkIfPossible(string, string) error
}

ISymLinker is an Optional interface. It is only implemented by the filesystems saying so.

type Limits added in v1.15.0

type Limits struct {
	MaxFileSize  int64  `mapstructure:"max_file_size"`
	MaxTotalSize uint64 `mapstructure:"max_total_size"`
	MaxFileCount int64  `mapstructure:"max_file_count"`
	MaxDepth     int64  `mapstructure:"max_depth"`
	Recursive    bool   `mapstructure:"recursive"`
}

Limits defines file system limits

func (*Limits) Apply added in v1.15.0

func (l *Limits) Apply() bool

func (*Limits) ApplyRecursively added in v1.24.0

func (l *Limits) ApplyRecursively() bool

func (*Limits) GetMaxDepth added in v1.24.0

func (l *Limits) GetMaxDepth() int64

func (*Limits) GetMaxFileCount added in v1.19.0

func (l *Limits) GetMaxFileCount() int64

func (*Limits) GetMaxFileSize added in v1.15.0

func (l *Limits) GetMaxFileSize() int64

func (*Limits) GetMaxTotalSize added in v1.15.0

func (l *Limits) GetMaxTotalSize() uint64

func (*Limits) Validate added in v1.15.0

func (l *Limits) Validate() error

type RemoteLockFile

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

RemoteLockFile describes a distributed lock using only the file system. The locking mechanism is performed using directories and the atomic function `mkdir`. A major issue of distributed locks is the presence of stale locks due to many factors such as the loss of the holder of a lock for various reasons. To mitigate this problem, a "heart bit" file is modified regularly by the lock holder in order to specify the holder is still alive and the lock still valid.

func (*RemoteLockFile) IsStale

func (l *RemoteLockFile) IsStale() bool

IsStale checks whether the lock is stale (i.e. no heart beat detected) or not.

func (*RemoteLockFile) Lock

func (l *RemoteLockFile) Lock(ctx context.Context) error

Lock locks the lock. This call will block until the lock is available.

func (*RemoteLockFile) LockWithTimeout

func (l *RemoteLockFile) LockWithTimeout(ctx context.Context, timeout time.Duration) error

LockWithTimeout tries to lock the lock until the timeout expires

func (*RemoteLockFile) MakeStale

func (l *RemoteLockFile) MakeStale(ctx context.Context) error

MakeStale is mostly useful for testing purposes and tries to mock locks going stale.

func (*RemoteLockFile) ReleaseIfStale

func (l *RemoteLockFile) ReleaseIfStale(ctx context.Context) error

func (*RemoteLockFile) TryLock

func (l *RemoteLockFile) TryLock(ctx context.Context) (err error)

TryLock attempts to lock the lock straight away.

func (*RemoteLockFile) Unlock

func (l *RemoteLockFile) Unlock(ctx context.Context) error

Unlock unlocks the lock

type UsageStat

type UsageStat struct {
	Total             uint64
	Free              uint64
	Used              uint64
	UsedPercent       float64
	InodesTotal       uint64
	InodesUsed        uint64
	InodesFree        uint64
	InodesUsedPercent float64
}

func (*UsageStat) GetFree

func (d *UsageStat) GetFree() uint64

func (*UsageStat) GetInodesFree

func (d *UsageStat) GetInodesFree() uint64

func (*UsageStat) GetInodesTotal

func (d *UsageStat) GetInodesTotal() uint64

func (*UsageStat) GetInodesUsed

func (d *UsageStat) GetInodesUsed() uint64

func (*UsageStat) GetInodesUsedPercent

func (d *UsageStat) GetInodesUsedPercent() float64

func (*UsageStat) GetTotal

func (d *UsageStat) GetTotal() uint64

func (*UsageStat) GetUsed

func (d *UsageStat) GetUsed() uint64

func (*UsageStat) GetUsedPercent

func (d *UsageStat) GetUsedPercent() float64

type VFS

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

func (*VFS) ChangeOwnership added in v1.43.0

func (fs *VFS) ChangeOwnership(name string, owner *user.User) error

func (*VFS) ChangeOwnershipRecursively added in v1.54.0

func (fs *VFS) ChangeOwnershipRecursively(ctx context.Context, path string, owner *user.User) (err error)

func (*VFS) Chmod

func (fs *VFS) Chmod(name string, mode os.FileMode) (err error)

func (*VFS) ChmodRecursively added in v1.54.0

func (fs *VFS) ChmodRecursively(ctx context.Context, path string, mode os.FileMode) (err error)

func (*VFS) Chown

func (fs *VFS) Chown(name string, uid, gid int) (err error)

func (*VFS) ChownRecursively added in v1.54.0

func (fs *VFS) ChownRecursively(ctx context.Context, path string, uid, gid int) (err error)

func (*VFS) Chtimes

func (fs *VFS) Chtimes(name string, atime time.Time, mtime time.Time) (err error)

func (*VFS) CleanDir

func (fs *VFS) CleanDir(dir string) error

func (*VFS) CleanDirWithContext added in v1.15.0

func (fs *VFS) CleanDirWithContext(ctx context.Context, dir string) error

func (*VFS) CleanDirWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) CleanDirWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)

func (*VFS) Close added in v1.42.0

func (fs *VFS) Close() error

func (*VFS) ConvertFilePath

func (fs *VFS) ConvertFilePath(name string) string

func (*VFS) ConvertToAbsolutePath

func (fs *VFS) ConvertToAbsolutePath(rootPath string, paths ...string) ([]string, error)

func (*VFS) ConvertToRelativePath

func (fs *VFS) ConvertToRelativePath(rootPath string, paths ...string) ([]string, error)

func (*VFS) Copy

func (fs *VFS) Copy(src string, dest string) (err error)

func (*VFS) CopyToDirectory added in v1.26.0

func (fs *VFS) CopyToDirectory(src, destDirectory string) error

func (*VFS) CopyToDirectoryWithContext added in v1.26.0

func (fs *VFS) CopyToDirectoryWithContext(ctx context.Context, src, destDirectory string) (err error)

func (*VFS) CopyToFile added in v1.26.0

func (fs *VFS) CopyToFile(src string, dest string) error

func (*VFS) CopyToFileWithContext added in v1.26.0

func (fs *VFS) CopyToFileWithContext(ctx context.Context, src string, dest string) (err error)

func (*VFS) CopyWithContext added in v1.15.0

func (fs *VFS) CopyWithContext(ctx context.Context, src string, dest string) error

func (*VFS) CopyWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) CopyWithContextAndExclusionPatterns(ctx context.Context, src string, dest string, exclusionPatterns ...string) error

func (*VFS) CreateFile

func (fs *VFS) CreateFile(name string) (File, error)

func (*VFS) CurrentDirectory

func (fs *VFS) CurrentDirectory() (string, error)

func (*VFS) DiskUsage

func (fs *VFS) DiskUsage(name string) (usage DiskUsage, err error)

func (*VFS) ExcludeAll

func (fs *VFS) ExcludeAll(files []string, exclusionPatterns ...string) ([]string, error)

func (*VFS) Exists

func (fs *VFS) Exists(path string) bool

func (*VFS) FetchFileOwner added in v1.43.0

func (fs *VFS) FetchFileOwner(name string) (owner *user.User, err error)

func (*VFS) FetchOwners added in v1.18.0

func (fs *VFS) FetchOwners(name string) (uid, gid int, err error)

func (*VFS) FileHash

func (fs *VFS) FileHash(hashAlgo string, path string) (string, error)

func (*VFS) FileHashWithContext added in v1.28.0

func (fs *VFS) FileHashWithContext(ctx context.Context, hashAlgo string, path string) (hash string, err error)

func (*VFS) FindAll

func (fs *VFS) FindAll(dir string, extensions ...string) (files []string, err error)

func (*VFS) GarbageCollect

func (fs *VFS) GarbageCollect(root string, durationSinceLastAccess time.Duration) error

func (*VFS) GarbageCollectWithContext added in v1.15.0

func (fs *VFS) GarbageCollectWithContext(ctx context.Context, root string, durationSinceLastAccess time.Duration) error

func (*VFS) GenericOpen

func (fs *VFS) GenericOpen(name string) (File, error)

func (*VFS) GetFileSize

func (fs *VFS) GetFileSize(name string) (size int64, err error)

func (*VFS) GetType

func (fs *VFS) GetType() FilesystemType

func (*VFS) Glob added in v1.54.0

func (fs *VFS) Glob(pattern string) (matches []string, err error)

func (*VFS) IsDir

func (fs *VFS) IsDir(path string) (result bool, err error)

func (*VFS) IsEmpty

func (fs *VFS) IsEmpty(name string) (empty bool, err error)

func (*VFS) IsFile

func (fs *VFS) IsFile(path string) (result bool, err error)
func (fs *VFS) IsLink(path string) (result bool, err error)

func (*VFS) IsZip added in v1.24.0

func (fs *VFS) IsZip(path string) bool

func (*VFS) IsZipWithContext added in v1.24.0

func (fs *VFS) IsZipWithContext(ctx context.Context, path string) (ok bool, err error)
func (fs *VFS) Link(oldname, newname string) (err error)

func (*VFS) ListDirTree

func (fs *VFS) ListDirTree(dirPath string, list *[]string) error

func (*VFS) ListDirTreeWithContext added in v1.15.0

func (fs *VFS) ListDirTreeWithContext(ctx context.Context, dirPath string, list *[]string) error

func (*VFS) ListDirTreeWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, dirPath string, list *[]string, exclusionPatterns ...string) (err error)

func (*VFS) Lls

func (fs *VFS) Lls(dir string) (files []os.FileInfo, err error)

func (*VFS) LlsFromOpenedDirectory

func (fs *VFS) LlsFromOpenedDirectory(dir File) ([]os.FileInfo, error)

func (*VFS) Ls

func (fs *VFS) Ls(dir string) (names []string, err error)

func (*VFS) LsFromOpenedDirectory

func (fs *VFS) LsFromOpenedDirectory(dir File) ([]string, error)

func (*VFS) LsWithExclusionPatterns added in v1.20.0

func (fs *VFS) LsWithExclusionPatterns(dir string, exclusionPatterns ...string) (names []string, err error)

func (*VFS) Lstat

func (fs *VFS) Lstat(name string) (fileInfo os.FileInfo, err error)

func (*VFS) MkDir

func (fs *VFS) MkDir(dir string) (err error)

func (*VFS) MkDirAll

func (fs *VFS) MkDirAll(dir string, perm os.FileMode) (err error)

func (*VFS) Move

func (fs *VFS) Move(src string, dest string) error

func (*VFS) MoveWithContext added in v1.15.0

func (fs *VFS) MoveWithContext(ctx context.Context, src string, dest string) (err error)

func (*VFS) NewRemoteLockFile

func (fs *VFS) NewRemoteLockFile(id string, dirToLock string) ILock

func (*VFS) Open

func (fs *VFS) Open(name string) (doublestar.File, error)

func (*VFS) OpenFile

func (fs *VFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)

func (*VFS) PathSeparator

func (fs *VFS) PathSeparator() rune

func (*VFS) ReadFile

func (fs *VFS) ReadFile(filename string) (content []byte, err error)

func (*VFS) ReadFileContent added in v1.38.0

func (fs *VFS) ReadFileContent(ctx context.Context, file File, limits ILimits) (content []byte, err error)

func (*VFS) ReadFileWithContext added in v1.24.0

func (fs *VFS) ReadFileWithContext(ctx context.Context, filename string) ([]byte, error)

func (*VFS) ReadFileWithContextAndLimits added in v1.24.0

func (fs *VFS) ReadFileWithContextAndLimits(ctx context.Context, filename string, limits ILimits) ([]byte, error)

func (*VFS) ReadFileWithLimits added in v1.15.0

func (fs *VFS) ReadFileWithLimits(filename string, limits ILimits) ([]byte, error)
func (fs *VFS) Readlink(name string) (value string, err error)

func (*VFS) RemoveWithContext added in v1.15.0

func (fs *VFS) RemoveWithContext(ctx context.Context, dir string) error

func (*VFS) RemoveWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) RemoveWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)

func (*VFS) RemoveWithPrivileges added in v1.50.0

func (fs *VFS) RemoveWithPrivileges(ctx context.Context, dir string) (err error)

func (*VFS) Rm

func (fs *VFS) Rm(dir string) error

func (*VFS) Stat

func (fs *VFS) Stat(name string) (os.FileInfo, error)

func (*VFS) StatTimes

func (fs *VFS) StatTimes(name string) (info FileTimeInfo, err error)

func (*VFS) SubDirectories

func (fs *VFS) SubDirectories(directory string) ([]string, error)

func (*VFS) SubDirectoriesWithContext added in v1.15.0

func (fs *VFS) SubDirectoriesWithContext(ctx context.Context, directory string) ([]string, error)

func (*VFS) SubDirectoriesWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) SubDirectoriesWithContextAndExclusionPatterns(ctx context.Context, directory string, exclusionPatterns ...string) (directories []string, err error)
func (fs *VFS) Symlink(oldname string, newname string) (err error)

func (*VFS) TempDir

func (fs *VFS) TempDir(dir string, prefix string) (name string, err error)

func (*VFS) TempDirInTempDir

func (fs *VFS) TempDirInTempDir(prefix string) (name string, err error)

func (*VFS) TempDirectory

func (fs *VFS) TempDirectory() string

func (*VFS) TempFile

func (fs *VFS) TempFile(dir string, prefix string) (f File, err error)

func (*VFS) TempFileInTempDir

func (fs *VFS) TempFileInTempDir(prefix string) (f File, err error)

func (*VFS) Touch added in v1.54.0

func (fs *VFS) Touch(path string) (err error)

func (*VFS) TouchTempFile added in v1.54.0

func (fs *VFS) TouchTempFile(dir string, prefix string) (filename string, err error)

func (*VFS) TouchTempFileInTempDir added in v1.54.0

func (fs *VFS) TouchTempFileInTempDir(prefix string) (filename string, err error)

func (*VFS) Unzip

func (fs *VFS) Unzip(source, destination string) ([]string, error)

func (*VFS) UnzipWithContext added in v1.15.0

func (fs *VFS) UnzipWithContext(ctx context.Context, source string, destination string) (fileList []string, err error)

func (*VFS) UnzipWithContextAndLimits added in v1.15.0

func (fs *VFS) UnzipWithContextAndLimits(ctx context.Context, source string, destination string, limits ILimits) (fileList []string, err error)

func (*VFS) Walk

func (fs *VFS) Walk(root string, fn filepath.WalkFunc) error

Walk walks https://golang.org/pkg/path/filepath/#WalkDir

func (*VFS) WalkWithContext added in v1.15.0

func (fs *VFS) WalkWithContext(ctx context.Context, root string, fn filepath.WalkFunc) error

func (*VFS) WalkWithContextAndExclusionPatterns added in v1.20.0

func (fs *VFS) WalkWithContextAndExclusionPatterns(ctx context.Context, root string, fn filepath.WalkFunc, exclusionPatterns ...string) (err error)

func (*VFS) WriteFile

func (fs *VFS) WriteFile(filename string, data []byte, perm os.FileMode) error

func (*VFS) WriteFileWithContext added in v1.24.0

func (fs *VFS) WriteFileWithContext(ctx context.Context, filename string, data []byte, perm os.FileMode) (err error)

func (*VFS) WriteToFile added in v1.24.0

func (fs *VFS) WriteToFile(ctx context.Context, filename string, reader io.Reader, perm os.FileMode) (written int64, err error)

func (*VFS) Zip

func (fs *VFS) Zip(source, destination string) error

func (*VFS) ZipWithContext added in v1.15.0

func (fs *VFS) ZipWithContext(ctx context.Context, source, destination string) (err error)

func (*VFS) ZipWithContextAndLimits added in v1.15.0

func (fs *VFS) ZipWithContextAndLimits(ctx context.Context, source, destination string, limits ILimits) error

func (*VFS) ZipWithContextAndLimitsAndExclusionPatterns added in v1.20.0

func (fs *VFS) ZipWithContextAndLimitsAndExclusionPatterns(ctx context.Context, source string, destination string, limits ILimits, exclusionPatterns ...string) (err error)

Jump to

Keyboard shortcuts

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