Documentation
¶
Overview ¶
Package fsys offers utilities to create and maintain a filesystem.
Index ¶
- func ErrNotFound(err error) bool
- func NotFound(err error) error
- type Config
- type File
- type FileSystem
- type LocalFileSystem
- func (LocalFileSystem) Chtimes(path string, atime, mtime time.Time) error
- func (fs LocalFileSystem) CopyDir(source, dest string) error
- func (fs LocalFileSystem) CopyFile(source, dest string) error
- func (LocalFileSystem) Create(path string) (File, error)
- func (LocalFileSystem) Exists(path string) bool
- func (LocalFileSystem) Lock(path string) (r Releaser, existed bool, err error)
- func (LocalFileSystem) Mkdir(path string, mode os.FileMode) error
- func (LocalFileSystem) MkdirAll(path string, mode os.FileMode) error
- func (fs LocalFileSystem) Open(path string) (File, error)
- func (fs LocalFileSystem) OpenFile(path string, flag int, perm os.FileMode) (File, error)
- func (LocalFileSystem) Remove(path string) error
- func (LocalFileSystem) RemoveAll(path string) error
- func (LocalFileSystem) Rename(oldname, newname string) error
- func (LocalFileSystem) Symlink(oldname, newname string) error
- func (LocalFileSystem) Walk(root string, walkFn filepath.WalkFunc) error
- type Option
- type Releaser
- type VirtualFileSystem
- func (fs *VirtualFileSystem) Chtimes(path string, atime, mtime time.Time) error
- func (fs *VirtualFileSystem) CopyDir(source, dest string) error
- func (fs *VirtualFileSystem) CopyFile(source, dest string) error
- func (fs *VirtualFileSystem) Create(path string) (File, error)
- func (fs *VirtualFileSystem) Exists(path string) bool
- func (fs *VirtualFileSystem) Lock(path string) (r Releaser, existed bool, err error)
- func (fs *VirtualFileSystem) Mkdir(path string, mode os.FileMode) error
- func (fs *VirtualFileSystem) MkdirAll(path string, mode os.FileMode) error
- func (fs *VirtualFileSystem) Open(path string) (File, error)
- func (fs *VirtualFileSystem) OpenFile(path string, flag int, perm os.FileMode) (File, error)
- func (fs *VirtualFileSystem) Remove(path string) error
- func (fs *VirtualFileSystem) RemoveAll(path string) error
- func (fs *VirtualFileSystem) Rename(oldname, newname string) error
- func (fs *VirtualFileSystem) Symlink(oldname, newname string) error
- func (fs *VirtualFileSystem) Walk(root string, walkFn filepath.WalkFunc) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrNotFound ¶
ErrNotFound tests to see if the error passed is a not found error or not.
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config encapsulates the requirements for generating a FileSystem
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 ¶
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 ¶
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.
type Option ¶
Option defines a option for generating a filesystem Config
func With ¶
With adds a type of filesystem to use for the configuration.
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 ¶
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 (*VirtualFileSystem) Symlink ¶
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.
Source Files
¶
- doc.go
- fsys.go
- local.go
- virtual.go