fsext

package
v0.0.0-...-deba56b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2023 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fsext provides extended file system functions

Index

Constants

View Source
const FilePathSeparator = afero.FilePathSeparator

FilePathSeparator is the FilePathSeparator to be used within a file system

Variables

View Source
var ErrPathNeverRequestedBefore = errors.New("path never requested before")

ErrPathNeverRequestedBefore represent an error when path never opened/requested before

Functions

func Abs

func Abs(root, path string) string

Abs returns an absolute representation of path.

this implementation allows k6 to handle absolute paths starting from the current drive on windows like `\users\noname\...`. It makes it easier to test and is needed for archive execution under windows (it always consider '/...' as an absolute path).

If the path is not absolute it will be joined with root to turn it into an absolute path. The root path is assumed to be a directory.

Because k6 does not interact with the OS itself, but with its own virtual file system, it needs to be able to resolve the root path of the file system. In most cases this would be the bundle or init environment's working directory.

func Exists

func Exists(fs Fs, path string) (bool, error)

Exists checks if the provided path exists on the filesystem

func IsDir

func IsDir(fs Fs, path string) (bool, error)

IsDir checks if the provided path is a directory

func JoinFilePath

func JoinFilePath(b, p string) string

JoinFilePath is a wrapper around filepath.Join starting go 1.20 on Windows, Clean (that is using inside the filepath.Join) does not modify the volume name other than to replace occurrences of "/" with `\`. that's why we need to add a leading slash to the path go.1.19: filepath.Join("\\c:", "test") // \c:\test go.1.20: filepath.Join("\\c:", "test") // \c:test

func NewCacheOnReadFs

func NewCacheOnReadFs(base, layer afero.Fs, cacheTime time.Duration) afero.Fs

NewCacheOnReadFs returns a new CacheOnReadFs

func ReadDir

func ReadDir(fs Fs, dirname string) ([]fs.FileInfo, error)

ReadDir reads the info for each file in the provided dirname

func ReadFile

func ReadFile(fs Fs, filename string) ([]byte, error)

ReadFile reads the whole file from the filesystem

func Walk

func Walk(fs afero.Fs, root string, walkFn filepath.WalkFunc) error

Walk implements afero.Walk, but in a way that it doesn't loop to infinity and doesn't have problems if a given path part looks like a windows volume name

func WriteFile

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

WriteFile writes the provided data to the provided fs in the provided filename

Types

type CacheLayerGetter

type CacheLayerGetter interface {
	GetCachingFs() afero.Fs
}

CacheLayerGetter provide a direct access to a cache layer

type CacheOnReadFs

type CacheOnReadFs struct {
	afero.Fs
	// contains filtered or unexported fields
}

CacheOnReadFs is wrapper around afero.CacheOnReadFs with the ability to return the filesystem that is used as cache

func (*CacheOnReadFs) AllowOnlyCached

func (c *CacheOnReadFs) AllowOnlyCached()

AllowOnlyCached enables the cached only mode of the CacheOnReadFs

func (*CacheOnReadFs) GetCachingFs

func (c *CacheOnReadFs) GetCachingFs() afero.Fs

GetCachingFs returns the afero.Fs being used for cache

func (*CacheOnReadFs) Open

func (c *CacheOnReadFs) Open(name string) (afero.File, error)

Open opens file and track the history of opened files if CacheOnReadFs is in the opened only mode it should return an error if file wasn't open before

func (*CacheOnReadFs) Stat

func (c *CacheOnReadFs) Stat(path string) (fs.FileInfo, error)

Stat returns a FileInfo describing the named file, or an error, if any happens. if CacheOnReadFs is in the opened only mode it should return an error if path wasn't open before

type ChangePathFile

type ChangePathFile struct {
	afero.File
	// contains filtered or unexported fields
}

ChangePathFile is a file from ChangePathFs

func (*ChangePathFile) Name

func (f *ChangePathFile) Name() string

Name Returns the name of the file

type ChangePathFs

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

ChangePathFs is a filesystem that wraps another afero.Fs and changes all given paths from all file and directory names, with a function, before calling the same method on the wrapped afero.Fs. Heavily based on afero.BasePathFs

func NewChangePathFs

func NewChangePathFs(source afero.Fs, fn ChangePathFunc) *ChangePathFs

NewChangePathFs return a ChangePathFs where all paths will be change with the provided funcs

func NewTrimFilePathSeparatorFs

func NewTrimFilePathSeparatorFs(source afero.Fs) *ChangePathFs

NewTrimFilePathSeparatorFs is ChangePathFs that trims a Afero.FilePathSeparator from all paths Heavily based on afero.BasePathFs

func (*ChangePathFs) Chmod

func (b *ChangePathFs) Chmod(name string, mode fs.FileMode) (err error)

Chmod changes the mode of the named file to mode.

func (*ChangePathFs) Chown

func (b *ChangePathFs) Chown(name string, uid, gid int) error

Chown changes the uid and gid of the named file.

func (*ChangePathFs) Chtimes

func (b *ChangePathFs) Chtimes(name string, atime, mtime time.Time) (err error)

Chtimes changes the access and modification times of the named file

func (*ChangePathFs) Create

func (b *ChangePathFs) Create(name string) (f afero.File, err error)

Create creates a file in the filesystem, returning the file and an error, if any happens

func (*ChangePathFs) LstatIfPossible

func (b *ChangePathFs) LstatIfPossible(name string) (fs.FileInfo, bool, error)

LstatIfPossible implements the afero.Lstater interface

func (*ChangePathFs) Mkdir

func (b *ChangePathFs) Mkdir(name string, mode fs.FileMode) (err error)

Mkdir creates a directory in the filesystem, return an error if any happens.

func (*ChangePathFs) MkdirAll

func (b *ChangePathFs) MkdirAll(name string, mode fs.FileMode) (err error)

MkdirAll creates a directory path and all parents that does not exist yet.

func (*ChangePathFs) Name

func (b *ChangePathFs) Name() string

Name return the name of this FileSystem

func (*ChangePathFs) Open

func (b *ChangePathFs) Open(name string) (f afero.File, err error)

Open opens a file, returning it or an error, if any happens.

func (*ChangePathFs) OpenFile

func (b *ChangePathFs) OpenFile(name string, flag int, mode fs.FileMode) (f afero.File, err error)

OpenFile opens a file using the given flags and the given mode.

func (*ChangePathFs) Remove

func (b *ChangePathFs) Remove(name string) (err error)

Remove removes a file identified by name, returning an error, if any happens.

func (*ChangePathFs) RemoveAll

func (b *ChangePathFs) RemoveAll(name string) (err error)

RemoveAll removes a directory path and any children it contains. It does not fail if the path does not exist (return nil).

func (*ChangePathFs) Rename

func (b *ChangePathFs) Rename(oldName, newName string) (err error)

Rename renames a file.

func (*ChangePathFs) Stat

func (b *ChangePathFs) Stat(name string) (fi fs.FileInfo, err error)

Stat returns a FileInfo describing the named file, or an error, if any happens.

type ChangePathFunc

type ChangePathFunc func(name string) (path string, err error)

ChangePathFunc is the function that will be called by ChangePathFs to change the path

type Fs

type Fs = afero.Fs

Fs represents a file system

func NewMemMapFs

func NewMemMapFs() Fs

NewMemMapFs returns a Fs that is in memory

func NewOsFs

func NewOsFs() Fs

NewOsFs returns a new wrapps os.Fs

func NewReadOnlyFs

func NewReadOnlyFs(fs Fs) Fs

NewReadOnlyFs returns a Fs wrapping the provided one and returning error on any not read operation.

type OnlyCachedEnabler

type OnlyCachedEnabler interface {
	AllowOnlyCached()
}

OnlyCachedEnabler enables the mode of FS that allows to open already opened files (e.g. serve from cache only)

Jump to

Keyboard shortcuts

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