internal/archiver: fixed BackupEnd when SkipIfUnchanged is true

This commit is contained in:
dmotte
2025-09-23 03:07:30 +02:00
parent 93d1e3b211
commit 9017fefddd
2 changed files with 36 additions and 8 deletions

View File

@@ -927,6 +927,7 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps
if opts.ParentSnapshot != nil && opts.SkipIfUnchanged { if opts.ParentSnapshot != nil && opts.SkipIfUnchanged {
ps := opts.ParentSnapshot ps := opts.ParentSnapshot
if ps.Tree != nil && rootTreeID.Equal(*ps.Tree) { if ps.Tree != nil && rootTreeID.Equal(*ps.Tree) {
arch.summary.BackupEnd = time.Now()
return nil, restic.ID{}, arch.summary, nil return nil, restic.ID{}, arch.summary, nil
} }
} }

View File

@@ -1701,6 +1701,7 @@ func TestArchiverParent(t *testing.T) {
var tests = []struct { var tests = []struct {
src TestDir src TestDir
modify func(path string) modify func(path string)
opts SnapshotOptions
statInitial Summary statInitial Summary
statSecond Summary statSecond Summary
}{ }{
@@ -1720,6 +1721,25 @@ func TestArchiverParent(t *testing.T) {
ProcessedBytes: 2102152, ProcessedBytes: 2102152,
}, },
}, },
{
src: TestDir{
"targetfile": TestFile{Content: string(rtest.Random(888, 2*1024*1024+5000))},
},
opts: SnapshotOptions{
SkipIfUnchanged: true,
},
statInitial: Summary{
Files: ChangeStats{1, 0, 0},
Dirs: ChangeStats{0, 0, 0},
ProcessedBytes: 2102152,
ItemStats: ItemStats{3, 0x201593, 0x201632, 1, 0, 0},
},
statSecond: Summary{
Files: ChangeStats{0, 0, 1},
Dirs: ChangeStats{0, 0, 0},
ProcessedBytes: 2102152,
},
},
{ {
src: TestDir{ src: TestDir{
"targetDir": TestDir{ "targetDir": TestDir{
@@ -1782,7 +1802,9 @@ func TestArchiverParent(t *testing.T) {
back := rtest.Chdir(t, tempdir) back := rtest.Chdir(t, tempdir)
defer back() defer back()
firstSnapshot, firstSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, SnapshotOptions{Time: time.Now()}) opts := test.opts
opts.Time = time.Now()
firstSnapshot, firstSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, opts)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@@ -1810,16 +1832,17 @@ func TestArchiverParent(t *testing.T) {
rtest.Equals(t, test.statInitial.Files, summary.Files) rtest.Equals(t, test.statInitial.Files, summary.Files)
rtest.Equals(t, test.statInitial.Dirs, summary.Dirs) rtest.Equals(t, test.statInitial.Dirs, summary.Dirs)
rtest.Equals(t, test.statInitial.ProcessedBytes, summary.ProcessedBytes) rtest.Equals(t, test.statInitial.ProcessedBytes, summary.ProcessedBytes)
rtest.Assert(t, summary.BackupStart.Before(summary.BackupEnd), "BackupStart %v is not before BackupEnd %v", summary.BackupStart, summary.BackupEnd)
checkSnapshotStats(t, firstSnapshot, test.statInitial) checkSnapshotStats(t, firstSnapshot, test.statInitial)
if test.modify != nil { if test.modify != nil {
test.modify(tempdir) test.modify(tempdir)
} }
opts := SnapshotOptions{ opts = test.opts
Time: time.Now(), opts.Time = time.Now()
ParentSnapshot: firstSnapshot, opts.ParentSnapshot = firstSnapshot
}
testFS.bytesRead = map[string]int{} testFS.bytesRead = map[string]int{}
secondSnapshot, secondSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, opts) secondSnapshot, secondSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, opts)
if err != nil { if err != nil {
@@ -1833,10 +1856,14 @@ func TestArchiverParent(t *testing.T) {
rtest.Equals(t, test.statSecond.Files, summary.Files) rtest.Equals(t, test.statSecond.Files, summary.Files)
rtest.Equals(t, test.statSecond.Dirs, summary.Dirs) rtest.Equals(t, test.statSecond.Dirs, summary.Dirs)
rtest.Equals(t, test.statSecond.ProcessedBytes, summary.ProcessedBytes) rtest.Equals(t, test.statSecond.ProcessedBytes, summary.ProcessedBytes)
rtest.Assert(t, summary.BackupStart.Before(summary.BackupEnd), "BackupStart %v is not before BackupEnd %v", summary.BackupStart, summary.BackupEnd)
if secondSnapshot != nil {
checkSnapshotStats(t, secondSnapshot, test.statSecond) checkSnapshotStats(t, secondSnapshot, test.statSecond)
t.Logf("second backup saved as %v", secondSnapshotID.Str()) t.Logf("second backup saved as %v", secondSnapshotID.Str())
t.Logf("testfs: %v", testFS) t.Logf("testfs: %v", testFS)
}
checker.TestCheckRepo(t, repo, false) checker.TestCheckRepo(t, repo, false)
}) })