fsys

package
v0.0.0-...-d2438c5 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fsys offers utilities to create and maintain a filesystem.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotFound

func ErrNotFound(err error) bool

ErrNotFound tests to see if the error passed is a not found error or not.

func NotFound

func NotFound(err error) error

NotFound creates a new not found error

Types

type Config

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

Config encapsulates the requirements for generating a FileSystem

func Build

func Build(opts ...Option) (*Config, error)

Build ingests configuration options to then yield a Config and return an error if it fails during setup.

type File

type File interface {
	io.Reader
	io.Writer
	io.Closer

	// Name returns the name of the file
	Name() string

	// Size returns the size of the file
	Size() int64

	// Sync attempts to sync the file with the underlying storage or errors if it
	// can't not succeed.
	Sync() error
}

File is an abstraction for reading, writing and also closing a file. These interfaces already exist, it's just a matter of composing them to be more usable by other components.

type FileSystem

type FileSystem interface {
	// Create takes a path, creates the file and then returns a File back that
	// can be used. This returns an error if the file can not be created in
	// some way.
	Create(string) (File, error)

	// Open takes a path, opens a potential file and then returns a File if
	// that file exists, otherwise it returns an error if the file wasn't found.
	Open(string) (File, error)

	// OpenFile takes a path, opens a potential file and then returns a File if
	// that file exists, otherwise it returns an error if the file wasn't found.
	OpenFile(path string, flag int, perm os.FileMode) (File, error)

	// Rename takes a current destination path and a new destination path and will
	// rename the a File if it exists, otherwise it returns an error if the file
	// wasn't found.
	Rename(string, string) error

	// Exists takes a path and checks to see if the potential file exists or
	// not.
	// Note: If there is an error trying to read that file, it will return false
	// even if the file already exists.
	Exists(string) bool

	// Remove takes a path, removes a potential file, if no file doesn't exist it
	// will return not found.
	Remove(string) error

	// RemoveAll takes a path, removes all potential files and directories, if
	// no file or directory doesn't exist it will return not found.
	RemoveAll(string) error

	// Mkdir takes a path and generates a directory structure from that path,
	// with the given file mode and if there is a failure it will return an error.
	Mkdir(string, os.FileMode) error

	// MkdirAll takes a path and generates a directory structure from that path,
	// if there is a failure it will return an error.
	MkdirAll(string, os.FileMode) error

	// Chtimes updates the modifier times for a given path or returns an error
	// upon failure
	Chtimes(string, time.Time, time.Time) error

	// Walk over a specific directory and will return an error if there was an
	// error whilst walking.
	Walk(string, filepath.WalkFunc) error

	// Lock attempts to create a locking file for a given path.
	Lock(string) (Releaser, bool, error)

	// CopyFile copies a directory recursively, overwriting the target if it
	// exists.
	CopyFile(string, string) error

	// CopyDir copies a directory recursively, overwriting the target if it
	// exists.
	CopyDir(string, string) error

	// Symlink creates newname as a symbolic link to oldname.
	// If there is an error, it will be of type *LinkError.
	Symlink(string, string) error
}

FileSystem is an abstraction over the native filesystem

func New

func New(config *Config) (fsys FileSystem, err error)

New creates a filesystem from a configuration or returns error if on failure.

type LocalFileSystem

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

LocalFileSystem represents a local disk filesystem

func NewLocalFileSystem

func NewLocalFileSystem(mmap bool) LocalFileSystem

NewLocalFileSystem yields a local disk filesystem.

func (LocalFileSystem) Chtimes

func (LocalFileSystem) Chtimes(path string, atime, mtime time.Time) error

Chtimes updates the modifier times for a given path or returns an error upon failure

func (LocalFileSystem) CopyDir

func (fs LocalFileSystem) CopyDir(source, dest string) error

CopyDir copies a directory recursively, overwriting the target if it exists.

func (LocalFileSystem) CopyFile

func (fs LocalFileSystem) CopyFile(source, dest string) error

CopyFile copies a directory recursively, overwriting the target if it exists.

func (LocalFileSystem) Create

func (LocalFileSystem) Create(path string) (File, error)

Create takes a path, creates the file and then returns a File back that can be used. This returns an error if the file can not be created in some way.

func (LocalFileSystem) Exists

func (LocalFileSystem) Exists(path string) bool

Exists takes a path and checks to see if the potential file exists or not. Note: If there is an error trying to read that file, it will return false even if the file already exists.

func (LocalFileSystem) Lock

func (LocalFileSystem) Lock(path string) (r Releaser, existed bool, err error)

Lock attempts to create a locking file for a given path.

func (LocalFileSystem) Mkdir

func (LocalFileSystem) Mkdir(path string, mode os.FileMode) error

Mkdir takes a path and generates a directory structure from that path, with the given file mode and if there is a failure it will return an error.

func (LocalFileSystem) MkdirAll

func (LocalFileSystem) MkdirAll(path string, mode os.FileMode) error

MkdirAll takes a path and generates a directory structure from that path, if there is a failure it will return an error.

func (LocalFileSystem) Open

func (fs LocalFileSystem) Open(path string) (File, error)

Open takes a path, opens a potential file and then returns a File if that file exists, otherwise it returns an error if the file wasn't found.

func (LocalFileSystem) OpenFile

func (fs LocalFileSystem) OpenFile(path string, flag int, perm os.FileMode) (File, error)

OpenFile takes a path, opens a potential file and then returns a File if that file exists, otherwise it returns an error if the file wasn't found.

func (LocalFileSystem) Remove

func (LocalFileSystem) Remove(path string) error

Remove takes a path, removes a potential file, if no file doesn't exist it will return not found.

func (LocalFileSystem) RemoveAll

func (LocalFileSystem) RemoveAll(path string) error

RemoveAll takes a path, removes all potential files and directories, if no file or directory doesn't exist it will return not found.

func (LocalFileSystem) Rename

func (LocalFileSystem) Rename(oldname, newname string) error

Rename takes a current destination path and a new destination path and will rename the a File if it exists, otherwise it returns an error if the file wasn't found.

func (LocalFileSystem) Symlink(oldname, newname string) error

Symlink creates newname as a symbolic link to oldname. If there is an error, it will be of type *LinkError.

func (LocalFileSystem) Walk

func (LocalFileSystem) Walk(root string, walkFn filepath.WalkFunc) error

Walk over a specific directory and will return an error if there was an error whilst walking.

type Option

type Option func(*Config) error

Option defines a option for generating a filesystem Config

func With

func With(name string) Option

With adds a type of filesystem to use for the configuration.

func WithMMAP

func WithMMAP(mmap bool) Option

WithMMAP defines if we should use mmap or not.

type Releaser

type Releaser interface {

	// Release given lock or returns error upon failure.
	Release() error
}

Releaser is returned by Lock calls.

type VirtualFileSystem

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

VirtualFileSystem represents an in-memory filesystem.

func NewVirtualFileSystem

func NewVirtualFileSystem() *VirtualFileSystem

NewVirtualFileSystem yields an in-memory filesystem.

func (*VirtualFileSystem) Chtimes

func (fs *VirtualFileSystem) Chtimes(path string, atime, mtime time.Time) error

Chtimes updates the modifier times for a given path or returns an error upon failure

func (*VirtualFileSystem) CopyDir

func (fs *VirtualFileSystem) CopyDir(source, dest string) error

CopyDir copies a directory recursively, overwriting the target if it exists.

func (*VirtualFileSystem) CopyFile

func (fs *VirtualFileSystem) CopyFile(source, dest string) error

CopyFile copies a directory recursively, overwriting the target if it exists.

func (*VirtualFileSystem) Create

func (fs *VirtualFileSystem) Create(path string) (File, error)

Create takes a path, creates the file and then returns a File back that can be used. This returns an error if the file can not be created in some way.

func (*VirtualFileSystem) Exists

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

Exists takes a path and checks to see if the potential file exists or not. Note: If there is an error trying to read that file, it will return false even if the file already exists.

func (*VirtualFileSystem) Lock

func (fs *VirtualFileSystem) Lock(path string) (r Releaser, existed bool, err error)

Lock attempts to create a locking file for a given path.

func (*VirtualFileSystem) Mkdir

func (fs *VirtualFileSystem) Mkdir(path string, mode os.FileMode) error

Mkdir takes a path and generates a directory structure from that path, with the given file mode and if there is a failure it will return an error.

func (*VirtualFileSystem) MkdirAll

func (fs *VirtualFileSystem) MkdirAll(path string, mode os.FileMode) error

MkdirAll takes a path and generates a directory structure from that path, if there is a failure it will return an error.

func (*VirtualFileSystem) Open

func (fs *VirtualFileSystem) Open(path string) (File, error)

Open takes a path, opens a potential file and then returns a File if that file exists, otherwise it returns an error if the file wasn't found.

func (*VirtualFileSystem) OpenFile

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

OpenFile takes a path, opens a potential file and then returns a File if that file exists, otherwise it returns an error if the file wasn't found.

func (*VirtualFileSystem) Remove

func (fs *VirtualFileSystem) Remove(path string) error

Remove takes a path, removes a potential file, if no file doesn't exist it will return not found.

func (*VirtualFileSystem) RemoveAll

func (fs *VirtualFileSystem) RemoveAll(path string) error

RemoveAll takes a path, removes a potential file, if no file doesn't exist it will return not found.

func (*VirtualFileSystem) Rename

func (fs *VirtualFileSystem) Rename(oldname, newname string) error

Rename takes a current destination path and a new destination path and will rename the a File if it exists, otherwise it returns an error if the file wasn't found.

func (fs *VirtualFileSystem) Symlink(oldname, newname string) error

Symlink creates newname as a symbolic link to oldname. If there is an error, it will be of type *LinkError.

func (*VirtualFileSystem) Walk

func (fs *VirtualFileSystem) Walk(root string, walkFn filepath.WalkFunc) error

Walk over a specific directory and will return an error if there was an error whilst walking.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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