filesystem

package
v0.0.0-...-430414e Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLocked = filelock.ErrLocked

ErrLocked - the filelock error.

Functions

This section is empty.

Types

type Archiver

type Archiver interface {
	Unarchive(source string, destination string) error
}

Archiver defines what this package has available.

type FileSystem

type FileSystem interface {
	AppendIfMissing(name string, content []byte, mode os.FileMode) error
	Chmod(name string, mode os.FileMode) error
	CopyDir(src string, dst string) error
	CopyFile(src string, dst string) error
	Chtimes(name string, atime time.Time, mtime time.Time) error
	Create(name string) (afero.File, error)
	DownloadRemoteFile(url string, name string) error
	Exists(path string) (bool, error)
	FileContainsBytes(filename string, subslice []byte) (bool, error)
	MkdirAll(path string, perm os.FileMode) error
	ReadFile(filename string) ([]byte, error)
	Rename(oldname string, newname string) error
	Remove(name string) error
	RemoveAll(path string) error
	Stat(path string) (os.FileInfo, error)
	WriteFile(filename string, data []byte, perm os.FileMode) error
}

FileSystem is an interface that wraps a subset of afero calls but also adds a few of our own.

type Fs

type Fs struct {
	AferoFs afero.Fs
}

Fs is a wrapper around the real afero.Fs we want.

func NewMemFs

func NewMemFs() *Fs

NewMemFs maps memory to the Afero Fs.

func NewOsFs

func NewOsFs() *Fs

NewOsFs creates a new Afero Fs.

func (*Fs) AppendIfMissing

func (f *Fs) AppendIfMissing(filePath string, content []byte, mode os.FileMode) error

AppendIfMissing appends the content string to the given file.

func (*Fs) Chmod

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

Chmod modifies the file permissions.

func (*Fs) Chtimes

func (f *Fs) Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file.

func (*Fs) CopyDir

func (f *Fs) CopyDir(src string, dst string) error

CopyDir copies the contents of the given directory to another directory on the same filesystem.

func (*Fs) CopyFile

func (f *Fs) CopyFile(src string, dst string) error

CopyFile copies the specified file to the the given destination.

func (*Fs) Create

func (f *Fs) Create(name string) (afero.File, error)

Create creates a file.

func (*Fs) DownloadRemoteFile

func (f *Fs) DownloadRemoteFile(url string, name string) error

DownloadRemoteFile downloads file from the internet onto disk.

func (*Fs) Exists

func (f *Fs) Exists(path string) (bool, error)

Exists returns whether or not the file exists.

func (*Fs) FileContainsBytes

func (f *Fs) FileContainsBytes(filename string, subslice []byte) (bool, error)

FileContainsBytes returns whether or not the given file contains the subslice, otherwise an error.

func (*Fs) MkdirAll

func (f *Fs) MkdirAll(path string, perm os.FileMode) error

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

func (*Fs) ReadFile

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

ReadFile returns the contents of the file as a slice, otherwise error.

func (*Fs) Remove

func (f *Fs) Remove(name string) error

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

func (*Fs) RemoveAll

func (f *Fs) RemoveAll(path string) error

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

func (*Fs) Rename

func (f *Fs) Rename(oldname string, newname string) error

Rename returns an error if there was an issue renaming the given path.

func (*Fs) Stat

func (f *Fs) Stat(path string) (os.FileInfo, error)

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

func (*Fs) WriteFile

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

WriteFile writes the byte slice to the givn file.

type Locker

type Locker interface {
	GetLock(filename string) (filelock.TryLockerSafe, error)
	GetRetryAttempts() uint
	GetRetryDelay() time.Duration
	GetRetryDelayType() retry.DelayTypeFunc
}

Locker is an interface of filelock.

type MemLock

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

MemLock - definition of the memory lock.

func (*MemLock) Destroy

func (f *MemLock) Destroy() error

Destroy - destroy the lock.

func (*MemLock) Lock

func (f *MemLock) Lock() error

Lock - lock the fs.

func (*MemLock) Must

func (f *MemLock) Must() filelock.TryLocker

Must - nil.

func (*MemLock) String

func (f *MemLock) String() string

func (*MemLock) TryLock

func (f *MemLock) TryLock() (bool, error)

TryLock - attempt to get the lock.

func (*MemLock) Unlock

func (f *MemLock) Unlock() error

Unlock - unlock the fs.

type MemMapLock

type MemMapLock struct {
	RetryAttempts  uint
	RetryDelay     time.Duration
	RetryDelayType retry.DelayTypeFunc

	Locks map[string]*MemLock

	// The error you want GetLock() to throw
	Err error

	// The error you want TryLock() to throw
	LockErr error
}

MemMapLock - This is a super simple implementation and could probably be done with something better than a map, but heh its mostly for testing.

func (*MemMapLock) GetLock

func (o *MemMapLock) GetLock(filename string) (filelock.TryLockerSafe, error)

GetLock - create a new lock.

func (*MemMapLock) GetRetryAttempts

func (o *MemMapLock) GetRetryAttempts() uint

GetRetryAttempts - get retry count.

func (*MemMapLock) GetRetryDelay

func (o *MemMapLock) GetRetryDelay() time.Duration

GetRetryDelay - time between each retry.

func (*MemMapLock) GetRetryDelayType

func (o *MemMapLock) GetRetryDelayType() retry.DelayTypeFunc

GetRetryDelayType - type of retry delay.

type OsLock

type OsLock struct {
	RetryAttempts  uint
	RetryDelay     time.Duration
	RetryDelayType retry.DelayTypeFunc
}

OsLock defines what is available for retries.

func (*OsLock) GetLock

func (o *OsLock) GetLock(filename string) (filelock.TryLockerSafe, error)

GetLock creates a new filelock.

func (*OsLock) GetRetryAttempts

func (o *OsLock) GetRetryAttempts() uint

GetRetryAttempts returns the max number of retries allowed.

func (*OsLock) GetRetryDelay

func (o *OsLock) GetRetryDelay() time.Duration

GetRetryDelay returns the timed allowed between retries.

func (*OsLock) GetRetryDelayType

func (o *OsLock) GetRetryDelayType() retry.DelayTypeFunc

GetRetryDelayType returns the type of retry delay.

type Unarchiver

type Unarchiver struct{}

Unarchiver has access to the methods of this package.

func (*Unarchiver) Unarchive

func (a *Unarchiver) Unarchive(source string, destination string) error

Unarchive - unarchive the source.

Jump to

Keyboard shortcuts

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