From 5e7333d28dc20d51103cc620a4d74428177bda64 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Mar 2025 09:57:59 +0000 Subject: [PATCH 1/5] Unify repository receiver name. --- internal/repository/warmup.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/repository/warmup.go b/internal/repository/warmup.go index 7d96185a7..eca46692a 100644 --- a/internal/repository/warmup.go +++ b/internal/repository/warmup.go @@ -23,7 +23,7 @@ func (job *WarmupJob) Wait(ctx context.Context) error { } // StartWarmup creates a new warmup job, requesting the backend to warmup the specified packs. -func (repo *Repository) StartWarmup(ctx context.Context, packs restic.IDSet) (restic.WarmupJob, error) { +func (r *Repository) StartWarmup(ctx context.Context, packs restic.IDSet) (restic.WarmupJob, error) { handles := make([]backend.Handle, 0, len(packs)) for pack := range packs { handles = append( @@ -31,9 +31,9 @@ func (repo *Repository) StartWarmup(ctx context.Context, packs restic.IDSet) (re backend.Handle{Type: restic.PackFile, Name: pack.String()}, ) } - handlesWarmingUp, err := repo.be.Warmup(ctx, handles) + handlesWarmingUp, err := r.be.Warmup(ctx, handles) return &WarmupJob{ - repo: repo, + repo: r, handlesWarmingUp: handlesWarmingUp, }, err } From 6e45c5150921675bb728ed6680aa41825dd8effa Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Mar 2025 10:01:19 +0000 Subject: [PATCH 2/5] Fix name including package name and variable shadowing package. --- cmd/restic/cmd_repair_index_integration_test.go | 6 +++--- internal/repository/index/index.go | 16 ++++++++-------- internal/repository/index/index_internal_test.go | 4 ++-- internal/repository/index/master_index.go | 8 ++++---- internal/repository/index/master_index_test.go | 12 ++++++------ internal/repository/repository_test.go | 2 +- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/cmd/restic/cmd_repair_index_integration_test.go b/cmd/restic/cmd_repair_index_integration_test.go index 9bfc93b40..2b76bf4b3 100644 --- a/cmd/restic/cmd_repair_index_integration_test.go +++ b/cmd/restic/cmd_repair_index_integration_test.go @@ -64,11 +64,11 @@ func TestRebuildIndex(t *testing.T) { } func TestRebuildIndexAlwaysFull(t *testing.T) { - indexFull := index.IndexFull + indexFull := index.Full defer func() { - index.IndexFull = indexFull + index.Full = indexFull }() - index.IndexFull = func(*index.Index) bool { return true } + index.Full = func(*index.Index) bool { return true } testRebuildIndex(t, nil) } diff --git a/internal/repository/index/index.go b/internal/repository/index/index.go index 5a80a3c10..5729a689c 100644 --- a/internal/repository/index/index.go +++ b/internal/repository/index/index.go @@ -93,8 +93,8 @@ const ( indexMaxAge = 10 * time.Minute ) -// IndexFull returns true iff the index is "full enough" to be saved as a preliminary index. -var IndexFull = func(idx *Index) bool { +// Full returns true iff the index is "full enough" to be saved as a preliminary index. +var Full = func(idx *Index) bool { idx.m.RLock() defer idx.m.RUnlock() @@ -119,7 +119,7 @@ var IndexFull = func(idx *Index) bool { return false } -var IndexOversized = func(idx *Index) bool { +var Oversized = func(idx *Index) bool { idx.m.RLock() defer idx.m.RUnlock() @@ -258,8 +258,8 @@ func (idx *Index) EachByPack(ctx context.Context, packBlacklist restic.IDSet) <- for packID, packByType := range byPack { var result EachByPackResult result.PackID = packID - for typ, pack := range packByType { - for _, e := range pack { + for typ, p := range packByType { + for _, e := range p { result.Blobs = append(result.Blobs, idx.toPackedBlob(e, restic.BlobType(typ)).Blob) } } @@ -511,10 +511,10 @@ func DecodeIndex(buf []byte, id restic.ID) (idx *Index, err error) { } idx = NewIndex() - for _, pack := range idxJSON.Packs { - packID := idx.addToPacks(pack.ID) + for _, p := range idxJSON.Packs { + packID := idx.addToPacks(p.ID) - for _, blob := range pack.Blobs { + for _, blob := range p.Blobs { idx.store(packID, restic.Blob{ BlobHandle: restic.BlobHandle{ Type: blob.Type, diff --git a/internal/repository/index/index_internal_test.go b/internal/repository/index/index_internal_test.go index f55c9f546..67591ef8a 100644 --- a/internal/repository/index/index_internal_test.go +++ b/internal/repository/index/index_internal_test.go @@ -24,7 +24,7 @@ func TestIndexOversized(t *testing.T) { }) } - rtest.Assert(t, !IndexOversized(idx), "index should not be considered oversized") + rtest.Assert(t, !Oversized(idx), "index should not be considered oversized") // Add one more blob to exceed the limit idx.store(packID, restic.Blob{ @@ -36,5 +36,5 @@ func TestIndexOversized(t *testing.T) { Offset: uint(indexMaxBlobs+pack.MaxHeaderEntries) * 100, }) - rtest.Assert(t, IndexOversized(idx), "index should be considered oversized") + rtest.Assert(t, Oversized(idx), "index should be considered oversized") } diff --git a/internal/repository/index/master_index.go b/internal/repository/index/master_index.go index 2a2f4988b..a41119b58 100644 --- a/internal/repository/index/master_index.go +++ b/internal/repository/index/master_index.go @@ -211,7 +211,7 @@ func (mi *MasterIndex) finalizeFullIndexes() []*Index { continue } - if IndexFull(idx) { + if Full(idx) { debug.Log("index %p is full", idx) idx.Finalize() list = append(list, idx) @@ -419,7 +419,7 @@ func (mi *MasterIndex) Rewrite(ctx context.Context, repo restic.Unpacked[restic. newIndex := NewIndex() for task := range rewriteCh { // always rewrite indexes that include a pack that must be removed or that are not full - if len(task.idx.Packs().Intersect(excludePacks)) == 0 && IndexFull(task.idx) && !IndexOversized(task.idx) { + if len(task.idx.Packs().Intersect(excludePacks)) == 0 && Full(task.idx) && !Oversized(task.idx) { // make sure that each pack is only stored exactly once in the index excludePacks.Merge(task.idx.Packs()) // index is already up to date @@ -435,7 +435,7 @@ func (mi *MasterIndex) Rewrite(ctx context.Context, repo restic.Unpacked[restic. for pbs := range task.idx.EachByPack(wgCtx, excludePacks) { newIndex.StorePack(pbs.PackID, pbs.Blobs) - if IndexFull(newIndex) { + if Full(newIndex) { select { case saveCh <- newIndex: case <-wgCtx.Done(): @@ -532,7 +532,7 @@ func (mi *MasterIndex) SaveFallback(ctx context.Context, repo restic.SaverRemove for pbs := range idx.EachByPack(wgCtx, excludePacks) { newIndex.StorePack(pbs.PackID, pbs.Blobs) p.Add(1) - if IndexFull(newIndex) { + if Full(newIndex) { select { case ch <- newIndex: case <-wgCtx.Done(): diff --git a/internal/repository/index/master_index_test.go b/internal/repository/index/master_index_test.go index ac7beb84f..063af862d 100644 --- a/internal/repository/index/master_index_test.go +++ b/internal/repository/index/master_index_test.go @@ -466,16 +466,16 @@ func TestRewriteOversizedIndex(t *testing.T) { const fullIndexCount = 1000 // replace index size checks for testing - originalIndexFull := index.IndexFull - originalIndexOversized := index.IndexOversized + originalIndexFull := index.Full + originalIndexOversized := index.Oversized defer func() { - index.IndexFull = originalIndexFull - index.IndexOversized = originalIndexOversized + index.Full = originalIndexFull + index.Oversized = originalIndexOversized }() - index.IndexFull = func(idx *index.Index) bool { + index.Full = func(idx *index.Index) bool { return idx.Len(restic.DataBlob) > fullIndexCount } - index.IndexOversized = func(idx *index.Index) bool { + index.Oversized = func(idx *index.Index) bool { return idx.Len(restic.DataBlob) > 2*fullIndexCount } diff --git a/internal/repository/repository_test.go b/internal/repository/repository_test.go index 1b0d47c8f..0ce1eab14 100644 --- a/internal/repository/repository_test.go +++ b/internal/repository/repository_test.go @@ -333,7 +333,7 @@ func TestRepositoryIncrementalIndex(t *testing.T) { func testRepositoryIncrementalIndex(t *testing.T, version uint) { repo, _, _ := repository.TestRepositoryWithVersion(t, version) - index.IndexFull = func(*index.Index) bool { return true } + index.Full = func(*index.Index) bool { return true } // add a few rounds of packs for j := 0; j < 5; j++ { From a389977bd7d1ef8c22a2e41b49a987915591b299 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Mar 2025 10:05:13 +0000 Subject: [PATCH 3/5] Remove redudnant error check, handled above. --- internal/archiver/archiver.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/internal/archiver/archiver.go b/internal/archiver/archiver.go index 0b71cbacf..4a6577d27 100644 --- a/internal/archiver/archiver.go +++ b/internal/archiver/archiver.go @@ -695,10 +695,6 @@ func (arch *Archiver) saveTree(ctx context.Context, snPath string, atree *tree, return futureNode{}, 0, err } - if err != nil { - return futureNode{}, 0, err - } - if !excluded { nodes = append(nodes, fn) } From 4420fde3788888a3b4c686e55c86ee821a5ab5f7 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Mar 2025 10:10:54 +0000 Subject: [PATCH 4/5] Remove deprecated HTTP option that is now the default. --- internal/backend/http_transport.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/backend/http_transport.go b/internal/backend/http_transport.go index 5a3856e41..4e0bb6594 100644 --- a/internal/backend/http_transport.go +++ b/internal/backend/http_transport.go @@ -80,7 +80,6 @@ func Transport(opts TransportOptions) (http.RoundTripper, error) { DialContext: (&net.Dialer{ Timeout: 30 * time.Second, KeepAlive: 30 * time.Second, - DualStack: true, }).DialContext, MaxIdleConns: 100, MaxIdleConnsPerHost: 100, From 6caad10840abb6442e8a023acadedea8c1510c96 Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Sun, 23 Mar 2025 10:11:43 +0000 Subject: [PATCH 5/5] Remove extra brackets. --- cmd/restic/global.go | 2 +- internal/repository/prune.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/restic/global.go b/cmd/restic/global.go index 22b09390c..4d2ea75d5 100644 --- a/cmd/restic/global.go +++ b/cmd/restic/global.go @@ -302,7 +302,7 @@ func resolvePassword(opts *GlobalOptions, envStr string) (string, error) { if err != nil { return "", err } - return (strings.TrimSpace(string(output))), nil + return strings.TrimSpace(string(output)), nil } if opts.PasswordFile != "" { return loadPasswordFromFile(opts.PasswordFile) diff --git a/internal/repository/prune.go b/internal/repository/prune.go index e22dd4c20..9726a6032 100644 --- a/internal/repository/prune.go +++ b/internal/repository/prune.go @@ -276,7 +276,7 @@ func packInfoFromIndex(ctx context.Context, idx restic.ListBlobser, usedBlobs *i ip := indexPack[blob.PackID] size := uint64(blob.Length) switch { - case ip.usedBlobs > 0, (ip.duplicateBlobs == ip.unusedBlobs), count == 0: + case ip.usedBlobs > 0, ip.duplicateBlobs == ip.unusedBlobs, count == 0: // other used blobs in pack, only duplicate blobs or "last" occurrence -> transition to used // a pack file created by an interrupted prune run will consist of only duplicate blobs // thus select such already repacked pack files