fs

package
v0.0.0-...-08e1f15 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2011 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

View Source
const BLOCKSIZE int = 8192

Block size used for checksum, comparison, transmitting deltas.

View Source
const RELOC_PREFIX string = "_reloc"

Variables

This section is empty.

Functions

func AlwaysMatch

func AlwaysMatch(path string, f *os.FileInfo) bool

func CalcStrong

func CalcStrong(dir Dir) string

Calculate the strong checksum of a directory.

func IndexFile

func IndexFile(path string) (fileInfo *FileInfo, blocksInfo []*BlockInfo, err os.Error)

Build a hierarchical tree model representing a file's contents

func Move

func Move(src string, dst string) (err os.Error)

Move src to dst. Try a rename. If that fails due to different filesystems, try a copy/delete instead.

func PostOrderWalk

func PostOrderWalk(path string, visitor filepath.Visitor, errors chan<- os.Error)

func RelPath

func RelPath(item FsNode) string

Given a filesystem node, calculate the relative path string to it from the root node.

func SplitNames

func SplitNames(path string) []string

func StrongChecksum

func StrongChecksum(buf []byte) string

Strong checksum algorithm used throughout replican For now, it's SHA-1.

func Walk

func Walk(node Node, visitor NodeVisitor)

Traverse the hierarchical tree model with a user-defined NodeVisitor function.

Types

type Block

type Block interface {
	Node

	Info() *BlockInfo
}

type BlockInfo

type BlockInfo struct {
	Position int
	Weak     int
	Strong   string
	Parent   string
}

Represent a block in a hierarchical tree model. Blocks are BLOCKSIZE chunks of data which comprise files.

func IndexBlock

func IndexBlock(buf []byte) *BlockInfo

Model a block with weak and strong checksums.

func (*BlockInfo) Offset

func (block *BlockInfo) Offset() int64

Get the byte offset of this block in its containing file.

type BlockStore

type BlockStore interface {
	Repo() NodeRepo

	// Given a strong checksum of a block, get the bytes for that block.
	ReadBlock(strong string) ([]byte, os.Error)

	// Given the strong checksum of a file, start and end positions, get those bytes.
	ReadInto(strong string, from int64, length int64, writer io.Writer) (int64, os.Error)
}

Provide access to the raw byte storage.

type Blocks

type Blocks struct {
	Contents []Block
}

func (*Blocks) Len

func (blocks *Blocks) Len() int

func (*Blocks) Less

func (blocks *Blocks) Less(i, j int) bool

func (*Blocks) Swap

func (blocks *Blocks) Swap(i, j int)

type Dir

type Dir interface {
	FsNode

	Info() *DirInfo

	SubDirs() []Dir

	Files() []File

	UpdateStrong() string
}

func IndexDir

func IndexDir(path string, repo NodeRepo) (Dir, []os.Error)

type DirInfo

type DirInfo struct {
	Name   string
	Mode   uint32
	Strong string
	Parent string
}

Represent a directory in a hierarchical tree model.

type Dirs

type Dirs struct {
	Contents []Dir
}

func (*Dirs) Len

func (dirs *Dirs) Len() int

func (*Dirs) Less

func (dirs *Dirs) Less(i, j int) bool

func (*Dirs) Swap

func (dirs *Dirs) Swap(i, j int)

type File

type File interface {
	FsNode

	Info() *FileInfo

	Blocks() []Block
}

type FileInfo

type FileInfo struct {
	Name   string
	Mode   uint32 // TODO: move to repo wrapper?
	Size   int64
	Strong string
	Parent string
}

Represent a file in a hierarchical tree model.

type Files

type Files struct {
	Contents []File
}

func (*Files) Len

func (files *Files) Len() int

func (*Files) Less

func (files *Files) Less(i, j int) bool

func (*Files) Swap

func (files *Files) Swap(i, j int)

type FsNode

type FsNode interface {

	// FsNode extends the concept of Node.
	Node

	// All FsNodes have names (file or directory name).
	Name() string

	Mode() uint32
}

FsNodes are members of a hierarchical index that map directly onto the filesystem: files and directories.

func Lookup

func Lookup(dir Dir, relpath string) (fsNode FsNode, hasItem bool)

type IndexFilter

type IndexFilter func(path string, f *os.FileInfo) bool

func AllMatch

func AllMatch(filters ...IndexFilter) IndexFilter

func AnyMatch

func AnyMatch(filters ...IndexFilter) IndexFilter

type Indexer

type Indexer struct {
	Path   string
	Repo   NodeRepo
	Filter IndexFilter
	Errors chan<- os.Error
	// contains filtered or unexported fields
}

func (*Indexer) Index

func (indexer *Indexer) Index() Dir

func (*Indexer) VisitDir

func (indexer *Indexer) VisitDir(path string, f *os.FileInfo) bool

Indexer callback for directories

func (*Indexer) VisitFile

func (indexer *Indexer) VisitFile(path string, f *os.FileInfo)

IndexDir visitor callback for files

type LocalDirStore

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

func (LocalDirStore) ReadBlock

func (store LocalDirStore) ReadBlock(strong string) ([]byte, os.Error)

func (LocalDirStore) ReadInto

func (store LocalDirStore) ReadInto(strong string, from int64, length int64, writer io.Writer) (int64, os.Error)

func (LocalDirStore) RelPath

func (store LocalDirStore) RelPath(fullpath string) (relpath string)

func (LocalDirStore) Relocate

func (store LocalDirStore) Relocate(fullpath string) (relocFullpath string, err os.Error)

func (LocalDirStore) Repo

func (store LocalDirStore) Repo() NodeRepo

func (LocalDirStore) Resolve

func (store LocalDirStore) Resolve(relpath string) string

func (*LocalDirStore) Root

func (store *LocalDirStore) Root() FsNode

func (LocalDirStore) RootPath

func (store LocalDirStore) RootPath() string

type LocalFileStore

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

func (LocalFileStore) ReadBlock

func (store LocalFileStore) ReadBlock(strong string) ([]byte, os.Error)

func (*LocalFileStore) ReadInto

func (store *LocalFileStore) ReadInto(strong string, from int64, length int64, writer io.Writer) (int64, os.Error)

func (LocalFileStore) RelPath

func (store LocalFileStore) RelPath(fullpath string) (relpath string)

func (LocalFileStore) Relocate

func (store LocalFileStore) Relocate(fullpath string) (relocFullpath string, err os.Error)

func (LocalFileStore) Repo

func (store LocalFileStore) Repo() NodeRepo

func (*LocalFileStore) Resolve

func (store *LocalFileStore) Resolve(_ string) string

func (*LocalFileStore) Root

func (store *LocalFileStore) Root() FsNode

func (LocalFileStore) RootPath

func (store LocalFileStore) RootPath() string

type LocalStore

type LocalStore interface {
	BlockStore

	RelPath(fullpath string) (relpath string)

	Relocate(fullpath string) (relocFullpath string, err os.Error)

	Resolve(relpath string) string

	RootPath() string
	// contains filtered or unexported methods
}

A local file implementation of BlockStore

func NewLocalStore

func NewLocalStore(rootPath string, repo NodeRepo) (local LocalStore, err os.Error)

type MemRepo

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

func NewMemRepo

func NewMemRepo() *MemRepo

func (*MemRepo) AddBlock

func (repo *MemRepo) AddBlock(file File, info *BlockInfo) Block

func (*MemRepo) AddDir

func (repo *MemRepo) AddDir(dir Dir, info *DirInfo) Dir

func (*MemRepo) AddFile

func (repo *MemRepo) AddFile(dir Dir, fileInfo *FileInfo, blocksInfo []*BlockInfo) File

func (*MemRepo) Block

func (repo *MemRepo) Block(strong string) (block Block, has bool)

func (*MemRepo) Close

func (repo *MemRepo) Close()

func (*MemRepo) Dir

func (repo *MemRepo) Dir(strong string) (dir Dir, has bool)

func (*MemRepo) File

func (repo *MemRepo) File(strong string) (file File, has bool)

func (*MemRepo) IndexFilter

func (repo *MemRepo) IndexFilter() IndexFilter

func (*MemRepo) Root

func (repo *MemRepo) Root() FsNode

func (*MemRepo) WeakBlock

func (repo *MemRepo) WeakBlock(weak int) (block Block, has bool)

type Node

type Node interface {
	Repo() NodeRepo

	// Get the node that contains this node in the hierarchical index.
	Parent() (FsNode, bool)
}

Nodes are any member of a hierarchical tree model representing a part of the filesystem. Nodes include files and directories, and also blocks within the files.

type NodeRepo

type NodeRepo interface {
	Root() FsNode

	WeakBlock(weak int) (Block, bool)

	Block(strong string) (Block, bool)

	File(strong string) (File, bool)

	Dir(strong string) (Dir, bool)

	AddBlock(file File, blockInfo *BlockInfo) Block

	AddFile(dir Dir, fileInfo *FileInfo, blocksInfo []*BlockInfo) File

	AddDir(dir Dir, subdirInfo *DirInfo) Dir

	Close()

	IndexFilter() IndexFilter
}

type NodeVisitor

type NodeVisitor func(Node) bool

Visitor function to traverse a hierarchical tree model.

type WeakChecksum

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

Represent a weak checksum as described in the rsync algorithm paper

func (*WeakChecksum) Get

func (weak *WeakChecksum) Get() int

Get the current weak checksum value

func (*WeakChecksum) Reset

func (weak *WeakChecksum) Reset()

Reset the state of the checksum

func (*WeakChecksum) Roll

func (weak *WeakChecksum) Roll(removedByte byte, newByte byte)

Roll the checksum forward by one byte

func (*WeakChecksum) Write

func (weak *WeakChecksum) Write(buf []byte)

Write a block of data into the checksum

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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