db

package
v0.10.22 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2015 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

Package db provides a set type to track local/remote files with newness checks. We must do a certain amount of normalization in here. We will get fed paths with either native or wire-format separators and encodings depending on who calls us. We transform paths to wire-format (NFC and slashes) on the way to the database, and transform to native format (varying separator and encoding) on the way back out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlocksToSize

func BlocksToSize(num int) int64

func DropFolder

func DropFolder(db *leveldb.DB, folder string)

DropFolder clears out all information related to the given folder from the database.

func ListFolders

func ListFolders(db *leveldb.DB) []string

ListFolders returns the folder IDs seen in the database.

Types

type BlockFinder

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

func NewBlockFinder

func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder

func (*BlockFinder) Changed

func (f *BlockFinder) Changed(cfg config.Configuration) error

Implements config.Handler interface

func (*BlockFinder) Fix

func (f *BlockFinder) Fix(folder, file string, index int32, oldHash, newHash []byte) error

A method for repairing incorrect blockmap entries, removes the old entry and replaces it with a new entry for the given block

func (*BlockFinder) Iterate

func (f *BlockFinder) Iterate(hash []byte, iterFn func(string, string, int32) bool) bool

An iterator function which iterates over all matching blocks for the given hash. The iterator function has to return either true (if they are happy with the block) or false to continue iterating for whatever reason. The iterator finally returns the result, whether or not a satisfying block was eventually found.

type BlockMap

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

func NewBlockMap

func NewBlockMap(db *leveldb.DB, folder string) *BlockMap

func (*BlockMap) Add

func (m *BlockMap) Add(files []protocol.FileInfo) error

Add files to the block map, ignoring any deleted or invalid files.

func (*BlockMap) Discard

func (m *BlockMap) Discard(files []protocol.FileInfo) error

Discard block map state, removing the given files

func (*BlockMap) Drop

func (m *BlockMap) Drop() error

Drop block map, removing all entries related to this block map from the db.

func (*BlockMap) Update

func (m *BlockMap) Update(files []protocol.FileInfo) error

Update block map state, removing any deleted or invalid files.

type FileInfoTruncated

type FileInfoTruncated struct {
	Name         string // max:8192
	Flags        uint32
	Modified     int64
	Version      int64
	LocalVersion int64
	NumBlocks    int32
}

Used for unmarshalling a FileInfo structure but skipping the block list.

func ToTruncated added in v0.10.22

func ToTruncated(file protocol.FileInfo) FileInfoTruncated

func (FileInfoTruncated) AppendXDR

func (o FileInfoTruncated) AppendXDR(bs []byte) ([]byte, error)

func (*FileInfoTruncated) DecodeXDR

func (o *FileInfoTruncated) DecodeXDR(r io.Reader) error

func (FileInfoTruncated) EncodeXDR

func (o FileInfoTruncated) EncodeXDR(w io.Writer) (int, error)

func (FileInfoTruncated) HasPermissionBits

func (f FileInfoTruncated) HasPermissionBits() bool

func (FileInfoTruncated) IsDeleted

func (f FileInfoTruncated) IsDeleted() bool

func (FileInfoTruncated) IsDirectory

func (f FileInfoTruncated) IsDirectory() bool

func (FileInfoTruncated) IsInvalid

func (f FileInfoTruncated) IsInvalid() bool
func (f FileInfoTruncated) IsSymlink() bool

func (FileInfoTruncated) MarshalXDR

func (o FileInfoTruncated) MarshalXDR() ([]byte, error)

func (FileInfoTruncated) MustMarshalXDR

func (o FileInfoTruncated) MustMarshalXDR() []byte

func (FileInfoTruncated) Size

func (f FileInfoTruncated) Size() int64

Returns a statistical guess on the size, not the exact figure

func (FileInfoTruncated) String

func (f FileInfoTruncated) String() string

func (*FileInfoTruncated) UnmarshalXDR

func (o *FileInfoTruncated) UnmarshalXDR(bs []byte) error

type FileIntf

type FileIntf interface {
	Size() int64
	IsDeleted() bool
	IsInvalid() bool
	IsDirectory() bool
	IsSymlink() bool
	HasPermissionBits() bool
}

FileIntf is the set of methods implemented by both protocol.FileInfo and protocol.FileInfoTruncated.

type FileSet

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

func NewFileSet

func NewFileSet(folder string, db *leveldb.DB) *FileSet

func (*FileSet) Availability

func (s *FileSet) Availability(file string) []protocol.DeviceID

func (*FileSet) Get

func (s *FileSet) Get(device protocol.DeviceID, file string) (protocol.FileInfo, bool)

func (*FileSet) GetGlobal

func (s *FileSet) GetGlobal(file string) (protocol.FileInfo, bool)

func (*FileSet) GetGlobalTruncated

func (s *FileSet) GetGlobalTruncated(file string) (FileInfoTruncated, bool)

func (*FileSet) LocalVersion

func (s *FileSet) LocalVersion(device protocol.DeviceID) int64

func (*FileSet) Replace

func (s *FileSet) Replace(device protocol.DeviceID, fs []protocol.FileInfo)

func (*FileSet) ReplaceWithDelete

func (s *FileSet) ReplaceWithDelete(device protocol.DeviceID, fs []protocol.FileInfo)

func (*FileSet) Update

func (s *FileSet) Update(device protocol.DeviceID, fs []protocol.FileInfo)

func (*FileSet) WithGlobal

func (s *FileSet) WithGlobal(fn Iterator)

func (*FileSet) WithGlobalTruncated

func (s *FileSet) WithGlobalTruncated(fn Iterator)

func (*FileSet) WithHave

func (s *FileSet) WithHave(device protocol.DeviceID, fn Iterator)

func (*FileSet) WithHaveTruncated

func (s *FileSet) WithHaveTruncated(device protocol.DeviceID, fn Iterator)

func (*FileSet) WithNeed

func (s *FileSet) WithNeed(device protocol.DeviceID, fn Iterator)

func (*FileSet) WithNeedTruncated

func (s *FileSet) WithNeedTruncated(device protocol.DeviceID, fn Iterator)

type Iterator

type Iterator func(f FileIntf) bool

The Iterator is called with either a protocol.FileInfo or a protocol.FileInfoTruncated (depending on the method) and returns true to continue iteration, false to stop.

Jump to

Keyboard shortcuts

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