Add more comments

This commit is contained in:
Alexander Neumann 2015-05-02 15:51:40 +02:00
parent 0a65901e18
commit ff4dd1f1fb
2 changed files with 17 additions and 4 deletions

View file

@ -28,6 +28,7 @@ const (
var archiverAbortOnAllErrors = func(str string, fi os.FileInfo, err error) error { return err } var archiverAbortOnAllErrors = func(str string, fi os.FileInfo, err error) error { return err }
var archiverAllowAllFiles = func(string, os.FileInfo) bool { return true } var archiverAllowAllFiles = func(string, os.FileInfo) bool { return true }
// Archiver is used to backup a set of directories.
type Archiver struct { type Archiver struct {
s *server.Server s *server.Server
@ -37,6 +38,7 @@ type Archiver struct {
Filter func(item string, fi os.FileInfo) bool Filter func(item string, fi os.FileInfo) bool
} }
// NewArchiver returns a new archiver.
func NewArchiver(s *server.Server) *Archiver { func NewArchiver(s *server.Server) *Archiver {
arch := &Archiver{ arch := &Archiver{
s: s, s: s,
@ -53,6 +55,7 @@ func NewArchiver(s *server.Server) *Archiver {
return arch return arch
} }
// Save stores a blob read from rd in the server.
func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error { func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Reader) error {
debug.Log("Archiver.Save", "Save(%v, %v)\n", t, id.Str()) debug.Log("Archiver.Save", "Save(%v, %v)\n", t, id.Str())
@ -73,6 +76,7 @@ func (arch *Archiver) Save(t pack.BlobType, id backend.ID, length uint, rd io.Re
return nil return nil
} }
// SaveTreeJSON stores a tree in the server.
func (arch *Archiver) SaveTreeJSON(item interface{}) (backend.ID, error) { func (arch *Archiver) SaveTreeJSON(item interface{}) (backend.ID, error) {
data, err := json.Marshal(item) data, err := json.Marshal(item)
if err != nil { if err != nil {
@ -619,7 +623,9 @@ func (j archiveJob) Copy() pipe.Job {
return j.new return j.new
} }
func (arch *Archiver) Snapshot(p *Progress, paths []string, pid backend.ID) (*Snapshot, backend.ID, error) { // Snapshot creates a snapshot of the given paths. If parentID is set, this is
// used to compare the files with.
func (arch *Archiver) Snapshot(p *Progress, paths []string, parentID backend.ID) (*Snapshot, backend.ID, error) {
debug.Log("Archiver.Snapshot", "start for %v", paths) debug.Log("Archiver.Snapshot", "start for %v", paths)
debug.Break("Archiver.Snapshot") debug.Break("Archiver.Snapshot")
@ -641,11 +647,11 @@ func (arch *Archiver) Snapshot(p *Progress, paths []string, pid backend.ID) (*Sn
jobs := archivePipe{} jobs := archivePipe{}
// use parent snapshot (if some was given) // use parent snapshot (if some was given)
if pid != nil { if parentID != nil {
sn.Parent = pid sn.Parent = parentID
// load parent snapshot // load parent snapshot
parent, err := LoadSnapshot(arch.s, pid) parent, err := LoadSnapshot(arch.s, parentID)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
@ -745,6 +751,8 @@ func isFile(fi os.FileInfo) bool {
return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0 return fi.Mode()&(os.ModeType|os.ModeCharDevice) == 0
} }
// Scan traverses the dirs to collect Stat information while emitting progress
// information with p.
func Scan(dirs []string, p *Progress) (Stat, error) { func Scan(dirs []string, p *Progress) (Stat, error) {
p.Start() p.Start()
defer p.Done() defer p.Done()

View file

@ -13,6 +13,7 @@ import (
"github.com/restic/restic/server" "github.com/restic/restic/server"
) )
// Cache is used to handle the local cache.
type Cache struct { type Cache struct {
base string base string
} }
@ -29,6 +30,7 @@ func NewCache(be backend.Identifier) (*Cache, error) {
return &Cache{base: basedir}, nil return &Cache{base: basedir}, nil
} }
// Has checks if the local cache has the id.
func (c *Cache) Has(t backend.Type, subtype string, id backend.ID) (bool, error) { func (c *Cache) Has(t backend.Type, subtype string, id backend.ID) (bool, error) {
filename, err := c.filename(t, subtype, id) filename, err := c.filename(t, subtype, id)
if err != nil { if err != nil {
@ -51,6 +53,7 @@ func (c *Cache) Has(t backend.Type, subtype string, id backend.ID) (bool, error)
return true, nil return true, nil
} }
// Store returns an io.WriteCloser that is used to save new information to.
func (c *Cache) Store(t backend.Type, subtype string, id backend.ID) (io.WriteCloser, error) { func (c *Cache) Store(t backend.Type, subtype string, id backend.ID) (io.WriteCloser, error) {
filename, err := c.filename(t, subtype, id) filename, err := c.filename(t, subtype, id)
if err != nil { if err != nil {
@ -73,6 +76,7 @@ func (c *Cache) Store(t backend.Type, subtype string, id backend.ID) (io.WriteCl
return file, nil return file, nil
} }
// Load returns information from the cache.
func (c *Cache) Load(t backend.Type, subtype string, id backend.ID) (io.ReadCloser, error) { func (c *Cache) Load(t backend.Type, subtype string, id backend.ID) (io.ReadCloser, error) {
filename, err := c.filename(t, subtype, id) filename, err := c.filename(t, subtype, id)
if err != nil { if err != nil {
@ -98,6 +102,7 @@ func (c *Cache) purge(t backend.Type, subtype string, id backend.ID) error {
return err return err
} }
// Clear removes information from the cache that isn't present in the server any more.
func (c *Cache) Clear(s *server.Server) error { func (c *Cache) Clear(s *server.Server) error {
list, err := c.list(backend.Snapshot) list, err := c.list(backend.Snapshot)
if err != nil { if err != nil {