filesystem

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

README

go-filesystem

Wrapper around aferoFS that includes some custom helpers

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLocked = filelock.ErrLocked
)

Functions

This section is empty.

Types

type Archiver

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

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
}

A wrapper around the real afero.Fs we want

func NewMemFs

func NewMemFs() *Fs

func NewOsFs

func NewOsFs() *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 modified 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
}

type MemLock

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

func (*MemLock) Destroy

func (f *MemLock) Destroy() error

func (*MemLock) Lock

func (f *MemLock) Lock() error

func (*MemLock) Must

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

func (*MemLock) String

func (f *MemLock) String() string

func (*MemLock) TryLock

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

func (*MemLock) Unlock

func (f *MemLock) Unlock() error

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
}

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 (f *MemMapLock) GetLock(filename string) (filelock.TryLockerSafe, error)

func (*MemMapLock) GetRetryAttempts

func (o *MemMapLock) GetRetryAttempts() uint

func (*MemMapLock) GetRetryDelay

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

func (*MemMapLock) GetRetryDelayType

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

type OsLock

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

func (*OsLock) GetLock

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

func (*OsLock) GetRetryAttempts

func (o *OsLock) GetRetryAttempts() uint

func (*OsLock) GetRetryDelay

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

func (*OsLock) GetRetryDelayType

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

type Unarchiver

type Unarchiver struct{}

func (*Unarchiver) Unarchive

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

Jump to

Keyboard shortcuts

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