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
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
Copyright (C) 2020-2022 Arm Limited or its affiliates and Contributors. All rights reserved.
SPDX-License-Identifier: Apache-2.0
Distributed lock using lock files https://fileinfo.com/extension/lock
Index ¶
- Constants
- Variables
- func CleanDir(dir string) (err error)
- func ConvertFileSytemError(err error) error
- func Copy(src string, dest string) (err error)
- func CopyBetweenFS(ctx context.Context, srcFs FS, src string, destFs FS, dest string) (err error)
- func CopyBetweenFSWithExclusionPatterns(ctx context.Context, srcFs FS, src string, destFs FS, dest string, ...) (err error)
- func CopyBetweenFSWithExclusionRegexes(ctx context.Context, srcFs FS, src string, destFs FS, dest string, ...) (err error)
- func CurrentDirectory() (string, error)
- func ExcludeAll(files []string, exclusionPatterns ...string) ([]string, error)
- func ExcludeFiles(files []string, regexes []*regexp.Regexp) (cleansedList []string, err error)
- func Exists(path string) bool
- func FilepathStem(fp string) string
- func FindAll(dir string, extensions ...string) (files []string, err error)
- func GetFileSize(name string) (size int64, err error)
- func IdentityPathConverterFunc(path string) string
- func IsDir(path string) (result bool, err error)
- func IsDirectory(fi os.FileInfo) bool
- func IsEmpty(name string) (empty bool, err error)
- func IsFile(path string) (result bool, err error)
- func IsFileHandleUnset(fh uintptr) bool
- func IsPathExcluded(path string, exclusionPatterns ...*regexp.Regexp) bool
- func IsPathExcludedFromPatterns(path string, pathSeparator rune, exclusionPatterns ...string) bool
- func IsPathNotExist(err error) bool
- func IsRegularFile(fi os.FileInfo) bool
- func IsSymLink(fi os.FileInfo) bool
- func ListDirTree(dirPath string, list *[]string) error
- func ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, fs FS, dirPath string, list *[]string, ...) (err error)
- func Ls(dir string) (files []string, err error)
- func LsWithExclusionPatterns(fs FS, dir string, regexes []*regexp.Regexp) (names []string, err error)
- func Lstat(name string) (fileInfo os.FileInfo, err error)
- func MkDir(dir string) (err error)
- func Move(src string, dest string) error
- func MoveBetweenFS(ctx context.Context, srcFs FS, src string, destFs FS, dest string) (err error)
- func NewExclusionRegexList(pathSeparator rune, exclusionPatterns ...string) ([]*regexp.Regexp, error)
- func NewExtendedOsFs() afero.Fs
- func PathSeparator() rune
- func ReadFile(name string) ([]byte, error)
- func ReadFileWithLimits(filename string, limits ILimits) ([]byte, error)
- func Rm(dir string) (err error)
- func Stat(name string) (os.FileInfo, error)
- func SubDirectories(directory string) ([]string, error)
- func TempDir(dir string, prefix string) (name string, err error)
- func TempDirInTempDir(prefix string) (name string, err error)
- func TempDirectory() string
- func Unzip(source, destination string) ([]string, error)
- func Zip(source string, destination string) error
- type Chowner
- type DiskUsage
- type ExtendedOsFs
- type FS
- type File
- type FileTimeInfo
- type FilesystemType
- type IFileHash
- type ILimits
- type ILock
- type Limits
- type Linker
- type RemoteLockFile
- func (l *RemoteLockFile) IsStale() bool
- func (l *RemoteLockFile) Lock(ctx context.Context) error
- func (l *RemoteLockFile) LockWithTimeout(ctx context.Context, timeout time.Duration) error
- func (l *RemoteLockFile) MakeStale(ctx context.Context) error
- func (l *RemoteLockFile) ReleaseIfStale(ctx context.Context) error
- func (l *RemoteLockFile) TryLock(ctx context.Context) (err error)
- func (l *RemoteLockFile) Unlock(ctx context.Context) error
- type UsageStat
- func (d *UsageStat) GetFree() uint64
- func (d *UsageStat) GetInodesFree() uint64
- func (d *UsageStat) GetInodesTotal() uint64
- func (d *UsageStat) GetInodesUsed() uint64
- func (d *UsageStat) GetInodesUsedPercent() float64
- func (d *UsageStat) GetTotal() uint64
- func (d *UsageStat) GetUsed() uint64
- func (d *UsageStat) GetUsedPercent() float64
- type VFS
- func (fs *VFS) Chmod(name string, mode os.FileMode) error
- func (fs *VFS) Chown(name string, uid, gid int) (err error)
- func (fs *VFS) Chtimes(name string, atime time.Time, mtime time.Time) error
- func (fs *VFS) CleanDir(dir string) error
- func (fs *VFS) CleanDirWithContext(ctx context.Context, dir string) error
- func (fs *VFS) CleanDirWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)
- func (fs *VFS) ConvertFilePath(name string) string
- func (fs *VFS) ConvertToAbsolutePath(rootPath string, paths ...string) ([]string, error)
- func (fs *VFS) ConvertToRelativePath(rootPath string, paths ...string) ([]string, error)
- func (fs *VFS) Copy(src string, dest string) (err error)
- func (fs *VFS) CopyWithContext(ctx context.Context, src string, dest string) (err error)
- func (fs *VFS) CopyWithContextAndExclusionPatterns(ctx context.Context, src string, dest string, exclusionPatterns ...string) (err error)
- func (fs *VFS) CreateFile(name string) (File, error)
- func (fs *VFS) CurrentDirectory() (string, error)
- func (fs *VFS) DiskUsage(name string) (usage DiskUsage, err error)
- func (fs *VFS) ExcludeAll(files []string, exclusionPatterns ...string) ([]string, error)
- func (fs *VFS) Exists(path string) bool
- func (fs *VFS) FetchOwners(name string) (uid, gid int, err error)
- func (fs *VFS) FileHash(hashAlgo string, path string) (hash string, err error)
- func (fs *VFS) FindAll(dir string, extensions ...string) (files []string, err error)
- func (fs *VFS) GarbageCollect(root string, durationSinceLastAccess time.Duration) error
- func (fs *VFS) GarbageCollectWithContext(ctx context.Context, root string, durationSinceLastAccess time.Duration) error
- func (fs *VFS) GenericOpen(name string) (File, error)
- func (fs *VFS) GetFileSize(name string) (size int64, err error)
- func (fs *VFS) GetType() FilesystemType
- func (fs *VFS) IsDir(path string) (result bool, err error)
- func (fs *VFS) IsEmpty(name string) (empty bool, err error)
- func (fs *VFS) IsFile(path string) (result bool, err error)
- func (fs *VFS) IsLink(path string) (result bool, err error)
- func (fs *VFS) Link(oldname, newname string) (err error)
- func (fs *VFS) ListDirTree(dirPath string, list *[]string) error
- func (fs *VFS) ListDirTreeWithContext(ctx context.Context, dirPath string, list *[]string) error
- func (fs *VFS) ListDirTreeWithContextAndExclusionPatterns(ctx context.Context, dirPath string, list *[]string, ...) (err error)
- func (fs *VFS) Lls(dir string) (files []os.FileInfo, err error)
- func (fs *VFS) LlsFromOpenedDirectory(dir File) ([]os.FileInfo, error)
- func (fs *VFS) Ls(dir string) (names []string, err error)
- func (fs *VFS) LsFromOpenedDirectory(dir File) ([]string, error)
- func (fs *VFS) LsWithExclusionPatterns(dir string, exclusionPatterns ...string) (names []string, err error)
- func (fs *VFS) Lstat(name string) (fileInfo os.FileInfo, err error)
- func (fs *VFS) MkDir(dir string) (err error)
- func (fs *VFS) MkDirAll(dir string, perm os.FileMode) (err error)
- func (fs *VFS) Move(src string, dest string) error
- func (fs *VFS) MoveWithContext(ctx context.Context, src string, dest string) (err error)
- func (fs *VFS) NewRemoteLockFile(id string, dirToLock string) ILock
- func (fs *VFS) Open(name string) (doublestar.File, error)
- func (fs *VFS) OpenFile(name string, flag int, perm os.FileMode) (File, error)
- func (fs *VFS) PathSeparator() rune
- func (fs *VFS) ReadFile(filename string) (content []byte, err error)
- func (fs *VFS) ReadFileWithLimits(filename string, limits ILimits) ([]byte, error)
- func (fs *VFS) Readlink(name string) (value string, err error)
- func (fs *VFS) RemoveWithContext(ctx context.Context, dir string) error
- func (fs *VFS) RemoveWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...string) (err error)
- func (fs *VFS) Rm(dir string) error
- func (fs *VFS) Stat(name string) (os.FileInfo, error)
- func (fs *VFS) StatTimes(name string) (info FileTimeInfo, err error)
- func (fs *VFS) SubDirectories(directory string) ([]string, error)
- func (fs *VFS) SubDirectoriesWithContext(ctx context.Context, directory string) ([]string, error)
- 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 (fs *VFS) TempDir(dir string, prefix string) (name string, err error)
- func (fs *VFS) TempDirInTempDir(prefix string) (name string, err error)
- func (fs *VFS) TempDirectory() string
- func (fs *VFS) TempFile(dir string, prefix string) (f File, err error)
- func (fs *VFS) TempFileInTempDir(prefix string) (f File, err error)
- func (fs *VFS) Unzip(source, destination string) ([]string, error)
- func (fs *VFS) UnzipWithContext(ctx context.Context, source string, destination string) (fileList []string, err error)
- func (fs *VFS) UnzipWithContextAndLimits(ctx context.Context, source string, destination string, limits ILimits) (fileList []string, err error)
- func (fs *VFS) Walk(root string, fn filepath.WalkFunc) error
- func (fs *VFS) WalkWithContext(ctx context.Context, root string, fn filepath.WalkFunc) error
- func (fs *VFS) WalkWithContextAndExclusionPatterns(ctx context.Context, root string, fn filepath.WalkFunc, ...) (err error)
- func (fs *VFS) WriteFile(filename string, data []byte, perm os.FileMode) (err error)
- func (fs *VFS) Zip(source, destination string) error
- func (fs *VFS) ZipWithContext(ctx context.Context, source, destination string) (err error)
- func (fs *VFS) ZipWithContextAndLimits(ctx context.Context, source, destination string, limits ILimits) error
- func (fs *VFS) ZipWithContextAndLimitsAndExclusionPatterns(ctx context.Context, source string, destination string, limits ILimits, ...) (err error)
Constants ¶
const LockFilePrefix = "lockfile"
const (
UnsetFileHandle = ^uint64(0)
)
Variables ¶
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") )
var (
FileSystemTypes = []FilesystemType{StandardFS, InMemoryFS}
)
Functions ¶
func ConvertFileSytemError ¶
Converts file system error into common errors
func CopyBetweenFS ¶
func CopyBetweenFSWithExclusionPatterns ¶ added in v1.20.0
func CopyBetweenFSWithExclusionRegexes ¶ added in v1.20.0
func CurrentDirectory ¶
func ExcludeAll ¶
ExcludeAll excludes files
func ExcludeFiles ¶ added in v1.20.0
func FilepathStem ¶ added in v1.13.0
FilepathStem returns the final path component, without its suffix.
func GetFileSize ¶
func IsDirectory ¶
func IsFileHandleUnset ¶
func IsPathExcluded ¶ added in v1.20.0
func IsPathExcludedFromPatterns ¶ added in v1.20.0
func IsPathNotExist ¶
func IsRegularFile ¶
func ListDirTree ¶
ListDirTree returns a list of files and directories recursively available under specified path
func ListDirTreeWithContextAndExclusionPatterns ¶ added in v1.20.0
func LsWithExclusionPatterns ¶ added in v1.20.0
func MoveBetweenFS ¶
func NewExclusionRegexList ¶ added in v1.20.0
func NewExtendedOsFs ¶
func PathSeparator ¶
func PathSeparator() rune
func ReadFileWithLimits ¶ added in v1.15.0
func SubDirectories ¶
func TempDirInTempDir ¶
func TempDirectory ¶
func TempDirectory() string
Types ¶
type Chowner ¶
Chowner is an Optional interface. It is only implemented by the filesystems saying so.
type ExtendedOsFs ¶
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) 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 -r) Rm(dir string) (err error) // RemoveWithContext removes directory (equivalent to rm -r) RemoveWithContext(ctx context.Context, dir string) (err error) // RemoveWithContextAndExclusionPatterns removes directory (equivalent to rm -r) unless they match some exclusion pattern. RemoveWithContextAndExclusionPatterns(ctx context.Context, dir string, exclusionPatterns ...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) // 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) // Copy copies files and directory (equivalent to cp -r) Copy(src string, dest string) (err error) // CopyWithContext copies files and directory (equivalent to cp -r) CopyWithContext(ctx context.Context, src string, dest string) (err error) // CopyWithContextAndExclusionPatterns copies files and directory (equivalent to cp -r) 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) // TempFileInTempDir creates a temp file in temp directory. TempFileInTempDir(pattern string) (f File, err error) // TempDirectory returns the temp directory. TempDirectory() string // CurrentDirectory returns current directory. CurrentDirectory() (string, error) // ReadFile reads a file and return its content. ReadFile(filename string) ([]byte, error) // ReadFileWithLimits reads a file and return its content. Nonetheless, it stops with EOF after FileSystemLimits are exceeded. ReadFileWithLimits(filename string, 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 // 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 // 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 // FetchOwners returns the numeric uid and gid of the named file FetchOwners(name string) (uid, gid int, 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) // 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) }
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 GetGlobalFileSystem ¶
func GetGlobalFileSystem() FS
func NewFs ¶
func NewFs(fsType FilesystemType) FS
func NewInMemoryFileSystem ¶
func NewInMemoryFileSystem() FS
func NewStandardFileSystem ¶
func NewStandardFileSystem() FS
func NewVirtualFileSystem ¶
type File ¶
func CreateFile ¶
func GenericOpen ¶
func TempFileInTempDir ¶
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 )
func GetType ¶
func GetType() FilesystemType
type IFileHash ¶
type IFileHash interface { Calculate(f File) (string, error) CalculateFile(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 ¶
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 }
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 FileSystemLimits
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 ¶
NewGenericRemoteLockFile creates a new remote lock using the file system.
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"` }
Limits defines file system limits
func (*Limits) GetMaxFileCount ¶ added in v1.19.0
func (*Limits) GetMaxFileSize ¶ added in v1.15.0
func (*Limits) GetMaxTotalSize ¶ added in v1.15.0
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 ¶
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
type UsageStat ¶
type UsageStat struct { Total uint64 Free uint64 Used uint64 UsedPercent float64 InodesTotal uint64 InodesUsed uint64 InodesFree uint64 InodesUsedPercent float64 }
func (*UsageStat) GetInodesFree ¶
func (*UsageStat) GetInodesTotal ¶
func (*UsageStat) GetInodesUsed ¶
func (*UsageStat) GetInodesUsedPercent ¶
func (*UsageStat) GetUsedPercent ¶
type VFS ¶
type VFS struct {
// contains filtered or unexported fields
}
func (*VFS) CleanDirWithContext ¶ added in v1.15.0
func (*VFS) CleanDirWithContextAndExclusionPatterns ¶ added in v1.20.0
func (*VFS) ConvertFilePath ¶
func (*VFS) ConvertToAbsolutePath ¶
func (*VFS) ConvertToRelativePath ¶
func (*VFS) CopyWithContext ¶ added in v1.15.0
func (*VFS) CopyWithContextAndExclusionPatterns ¶ added in v1.20.0
func (*VFS) CurrentDirectory ¶
func (*VFS) ExcludeAll ¶
func (*VFS) FetchOwners ¶ added in v1.18.0
func (*VFS) GarbageCollect ¶
func (*VFS) GarbageCollectWithContext ¶ added in v1.15.0
func (*VFS) GetType ¶
func (fs *VFS) GetType() FilesystemType