db

package
v0.0.0-...-47a16c3 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	File = Label(iota)
	Conflict
	Directory
	Deleted
)
View Source
const (
	TRADB = ".trago.db"
)

Variables

This section is empty.

Functions

func MergeVectors

func MergeVectors(v1 map[string]int, v2 map[string]int)

Types

type FileData

type FileData struct {
	Name string
	Data []byte
	Mode uint32
}

type FileState

type FileState struct {
	Size    int
	MTime   int64
	Version int
	Replica string
	Hash    string
	Mode    uint32
}

type FileTag

type FileTag struct {
	Label Label
	Mode  uint32
}

type Label

type Label uint8

type TagList

type TagList struct {
	Files map[string]FileTag
	Dirs  map[string]FileTag
}

type TraDb

type TraDb struct {
	ReplicaId  string
	VersionVec map[string]int
	Files      map[string]FileState
}

func New

func New() (*TraDb, error)

New creates a new TraDb.

The replica ID is a random string, and the version number is set to 1. Checks for files in the current directory and stores relevant file state in a map.

func Parse

func Parse(data string) (*TraDb, error)

Parse parses a TraDb structure. Fails if the given string is not in the correct format.

func ParseFile

func ParseFile() (*TraDb, error)

ParseFile parses a TraDb from the db file in the current directory. If the file doesn't exist, a new TraDb is created using New.

func (*TraDb) Compare

func (local *TraDb) Compare(remote *TraDb) (TagList, error)

Compare compares two TraDbs. Returns a TagList which gives the FileTag for each changed file.

func (*TraDb) Update

func (db *TraDb) Update() error

Update looks for modified files in the current directory and updates the filemap accordingly.

func (*TraDb) UpdateMTimes

func (db *TraDb) UpdateMTimes() error

func (*TraDb) WriteToFile

func (tradb *TraDb) WriteToFile() error

WriteToFile writes a TraDb to the db file .trago.db.

Jump to

Keyboard shortcuts

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