mirror of
https://github.com/restic/restic.git
synced 2024-12-22 15:57:07 +00:00
Rename functions, remove code for compare
* Archiver: Rename loadTree -> scan and LoadTree -> Scan * Archiver: Remove code to compare against an old snapshot/tree, the current implementation was really slow
This commit is contained in:
parent
34afb00d55
commit
a93bc3c991
2 changed files with 8 additions and 106 deletions
112
archiver.go
112
archiver.go
|
@ -1,7 +1,6 @@
|
||||||
package restic
|
package restic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -25,8 +24,7 @@ type Archiver struct {
|
||||||
s Server
|
s Server
|
||||||
ch *ContentHandler
|
ch *ContentHandler
|
||||||
|
|
||||||
bl *BlobList // blobs used for the current snapshot
|
bl *BlobList // blobs used for the current snapshot
|
||||||
parentBl *BlobList // blobs from the parent snapshot
|
|
||||||
|
|
||||||
fileToken chan struct{}
|
fileToken chan struct{}
|
||||||
blobToken chan struct{}
|
blobToken chan struct{}
|
||||||
|
@ -255,45 +253,8 @@ func (arch *Archiver) SaveFile(node *Node) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (arch *Archiver) populateFromOldTree(tree, oldTree Tree) error {
|
func (arch *Archiver) scan(dir string) (*Tree, error) {
|
||||||
// update content from old tree
|
var err error
|
||||||
err := tree.PopulateFrom(oldTree)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// add blobs to bloblist
|
|
||||||
for _, node := range tree {
|
|
||||||
if node.Content != nil {
|
|
||||||
for _, blobID := range node.Content {
|
|
||||||
blob, err := arch.parentBl.Find(Blob{ID: blobID})
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
arch.bl.Insert(blob)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error) {
|
|
||||||
var (
|
|
||||||
oldTree Tree
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if oldTreeID != nil {
|
|
||||||
// load old tree
|
|
||||||
oldTree, err = LoadTree(arch.ch, oldTreeID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, arrar.Annotate(err, "load old tree")
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("old tree: %v\n", oldTree)
|
|
||||||
}
|
|
||||||
|
|
||||||
// open and list path
|
// open and list path
|
||||||
fd, err := os.Open(dir)
|
fd, err := os.Open(dir)
|
||||||
|
@ -328,29 +289,13 @@ func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
if entry.IsDir() {
|
if entry.IsDir() {
|
||||||
oldSubtree, err := oldTree.Find(node.Name)
|
node.Tree, err = arch.scan(path)
|
||||||
if err != nil && err != ErrNodeNotFound {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var oldSubtreeID backend.ID
|
|
||||||
if err == nil {
|
|
||||||
oldSubtreeID = oldSubtree.Subtree
|
|
||||||
}
|
|
||||||
|
|
||||||
node.Tree, err = arch.loadTree(path, oldSubtreeID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// populate with content from oldTree
|
|
||||||
err = arch.populateFromOldTree(tree, oldTree)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, node := range tree {
|
for _, node := range tree {
|
||||||
if node.Type == "file" && node.Content != nil {
|
if node.Type == "file" && node.Content != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -372,34 +317,7 @@ func (arch *Archiver) loadTree(dir string, oldTreeID backend.ID) (*Tree, error)
|
||||||
return &tree, nil
|
return &tree, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (arch *Archiver) LoadTree(path string, parentSnapshot backend.ID) (*Tree, error) {
|
func (arch *Archiver) Scan(path string) (*Tree, error) {
|
||||||
var oldTree Tree
|
|
||||||
|
|
||||||
if parentSnapshot != nil {
|
|
||||||
// load old tree from snapshot
|
|
||||||
snapshot, err := LoadSnapshot(arch.ch, parentSnapshot)
|
|
||||||
if err != nil {
|
|
||||||
return nil, arrar.Annotate(err, "load old snapshot")
|
|
||||||
}
|
|
||||||
|
|
||||||
if snapshot.Tree == nil {
|
|
||||||
return nil, errors.New("snapshot without tree!")
|
|
||||||
}
|
|
||||||
|
|
||||||
// load old bloblist from snapshot
|
|
||||||
arch.parentBl, err = LoadBlobList(arch.ch, snapshot.Map)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
oldTree, err = LoadTree(arch.ch, snapshot.Tree)
|
|
||||||
if err != nil {
|
|
||||||
return nil, arrar.Annotate(err, "load old tree")
|
|
||||||
}
|
|
||||||
|
|
||||||
debug("old tree: %v\n", oldTree)
|
|
||||||
}
|
|
||||||
|
|
||||||
// reset global stats
|
// reset global stats
|
||||||
arch.updateStats = Stats{}
|
arch.updateStats = Stats{}
|
||||||
|
|
||||||
|
@ -416,13 +334,7 @@ func (arch *Archiver) LoadTree(path string, parentSnapshot backend.ID) (*Tree, e
|
||||||
if node.Type != "dir" {
|
if node.Type != "dir" {
|
||||||
t := &Tree{node}
|
t := &Tree{node}
|
||||||
|
|
||||||
// populate with content from oldTree
|
// update stats
|
||||||
err = arch.populateFromOldTree(*t, oldTree)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// if no old node has been found, update stats
|
|
||||||
if node.Content == nil && node.Subtree == nil {
|
if node.Content == nil && node.Subtree == nil {
|
||||||
arch.Stats.Files = 1
|
arch.Stats.Files = 1
|
||||||
arch.Stats.Bytes = node.Size
|
arch.Stats.Bytes = node.Size
|
||||||
|
@ -435,17 +347,7 @@ func (arch *Archiver) LoadTree(path string, parentSnapshot backend.ID) (*Tree, e
|
||||||
|
|
||||||
arch.Stats.Directories = 1
|
arch.Stats.Directories = 1
|
||||||
|
|
||||||
var oldSubtreeID backend.ID
|
node.Tree, err = arch.scan(path)
|
||||||
oldSubtree, err := oldTree.Find(node.Name)
|
|
||||||
if err != nil && err != ErrNodeNotFound {
|
|
||||||
return nil, arrar.Annotate(err, "search node in old tree")
|
|
||||||
}
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
oldSubtreeID = oldSubtree.Subtree
|
|
||||||
}
|
|
||||||
|
|
||||||
node.Tree, err = arch.loadTree(path, oldSubtreeID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, arrar.Annotate(err, "loadTree()")
|
return nil, arrar.Annotate(err, "loadTree()")
|
||||||
}
|
}
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (cmd CmdBackup) Execute(args []string) error {
|
||||||
// return true
|
// return true
|
||||||
// }
|
// }
|
||||||
|
|
||||||
t, err := arch.LoadTree(target, parentSnapshotID)
|
t, err := arch.Scan(target)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "error: %v\n", err)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue