archiver: remove fs parameter from fileChanged function

This commit is contained in:
Michael Eischer 2024-11-16 16:53:34 +01:00
parent 641390103d
commit 847b2efba2
2 changed files with 10 additions and 9 deletions

View file

@ -510,7 +510,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous
// check if the file has not changed before performing a fopen operation (more expensive, specially // check if the file has not changed before performing a fopen operation (more expensive, specially
// in network filesystems) // in network filesystems)
if previous != nil && !fileChanged(arch.FS, fi, previous, arch.ChangeIgnoreFlags) { if previous != nil && !fileChanged(fi, previous, arch.ChangeIgnoreFlags) {
if arch.allBlobsPresent(previous) { if arch.allBlobsPresent(previous) {
debug.Log("%v hasn't changed, using old list of blobs", target) debug.Log("%v hasn't changed, using old list of blobs", target)
arch.trackItem(snPath, previous, previous, ItemStats{}, time.Since(start)) arch.trackItem(snPath, previous, previous, ItemStats{}, time.Since(start))
@ -618,7 +618,7 @@ func (arch *Archiver) save(ctx context.Context, snPath, target string, previous
// fileChanged tries to detect whether a file's content has changed compared // fileChanged tries to detect whether a file's content has changed compared
// to the contents of node, which describes the same path in the parent backup. // to the contents of node, which describes the same path in the parent backup.
// It should only be run for regular files. // It should only be run for regular files.
func fileChanged(fs fs.FS, fi *fs.ExtendedFileInfo, node *restic.Node, ignoreFlags uint) bool { func fileChanged(fi *fs.ExtendedFileInfo, node *restic.Node, ignoreFlags uint) bool {
switch { switch {
case node == nil: case node == nil:
return true return true

View file

@ -683,10 +683,11 @@ func TestFileChanged(t *testing.T) {
save(t, filename, content) save(t, filename, content)
fs := &fs.Local{} fs := &fs.Local{}
fiBefore := lstat(t, filename) fiBefore, err := fs.Lstat(filename)
rtest.OK(t, err)
node := nodeFromFile(t, fs, filename) node := nodeFromFile(t, fs, filename)
if fileChanged(fs, fiBefore, node, 0) { if fileChanged(fiBefore, node, 0) {
t.Fatalf("unchanged file detected as changed") t.Fatalf("unchanged file detected as changed")
} }
@ -696,12 +697,12 @@ func TestFileChanged(t *testing.T) {
if test.SameFile { if test.SameFile {
// file should be detected as unchanged // file should be detected as unchanged
if fileChanged(fs, fiAfter, node, test.ChangeIgnore) { if fileChanged(fiAfter, node, test.ChangeIgnore) {
t.Fatalf("unmodified file detected as changed") t.Fatalf("unmodified file detected as changed")
} }
} else { } else {
// file should be detected as changed // file should be detected as changed
if !fileChanged(fs, fiAfter, node, test.ChangeIgnore) && !test.SameFile { if !fileChanged(fiAfter, node, test.ChangeIgnore) && !test.SameFile {
t.Fatalf("modified file detected as unchanged") t.Fatalf("modified file detected as unchanged")
} }
} }
@ -718,7 +719,7 @@ func TestFilChangedSpecialCases(t *testing.T) {
t.Run("nil-node", func(t *testing.T) { t.Run("nil-node", func(t *testing.T) {
fi := lstat(t, filename) fi := lstat(t, filename)
if !fileChanged(&fs.Local{}, fi, nil, 0) { if !fileChanged(fi, nil, 0) {
t.Fatal("nil node detected as unchanged") t.Fatal("nil node detected as unchanged")
} }
}) })
@ -727,7 +728,7 @@ func TestFilChangedSpecialCases(t *testing.T) {
fi := lstat(t, filename) fi := lstat(t, filename)
node := nodeFromFile(t, &fs.Local{}, filename) node := nodeFromFile(t, &fs.Local{}, filename)
node.Type = restic.NodeTypeSymlink node.Type = restic.NodeTypeSymlink
if !fileChanged(&fs.Local{}, fi, node, 0) { if !fileChanged(fi, node, 0) {
t.Fatal("node with changed type detected as unchanged") t.Fatal("node with changed type detected as unchanged")
} }
}) })
@ -2304,7 +2305,7 @@ func TestMetadataChanged(t *testing.T) {
// modify the mode by wrapping it in a new struct, uses the consts defined above // modify the mode by wrapping it in a new struct, uses the consts defined above
fs.overrideFI = wrapFileInfo(fi) fs.overrideFI = wrapFileInfo(fi)
rtest.Assert(t, !fileChanged(fs, fs.overrideFI, node2, 0), "testfile must not be considered as changed") rtest.Assert(t, !fileChanged(fs.overrideFI, node2, 0), "testfile must not be considered as changed")
// set the override values in the 'want' node which // set the override values in the 'want' node which
want.Mode = 0400 want.Mode = 0400