2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-05 21:07:52 +00:00

Use new Node if file has changed

Closes #604
This commit is contained in:
Alexander Neumann 2016-12-10 16:54:20 +01:00
parent 7d71bad4eb
commit 3fcbb4ac25

View File

@ -207,18 +207,18 @@ func updateNodeContent(node *restic.Node, results []saveResult) error {
// SaveFile stores the content of the file on the backend as a Blob by calling // SaveFile stores the content of the file on the backend as a Blob by calling
// Save for each chunk. // Save for each chunk.
func (arch *Archiver) SaveFile(p *restic.Progress, node *restic.Node) error { func (arch *Archiver) SaveFile(p *restic.Progress, node *restic.Node) (*restic.Node, error) {
file, err := fs.Open(node.Path) file, err := fs.Open(node.Path)
defer file.Close() defer file.Close()
if err != nil { if err != nil {
return errors.Wrap(err, "Open") return nil, errors.Wrap(err, "Open")
} }
debug.RunHook("archiver.SaveFile", node.Path) debug.RunHook("archiver.SaveFile", node.Path)
node, err = arch.reloadFileIfChanged(node, file) node, err = arch.reloadFileIfChanged(node, file)
if err != nil { if err != nil {
return err return nil, err
} }
chnker := chunker.New(file, arch.repo.Config().ChunkerPolynomial) chnker := chunker.New(file, arch.repo.Config().ChunkerPolynomial)
@ -231,7 +231,7 @@ func (arch *Archiver) SaveFile(p *restic.Progress, node *restic.Node) error {
} }
if err != nil { if err != nil {
return errors.Wrap(err, "chunker.Next") return nil, errors.Wrap(err, "chunker.Next")
} }
resCh := make(chan saveResult, 1) resCh := make(chan saveResult, 1)
@ -241,11 +241,11 @@ func (arch *Archiver) SaveFile(p *restic.Progress, node *restic.Node) error {
results, err := waitForResults(resultChannels) results, err := waitForResults(resultChannels)
if err != nil { if err != nil {
return err return nil, err
} }
err = updateNodeContent(node, results) err = updateNodeContent(node, results)
return err
return node, err
} }
func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-chan struct{}, entCh <-chan pipe.Entry) { func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-chan struct{}, entCh <-chan pipe.Entry) {
@ -309,7 +309,7 @@ func (arch *Archiver) fileWorker(wg *sync.WaitGroup, p *restic.Progress, done <-
// otherwise read file normally // otherwise read file normally
if node.Type == "file" && len(node.Content) == 0 { if node.Type == "file" && len(node.Content) == 0 {
debug.Log(" read and save %v, content: %v", e.Path(), node.Content) debug.Log(" read and save %v, content: %v", e.Path(), node.Content)
err = arch.SaveFile(p, node) node, err = arch.SaveFile(p, node)
if err != nil { if err != nil {
// TODO: integrate error reporting // TODO: integrate error reporting
fmt.Fprintf(os.Stderr, "error for %v: %v\n", node.Path, err) fmt.Fprintf(os.Stderr, "error for %v: %v\n", node.Path, err)