mirror of
https://github.com/restic/restic.git
synced 2025-03-29 16:42:13 +00:00
Merge pull request #5299 from Martin2112/go_cleanup
A few more small cleanups that should not change behaviour.
This commit is contained in:
commit
9aad8e9ea5
@ -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)
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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():
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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++ {
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user