filesystem

package
v0.0.0-...-5d142b5 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2016 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ModifiedComparator = func(src File, dest File) bool {
	if src.ModTime().After(dest.ModTime()) {
		return false
	}
	return true
}

Compares the last modified time of the File

Functions

func FileTreeToMap

func FileTreeToMap(tree FileTree, base string) (map[string]File, error)

Convert a FileTree to an Ordered ListMap

func FileTreeWalk

func FileTreeWalk(tree FileTree, treeFunc func(tree FileTree) (FileTree, error)) error

Recursively walk a FileTree and run a self-type function on each node. Walker function is able to mutate the FileTree.

Navigates the tree in a top left to bottom right fashion

Types

type File

type File struct {
	FileName    string      // base name of the file
	FilePath    string      // Full path to file, including filename
	FileSize    int64       // length in bytes for regular files; system-dependent for others
	FileModTime time.Time   // modification time
	FileMode    os.FileMode // File details including perms
}

Simple File abstraction (based on os.FileInfo)

All local and remote files will be represented as a File. It is up to the specific FileSystem implementation to uphold this

func FileMapDiff

func FileMapDiff(src map[string]File, target map[string]File, comparators ...func(left File, right File) bool) (diff []File, err error)

func (File) IsDir

func (f File) IsDir() bool

func (File) ModTime

func (f File) ModTime() time.Time

func (File) Mode

func (f File) Mode() os.FileMode

func (File) Name

func (f File) Name() string

func (File) Path

func (f File) Path() string

func (File) Size

func (f File) Size() int64

func (File) Sys

func (f File) Sys() interface{}

type FileComparator

type FileComparator func(src File, dest File) bool

A function that returns true iff the src and dest files are the same based on their definition

type FileMap

type FileMap map[string]File

type FileSystem

type FileSystem interface {
	Dir(string) ([]File, error)                           // Read the contents of a directory
	Read(File) ([]byte, error)                            // Read a File
	ReadFile(file string) (File, error)                   // Read a file and return a File
	Write(file File, data []byte, perm os.FileMode) error // Write a File
	FileTree(root File) *FileTree                         // Returns a FileTree structure of Files representing the FileSystem hierarchy
	FileMap(root File) FileMap                            // Returns a FileMap structure of Files representing a flattened FileSystem hierarchy
	MkDir(file File) error
	Delete(file string) error // Delete a file on the FileSystem
}

Generic File System abstraction

type FileTree

type FileTree struct {
	StdFile       File
	StdParentNode *FileTree
	StdChildNodes []*FileTree
}

Default Impl

func (*FileTree) ChildNodes

func (fs *FileTree) ChildNodes() []*FileTree

func (*FileTree) File

func (fs *FileTree) File() File

func (*FileTree) ParentNode

func (fs *FileTree) ParentNode() *FileTree

type MockFile

type MockFile struct {
	MockName     string    // base name of the file
	MockPath     string    // base name of the file
	MockSize     int64     // length in bytes for regular files; system-dependent for others
	MockModTime  time.Time // modification time
	MockIsDir    bool      // abbreviation for Mode().IsDir()
	MockFileMode os.FileMode
	MockFileSys  interface{}
}

func (*MockFile) IsDir

func (f *MockFile) IsDir() bool

func (*MockFile) ModTime

func (f *MockFile) ModTime() time.Time

func (*MockFile) Mode

func (f *MockFile) Mode() os.FileMode

func (*MockFile) Name

func (f *MockFile) Name() string

func (*MockFile) Path

func (f *MockFile) Path() string

func (*MockFile) Size

func (f *MockFile) Size() int64

func (*MockFile) Sys

func (f *MockFile) Sys() interface{}

type MockFileSystem

type MockFileSystem struct {
	ReadBytes []byte
	ReadError error

	WriteError error

	DirFiles []File
	DirError error

	FileTreeTree  *FileTree
	FileMapMap    FileMap
	MockFile      File
	MockFileError error
}

func (MockFileSystem) Delete

func (fs MockFileSystem) Delete(string) error

func (MockFileSystem) Dir

func (fs MockFileSystem) Dir(string) ([]File, error)

func (MockFileSystem) FileMap

func (fs MockFileSystem) FileMap(root File) FileMap

func (MockFileSystem) FileTree

func (fs MockFileSystem) FileTree(root File) *FileTree

func (MockFileSystem) MkDir

func (fs MockFileSystem) MkDir(file File) error

func (MockFileSystem) Read

func (fs MockFileSystem) Read(File) ([]byte, error)

func (MockFileSystem) ReadFile

func (fs MockFileSystem) ReadFile(file string) (File, error)

func (MockFileSystem) Write

func (fs MockFileSystem) Write(File, []byte, os.FileMode) error

type MockFileTree

type MockFileTree struct {
	ParentNodeFileTree *FileTree
	ChildNodesArray    []*FileTree
	FileFile           File
}

func (*MockFileTree) ChildNodes

func (t *MockFileTree) ChildNodes() []*FileTree

func (*MockFileTree) File

func (t *MockFileTree) File() File

func (*MockFileTree) ParentNode

func (t *MockFileTree) ParentNode() *FileTree

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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