mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 04:45:15 +00:00
archiver: remove unused fileInfo from progress callback
This commit is contained in:
parent
dcb00fd2d1
commit
32f4997733
@ -647,7 +647,7 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
|
||||
}
|
||||
|
||||
errorHandler := func(item string, err error) error {
|
||||
return progressReporter.Error(item, nil, err)
|
||||
return progressReporter.Error(item, err)
|
||||
}
|
||||
|
||||
messageHandler := func(msg string, args ...interface{}) {
|
||||
@ -690,9 +690,9 @@ func runBackup(opts BackupOptions, gopts GlobalOptions, term *termstatus.Termina
|
||||
arch.Select = selectFilter
|
||||
arch.WithAtime = opts.WithAtime
|
||||
success := true
|
||||
arch.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
arch.Error = func(item string, err error) error {
|
||||
success = false
|
||||
return progressReporter.Error(item, fi, err)
|
||||
return progressReporter.Error(item, err)
|
||||
}
|
||||
arch.CompleteItem = progressReporter.CompleteItem
|
||||
arch.StartFile = progressReporter.StartFile
|
||||
|
@ -27,7 +27,7 @@ type SelectFunc func(item string, fi os.FileInfo) bool
|
||||
// ErrorFunc is called when an error during archiving occurs. When nil is
|
||||
// returned, the archiver continues, otherwise it aborts and passes the error
|
||||
// up the call stack.
|
||||
type ErrorFunc func(file string, fi os.FileInfo, err error) error
|
||||
type ErrorFunc func(file string, err error) error
|
||||
|
||||
// ItemStats collects some statistics about a particular file or directory.
|
||||
type ItemStats struct {
|
||||
@ -157,7 +157,7 @@ func New(repo restic.Repository, fs fs.FS, opts Options) *Archiver {
|
||||
}
|
||||
|
||||
// error calls arch.Error if it is set and the error is different from context.Canceled.
|
||||
func (arch *Archiver) error(item string, fi os.FileInfo, err error) error {
|
||||
func (arch *Archiver) error(item string, err error) error {
|
||||
if arch.Error == nil || err == nil {
|
||||
return err
|
||||
}
|
||||
@ -166,7 +166,7 @@ func (arch *Archiver) error(item string, fi os.FileInfo, err error) error {
|
||||
return err
|
||||
}
|
||||
|
||||
errf := arch.Error(item, fi, err)
|
||||
errf := arch.Error(item, err)
|
||||
if err != errf {
|
||||
debug.Log("item %v: error was filtered by handler, before: %q, after: %v", item, err, errf)
|
||||
}
|
||||
@ -269,7 +269,7 @@ func (arch *Archiver) SaveDir(ctx context.Context, snPath string, fi os.FileInfo
|
||||
|
||||
// return error early if possible
|
||||
if err != nil {
|
||||
err = arch.error(pathname, fi, err)
|
||||
err = arch.error(pathname, err)
|
||||
if err == nil {
|
||||
// ignore error
|
||||
continue
|
||||
@ -294,9 +294,6 @@ func (arch *Archiver) SaveDir(ctx context.Context, snPath string, fi os.FileInfo
|
||||
type FutureNode struct {
|
||||
snPath, target string
|
||||
|
||||
// kept to call the error callback function
|
||||
fi os.FileInfo
|
||||
|
||||
node *restic.Node
|
||||
stats ItemStats
|
||||
err error
|
||||
@ -375,7 +372,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
fi, err := arch.FS.Lstat(target)
|
||||
if err != nil {
|
||||
debug.Log("lstat() for %v returned error: %v", target, err)
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
if err != nil {
|
||||
return FutureNode{}, false, errors.Wrap(err, "Lstat")
|
||||
}
|
||||
@ -412,7 +409,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
debug.Log("%v hasn't changed, but contents are missing!", target)
|
||||
// There are contents missing - inform user!
|
||||
err := errors.Errorf("parts of %v not found in the repository index; storing the file again", target)
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
if err != nil {
|
||||
return FutureNode{}, false, err
|
||||
}
|
||||
@ -423,7 +420,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
file, err := arch.FS.OpenFile(target, fs.O_RDONLY|fs.O_NOFOLLOW, 0)
|
||||
if err != nil {
|
||||
debug.Log("Openfile() for %v returned error: %v", target, err)
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
if err != nil {
|
||||
return FutureNode{}, false, errors.Wrap(err, "Lstat")
|
||||
}
|
||||
@ -434,7 +431,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
if err != nil {
|
||||
debug.Log("stat() on opened file %v returned error: %v", target, err)
|
||||
_ = file.Close()
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
if err != nil {
|
||||
return FutureNode{}, false, errors.Wrap(err, "Lstat")
|
||||
}
|
||||
@ -445,7 +442,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
if !fs.IsRegularFile(fi) {
|
||||
err = errors.Errorf("file %v changed type, refusing to archive")
|
||||
_ = file.Close()
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
if err != nil {
|
||||
return FutureNode{}, false, err
|
||||
}
|
||||
@ -467,7 +464,7 @@ func (arch *Archiver) Save(ctx context.Context, snPath, target string, previous
|
||||
start := time.Now()
|
||||
oldSubtree, err := arch.loadSubtree(ctx, previous)
|
||||
if err != nil {
|
||||
err = arch.error(abstarget, fi, err)
|
||||
err = arch.error(abstarget, err)
|
||||
}
|
||||
if err != nil {
|
||||
return FutureNode{}, false, err
|
||||
@ -576,7 +573,7 @@ func (arch *Archiver) SaveTree(ctx context.Context, snPath string, atree *Tree,
|
||||
fn, excluded, err := arch.Save(ctx, join(snPath, name), subatree.Path, previous.Find(name))
|
||||
|
||||
if err != nil {
|
||||
err = arch.error(subatree.Path, fn.fi, err)
|
||||
err = arch.error(subatree.Path, err)
|
||||
if err == nil {
|
||||
// ignore error
|
||||
continue
|
||||
@ -600,7 +597,7 @@ func (arch *Archiver) SaveTree(ctx context.Context, snPath string, atree *Tree,
|
||||
oldNode := previous.Find(name)
|
||||
oldSubtree, err := arch.loadSubtree(ctx, oldNode)
|
||||
if err != nil {
|
||||
err = arch.error(join(snPath, name), nil, err)
|
||||
err = arch.error(join(snPath, name), err)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -654,7 +651,7 @@ func (arch *Archiver) SaveTree(ctx context.Context, snPath string, atree *Tree,
|
||||
|
||||
// return the error, or ignore it
|
||||
if fn.err != nil {
|
||||
fn.err = arch.error(fn.target, fn.fi, fn.err)
|
||||
fn.err = arch.error(fn.target, fn.err)
|
||||
if fn.err == nil {
|
||||
// ignore error
|
||||
continue
|
||||
@ -762,7 +759,7 @@ func (arch *Archiver) loadParentTree(ctx context.Context, snapshotID restic.ID)
|
||||
tree, err := restic.LoadTree(ctx, arch.Repo, *sn.Tree)
|
||||
if err != nil {
|
||||
debug.Log("unable to load tree %v: %v", *sn.Tree, err)
|
||||
_ = arch.error("/", nil, arch.wrapLoadTreeError(*sn.Tree, err))
|
||||
_ = arch.error("/", arch.wrapLoadTreeError(*sn.Tree, err))
|
||||
return nil
|
||||
}
|
||||
return tree
|
||||
|
@ -47,7 +47,7 @@ func saveFile(t testing.TB, repo restic.Repository, filename string, filesystem
|
||||
arch := New(repo, filesystem, Options{})
|
||||
arch.runWorkers(ctx, wg)
|
||||
|
||||
arch.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
arch.Error = func(item string, err error) error {
|
||||
t.Errorf("archiver error for %v: %v", item, err)
|
||||
return err
|
||||
}
|
||||
@ -217,7 +217,7 @@ func TestArchiverSave(t *testing.T) {
|
||||
repo.StartPackUploader(ctx, wg)
|
||||
|
||||
arch := New(repo, fs.Track{FS: fs.Local{}}, Options{})
|
||||
arch.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
arch.Error = func(item string, err error) error {
|
||||
t.Errorf("archiver error for %v: %v", item, err)
|
||||
return err
|
||||
}
|
||||
@ -295,7 +295,7 @@ func TestArchiverSaveReaderFS(t *testing.T) {
|
||||
}
|
||||
|
||||
arch := New(repo, readerFs, Options{})
|
||||
arch.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
arch.Error = func(item string, err error) error {
|
||||
t.Errorf("archiver error for %v: %v", item, err)
|
||||
return err
|
||||
}
|
||||
@ -1723,7 +1723,7 @@ func TestArchiverParent(t *testing.T) {
|
||||
|
||||
func TestArchiverErrorReporting(t *testing.T) {
|
||||
ignoreErrorForBasename := func(basename string) ErrorFunc {
|
||||
return func(item string, fi os.FileInfo, err error) error {
|
||||
return func(item string, err error) error {
|
||||
if filepath.Base(item) == "targetfile" {
|
||||
t.Logf("ignoring error for targetfile: %v", err)
|
||||
return nil
|
||||
@ -2248,7 +2248,7 @@ func TestRacyFileSwap(t *testing.T) {
|
||||
repo.StartPackUploader(ctx, wg)
|
||||
|
||||
arch := New(repo, fs.Track{FS: statfs}, Options{})
|
||||
arch.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
arch.Error = func(item string, err error) error {
|
||||
t.Logf("archiver error as expected for %v: %v", item, err)
|
||||
return err
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ func NewScanner(fs fs.FS) *Scanner {
|
||||
FS: fs,
|
||||
SelectByName: func(item string) bool { return true },
|
||||
Select: func(item string, fi os.FileInfo) bool { return true },
|
||||
Error: func(item string, fi os.FileInfo, err error) error { return err },
|
||||
Error: func(item string, err error) error { return err },
|
||||
Result: func(item string, s ScanStats) {},
|
||||
}
|
||||
}
|
||||
@ -111,7 +111,7 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
|
||||
// get file information
|
||||
fi, err := s.FS.Lstat(target)
|
||||
if err != nil {
|
||||
return stats, s.Error(target, fi, err)
|
||||
return stats, s.Error(target, err)
|
||||
}
|
||||
|
||||
// run remaining select functions that require file information
|
||||
@ -126,7 +126,7 @@ func (s *Scanner) scan(ctx context.Context, stats ScanStats, target string) (Sca
|
||||
case fi.Mode().IsDir():
|
||||
names, err := readdirnames(s.FS, target, fs.O_NOFOLLOW)
|
||||
if err != nil {
|
||||
return stats, s.Error(target, fi, err)
|
||||
return stats, s.Error(target, err)
|
||||
}
|
||||
sort.Strings(names)
|
||||
|
||||
|
@ -133,7 +133,7 @@ func TestScannerError(t *testing.T) {
|
||||
src TestDir
|
||||
result ScanStats
|
||||
selFn SelectFunc
|
||||
errFn func(t testing.TB, item string, fi os.FileInfo, err error) error
|
||||
errFn func(t testing.TB, item string, err error) error
|
||||
resFn func(t testing.TB, item string, s ScanStats)
|
||||
prepare func(t testing.TB)
|
||||
}{
|
||||
@ -173,7 +173,7 @@ func TestScannerError(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
},
|
||||
errFn: func(t testing.TB, item string, fi os.FileInfo, err error) error {
|
||||
errFn: func(t testing.TB, item string, err error) error {
|
||||
if item == filepath.FromSlash("work/subdir") {
|
||||
return nil
|
||||
}
|
||||
@ -198,7 +198,7 @@ func TestScannerError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
},
|
||||
errFn: func(t testing.TB, item string, fi os.FileInfo, err error) error {
|
||||
errFn: func(t testing.TB, item string, err error) error {
|
||||
if item == "foo" {
|
||||
t.Logf("ignoring error for %v: %v", item, err)
|
||||
return nil
|
||||
@ -257,13 +257,13 @@ func TestScannerError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
if test.errFn != nil {
|
||||
sc.Error = func(item string, fi os.FileInfo, err error) error {
|
||||
sc.Error = func(item string, err error) error {
|
||||
p, relErr := filepath.Rel(cur, item)
|
||||
if relErr != nil {
|
||||
panic(relErr)
|
||||
}
|
||||
|
||||
return test.errFn(t, p, fi, err)
|
||||
return test.errFn(t, p, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ func (s *TreeSaver) save(ctx context.Context, snPath string, node *restic.Node,
|
||||
// return the error if it wasn't ignored
|
||||
if fn.err != nil {
|
||||
debug.Log("err for %v: %v", fn.snPath, fn.err)
|
||||
fn.err = s.errFn(fn.target, fn.fi, fn.err)
|
||||
fn.err = s.errFn(fn.target, fn.err)
|
||||
if fn.err == nil {
|
||||
// ignore error
|
||||
continue
|
||||
|
@ -3,7 +3,6 @@ package archiver
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
@ -23,7 +22,7 @@ func TestTreeSaver(t *testing.T) {
|
||||
return restic.NewRandomID(), ItemStats{TreeBlobs: 1, TreeSize: 123}, nil
|
||||
}
|
||||
|
||||
errFn := func(snPath string, fi os.FileInfo, err error) error {
|
||||
errFn := func(snPath string, err error) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -83,7 +82,7 @@ func TestTreeSaverError(t *testing.T) {
|
||||
return restic.NewRandomID(), ItemStats{TreeBlobs: 1, TreeSize: 123}, nil
|
||||
}
|
||||
|
||||
errFn := func(snPath string, fi os.FileInfo, err error) error {
|
||||
errFn := func(snPath string, err error) error {
|
||||
t.Logf("ignoring error %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package backup
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -79,7 +78,7 @@ func (b *JSONProgress) Update(total, processed Counter, errors uint, currentFile
|
||||
|
||||
// ScannerError is the error callback function for the scanner, it prints the
|
||||
// error in verbose mode and returns nil.
|
||||
func (b *JSONProgress) ScannerError(item string, fi os.FileInfo, err error) error {
|
||||
func (b *JSONProgress) ScannerError(item string, err error) error {
|
||||
b.error(errorUpdate{
|
||||
MessageType: "error",
|
||||
Error: err,
|
||||
@ -90,7 +89,7 @@ func (b *JSONProgress) ScannerError(item string, fi os.FileInfo, err error) erro
|
||||
}
|
||||
|
||||
// Error is the error callback function for the archiver, it prints the error and returns nil.
|
||||
func (b *JSONProgress) Error(item string, fi os.FileInfo, err error) error {
|
||||
func (b *JSONProgress) Error(item string, err error) error {
|
||||
b.error(errorUpdate{
|
||||
MessageType: "error",
|
||||
Error: err,
|
||||
|
@ -3,7 +3,6 @@ package backup
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@ -14,8 +13,8 @@ import (
|
||||
|
||||
type ProgressPrinter interface {
|
||||
Update(total, processed Counter, errors uint, currentFiles map[string]struct{}, start time.Time, secs uint64)
|
||||
Error(item string, fi os.FileInfo, err error) error
|
||||
ScannerError(item string, fi os.FileInfo, err error) error
|
||||
Error(item string, err error) error
|
||||
ScannerError(item string, err error) error
|
||||
CompleteItem(messageType string, item string, previous, current *restic.Node, s archiver.ItemStats, d time.Duration)
|
||||
ReportTotal(item string, start time.Time, s archiver.ScanStats)
|
||||
Finish(snapshotID restic.ID, start time.Time, summary *Summary, dryRun bool)
|
||||
@ -44,11 +43,11 @@ type ProgressReporter interface {
|
||||
CompleteItem(item string, previous, current *restic.Node, s archiver.ItemStats, d time.Duration)
|
||||
StartFile(filename string)
|
||||
CompleteBlob(filename string, bytes uint64)
|
||||
ScannerError(item string, fi os.FileInfo, err error) error
|
||||
ScannerError(item string, err error) error
|
||||
ReportTotal(item string, s archiver.ScanStats)
|
||||
SetMinUpdatePause(d time.Duration)
|
||||
Run(ctx context.Context) error
|
||||
Error(item string, fi os.FileInfo, err error) error
|
||||
Error(item string, err error) error
|
||||
Finish(snapshotID restic.ID)
|
||||
}
|
||||
|
||||
@ -173,13 +172,13 @@ func (p *Progress) Run(ctx context.Context) error {
|
||||
|
||||
// ScannerError is the error callback function for the scanner, it prints the
|
||||
// error in verbose mode and returns nil.
|
||||
func (p *Progress) ScannerError(item string, fi os.FileInfo, err error) error {
|
||||
return p.printer.ScannerError(item, fi, err)
|
||||
func (p *Progress) ScannerError(item string, err error) error {
|
||||
return p.printer.ScannerError(item, err)
|
||||
}
|
||||
|
||||
// Error is the error callback function for the archiver, it prints the error and returns nil.
|
||||
func (p *Progress) Error(item string, fi os.FileInfo, err error) error {
|
||||
cbErr := p.printer.Error(item, fi, err)
|
||||
func (p *Progress) Error(item string, err error) error {
|
||||
cbErr := p.printer.Error(item, err)
|
||||
|
||||
select {
|
||||
case p.errCh <- struct{}{}:
|
||||
|
@ -2,7 +2,6 @@ package backup
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
@ -75,13 +74,13 @@ func (b *TextProgress) Update(total, processed Counter, errors uint, currentFile
|
||||
|
||||
// ScannerError is the error callback function for the scanner, it prints the
|
||||
// error in verbose mode and returns nil.
|
||||
func (b *TextProgress) ScannerError(item string, fi os.FileInfo, err error) error {
|
||||
func (b *TextProgress) ScannerError(item string, err error) error {
|
||||
b.V("scan: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
// Error is the error callback function for the archiver, it prints the error and returns nil.
|
||||
func (b *TextProgress) Error(item string, fi os.FileInfo, err error) error {
|
||||
func (b *TextProgress) Error(item string, err error) error {
|
||||
b.E("error: %v\n", err)
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user