From 9017fefdddba050ee99a4bbae06267687558cd58 Mon Sep 17 00:00:00 2001 From: dmotte <37443982+dmotte@users.noreply.github.com> Date: Tue, 23 Sep 2025 03:07:30 +0200 Subject: [PATCH] internal/archiver: fixed BackupEnd when SkipIfUnchanged is true --- internal/archiver/archiver.go | 1 + internal/archiver/archiver_test.go | 43 ++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 981b1fecc..95facb16f 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -927,6 +927,7 @@ func (arch *Archiver) Snapshot(ctx context.Context, targets []string, opts Snaps if opts.ParentSnapshot != nil && opts.SkipIfUnchanged { ps := opts.ParentSnapshot if ps.Tree != nil && rootTreeID.Equal(*ps.Tree) { + arch.summary.BackupEnd = time.Now() return nil, restic.ID{}, arch.summary, nil } } diff --git a/internal/archiver/archiver_test.go b/internal/archiver/archiver_test.go index 18f8c7d52..b0f338092 100644 --- a/internal/archiver/archiver_test.go +++ b/internal/archiver/archiver_test.go @@ -1701,6 +1701,7 @@ func TestArchiverParent(t *testing.T) { var tests = []struct { src TestDir modify func(path string) + opts SnapshotOptions statInitial Summary statSecond Summary }{ @@ -1720,6 +1721,25 @@ func TestArchiverParent(t *testing.T) { 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{ "targetDir": TestDir{ @@ -1782,7 +1802,9 @@ func TestArchiverParent(t *testing.T) { back := rtest.Chdir(t, tempdir) 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 { 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.Dirs, summary.Dirs) 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) if test.modify != nil { test.modify(tempdir) } - opts := SnapshotOptions{ - Time: time.Now(), - ParentSnapshot: firstSnapshot, - } + opts = test.opts + opts.Time = time.Now() + opts.ParentSnapshot = firstSnapshot testFS.bytesRead = map[string]int{} secondSnapshot, secondSnapshotID, summary, err := arch.Snapshot(ctx, []string{"."}, opts) 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.Dirs, summary.Dirs) rtest.Equals(t, test.statSecond.ProcessedBytes, summary.ProcessedBytes) - checkSnapshotStats(t, secondSnapshot, test.statSecond) + rtest.Assert(t, summary.BackupStart.Before(summary.BackupEnd), "BackupStart %v is not before BackupEnd %v", summary.BackupStart, summary.BackupEnd) - t.Logf("second backup saved as %v", secondSnapshotID.Str()) - t.Logf("testfs: %v", testFS) + if secondSnapshot != nil { + checkSnapshotStats(t, secondSnapshot, test.statSecond) + + t.Logf("second backup saved as %v", secondSnapshotID.Str()) + t.Logf("testfs: %v", testFS) + } checker.TestCheckRepo(t, repo, false) })