db

package
v0.14.11 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2016 License: MPL-2.0 Imports: 24 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.

Package db is a generated protocol buffer package.

It is generated from these files:
	structs.proto

It has these top-level messages:
	FileVersion
	VersionList
	FileInfoTruncated

Index

Constants

View Source
const (
	KeyTypeDevice = iota
	KeyTypeGlobal
	KeyTypeBlock
	KeyTypeDeviceStatistic
	KeyTypeFolderStatistic
	KeyTypeVirtualMtime
	KeyTypeFolderIdx
	KeyTypeDeviceIdx
	KeyTypeIndexID
)

Variables

View Source
var (
	ErrInvalidLengthStructs = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowStructs   = fmt.Errorf("proto: integer overflow")
)

Functions

func DropFolder

func DropFolder(db *Instance, folder string)

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

Types

type BlockFinder

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

func NewBlockFinder

func NewBlockFinder(db *Instance) *BlockFinder

func (*BlockFinder) Fix

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

Fix repairs incorrect blockmap entries, removing the old entry and replacing it with a new entry for the given block

func (*BlockFinder) Iterate

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

Iterate takes 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.

func (*BlockFinder) String

func (f *BlockFinder) String() string

type BlockMap

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

func NewBlockMap

func NewBlockMap(db *Instance, folder uint32) *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 Counts added in v0.14.10

type Counts struct {
	Files       int
	Directories int
	Symlinks    int
	Deleted     int
	Bytes       int64
}

type FileInfoTruncated

type FileInfoTruncated struct {
	Name          string                `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	Type          protocol.FileInfoType `protobuf:"varint,2,opt,name=type,proto3,enum=protocol.FileInfoType" json:"type,omitempty"`
	Size          int64                 `protobuf:"varint,3,opt,name=size,proto3" json:"size,omitempty"`
	Permissions   uint32                `protobuf:"varint,4,opt,name=permissions,proto3" json:"permissions,omitempty"`
	ModifiedS     int64                 `protobuf:"varint,5,opt,name=modified_s,json=modifiedS,proto3" json:"modified_s,omitempty"`
	ModifiedNs    int32                 `protobuf:"varint,11,opt,name=modified_ns,json=modifiedNs,proto3" json:"modified_ns,omitempty"`
	Deleted       bool                  `protobuf:"varint,6,opt,name=deleted,proto3" json:"deleted,omitempty"`
	Invalid       bool                  `protobuf:"varint,7,opt,name=invalid,proto3" json:"invalid,omitempty"`
	NoPermissions bool                  `protobuf:"varint,8,opt,name=no_permissions,json=noPermissions,proto3" json:"no_permissions,omitempty"`
	Version       protocol.Vector       `protobuf:"bytes,9,opt,name=version" json:"version"`
	Sequence      int64                 `protobuf:"varint,10,opt,name=sequence,proto3" json:"sequence,omitempty"`
}

Must be the same as FileInfo but without the blocks field

func (*FileInfoTruncated) Descriptor added in v0.14.0

func (*FileInfoTruncated) Descriptor() ([]byte, []int)

func (FileInfoTruncated) FileName added in v0.14.0

func (f FileInfoTruncated) FileName() string

func (FileInfoTruncated) FileSize added in v0.14.0

func (f FileInfoTruncated) FileSize() int64

func (FileInfoTruncated) HasPermissionBits added in v0.14.0

func (f FileInfoTruncated) HasPermissionBits() bool

func (FileInfoTruncated) IsDeleted added in v0.14.0

func (f FileInfoTruncated) IsDeleted() bool

func (FileInfoTruncated) IsDirectory added in v0.14.0

func (f FileInfoTruncated) IsDirectory() bool

func (FileInfoTruncated) IsInvalid added in v0.14.0

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

func (*FileInfoTruncated) Marshal added in v0.14.0

func (m *FileInfoTruncated) Marshal() (data []byte, err error)

func (*FileInfoTruncated) MarshalTo added in v0.14.0

func (m *FileInfoTruncated) MarshalTo(data []byte) (int, error)

func (FileInfoTruncated) ModTime added in v0.14.4

func (f FileInfoTruncated) ModTime() time.Time

func (*FileInfoTruncated) ProtoMessage added in v0.14.0

func (*FileInfoTruncated) ProtoMessage()

func (*FileInfoTruncated) ProtoSize added in v0.14.0

func (m *FileInfoTruncated) ProtoSize() (n int)

func (*FileInfoTruncated) Reset added in v0.14.0

func (m *FileInfoTruncated) Reset()

func (FileInfoTruncated) String added in v0.14.0

func (f FileInfoTruncated) String() string

func (*FileInfoTruncated) Unmarshal added in v0.14.0

func (m *FileInfoTruncated) Unmarshal(data []byte) error

type FileIntf

type FileIntf interface {
	FileSize() int64
	FileName() string
	IsDeleted() bool
	IsInvalid() bool
	IsDirectory() bool
	IsSymlink() bool
	HasPermissionBits() bool
}

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

type FileSet

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

func NewFileSet

func NewFileSet(folder string, db *Instance) *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) GlobalSize added in v0.12.0

func (s *FileSet) GlobalSize() Counts

func (*FileSet) IndexID added in v0.14.1

func (s *FileSet) IndexID(device protocol.DeviceID) protocol.IndexID

func (*FileSet) ListDevices added in v0.14.4

func (s *FileSet) ListDevices() []protocol.DeviceID

func (*FileSet) LocalSize added in v0.12.0

func (s *FileSet) LocalSize() Counts

func (*FileSet) MtimeFS added in v0.14.4

func (s *FileSet) MtimeFS() *fs.MtimeFS

func (*FileSet) Replace

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

func (*FileSet) Sequence added in v0.14.4

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

func (*FileSet) SetIndexID added in v0.14.1

func (s *FileSet) SetIndexID(device protocol.DeviceID, id protocol.IndexID)

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)

func (*FileSet) WithPrefixedGlobalTruncated

func (s *FileSet) WithPrefixedGlobalTruncated(prefix string, fn Iterator)

func (*FileSet) WithPrefixedHaveTruncated added in v0.12.21

func (s *FileSet) WithPrefixedHaveTruncated(device protocol.DeviceID, prefix string, fn Iterator)

type FileVersion added in v0.14.0

type FileVersion struct {
	Version protocol.Vector `protobuf:"bytes,1,opt,name=version" json:"version"`
	Device  []byte          `protobuf:"bytes,2,opt,name=device,proto3" json:"device,omitempty"`
}

func (*FileVersion) Descriptor added in v0.14.0

func (*FileVersion) Descriptor() ([]byte, []int)

func (*FileVersion) Marshal added in v0.14.0

func (m *FileVersion) Marshal() (data []byte, err error)

func (*FileVersion) MarshalTo added in v0.14.0

func (m *FileVersion) MarshalTo(data []byte) (int, error)

func (*FileVersion) ProtoMessage added in v0.14.0

func (*FileVersion) ProtoMessage()

func (*FileVersion) ProtoSize added in v0.14.0

func (m *FileVersion) ProtoSize() (n int)

func (*FileVersion) Reset added in v0.14.0

func (m *FileVersion) Reset()

func (*FileVersion) String added in v0.14.0

func (m *FileVersion) String() string

func (*FileVersion) Unmarshal added in v0.14.0

func (m *FileVersion) Unmarshal(data []byte) error

type Instance added in v0.12.0

type Instance struct {
	*leveldb.DB
	// contains filtered or unexported fields
}

func Open added in v0.12.0

func Open(file string) (*Instance, error)

func OpenMemory added in v0.12.0

func OpenMemory() *Instance

func (*Instance) Committed added in v0.13.8

func (db *Instance) Committed() int64

Committed returns the number of items committed to the database since startup

func (*Instance) DropDeltaIndexIDs added in v0.14.4

func (db *Instance) DropDeltaIndexIDs()

DropDeltaIndexIDs removes all index IDs from the database. This will cause a full index transmission on the next connection.

func (*Instance) ListFolders added in v0.12.0

func (db *Instance) ListFolders() []string

func (*Instance) Location added in v0.14.3

func (db *Instance) Location() string

Location returns the filesystem path where the database is stored

type Iterator

type Iterator func(f FileIntf) bool

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

type NamespacedKV

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

NamespacedKV is a simple key-value store using a specific namespace within a leveldb.

func NewNamespacedKV

func NewNamespacedKV(db *Instance, prefix string) *NamespacedKV

NewNamespacedKV returns a new NamespacedKV that lives in the namespace specified by the prefix.

func (NamespacedKV) Bool

func (n NamespacedKV) Bool(key string) (bool, bool)

Bool returns the stored value as a boolean and a boolean that is false if no value was stored at the key.

func (NamespacedKV) Bytes

func (n NamespacedKV) Bytes(key string) ([]byte, bool)

Bytes returns the stored value as a raw byte slice and a boolean that is false if no value was stored at the key.

func (NamespacedKV) Delete

func (n NamespacedKV) Delete(key string)

Delete deletes the specified key. It is allowed to delete a nonexistent key.

func (*NamespacedKV) Int64

func (n *NamespacedKV) Int64(key string) (int64, bool)

Int64 returns the stored value interpreted as an int64 and a boolean that is false if no value was stored at the key.

func (*NamespacedKV) PutBool

func (n *NamespacedKV) PutBool(key string, val bool)

PutBool stores a new boolean. Any existing value (even if of another type) is overwritten.

func (*NamespacedKV) PutBytes

func (n *NamespacedKV) PutBytes(key string, val []byte)

PutBytes stores a new byte slice. Any existing value (even if of another type) is overwritten.

func (*NamespacedKV) PutInt64

func (n *NamespacedKV) PutInt64(key string, val int64)

PutInt64 stores a new int64. Any existing value (even if of another type) is overwritten.

func (*NamespacedKV) PutString

func (n *NamespacedKV) PutString(key, val string)

PutString stores a new string. Any existing value (even if of another type) is overwritten.

func (*NamespacedKV) PutTime

func (n *NamespacedKV) PutTime(key string, val time.Time)

PutTime stores a new time.Time. Any existing value (even if of another type) is overwritten.

func (*NamespacedKV) Reset

func (n *NamespacedKV) Reset()

Reset removes all entries in this namespace.

func (NamespacedKV) String

func (n NamespacedKV) String(key string) (string, bool)

String returns the stored value interpreted as a string and a boolean that is false if no value was stored at the key.

func (NamespacedKV) Time

func (n NamespacedKV) Time(key string) (time.Time, bool)

Time returns the stored value interpreted as a time.Time and a boolean that is false if no value was stored at the key.

type VersionList added in v0.13.5

type VersionList struct {
	Versions []FileVersion `protobuf:"bytes,1,rep,name=versions" json:"versions"`
}

func (*VersionList) Descriptor added in v0.14.0

func (*VersionList) Descriptor() ([]byte, []int)

func (*VersionList) Marshal added in v0.14.0

func (m *VersionList) Marshal() (data []byte, err error)

func (*VersionList) MarshalTo added in v0.14.0

func (m *VersionList) MarshalTo(data []byte) (int, error)

func (*VersionList) ProtoMessage added in v0.14.0

func (*VersionList) ProtoMessage()

func (*VersionList) ProtoSize added in v0.14.0

func (m *VersionList) ProtoSize() (n int)

func (*VersionList) Reset added in v0.14.0

func (m *VersionList) Reset()

func (VersionList) String added in v0.13.5

func (l VersionList) String() string

func (*VersionList) Unmarshal added in v0.14.0

func (m *VersionList) Unmarshal(data []byte) error

Jump to

Keyboard shortcuts

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