mirror of
https://github.com/kopia/kopia.git
synced 2025-12-23 22:57:50 -05:00
chore(general): minor cleanups (#4704)
- use `slices.Clone` - remove stale `.gometalinter.json` - unexport `maintenance.dropDeletedContents` - rename `fetchIndexBlob` - use `require` in `TestTimeFuncWiring`
This commit is contained in:
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"Disable": ["maligned","gas","gosec"],
|
||||
"Exclude": [
|
||||
"playground/",
|
||||
".+\\.pb\\.go",
|
||||
".+_test\\.go"
|
||||
],
|
||||
"Deadline": "120s"
|
||||
}
|
||||
@@ -24,9 +24,7 @@ func TestTimeFuncWiring(t *testing.T) {
|
||||
|
||||
// Re open with injected time
|
||||
rep, err := repo.Open(ctx, env.RepositoryWriter.ConfigFilename(), env.Password, &repo.Options{TimeNowFunc: ft.NowFunc()})
|
||||
if err != nil {
|
||||
t.Fatal("Failed to open repo:", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to open test repository")
|
||||
|
||||
r0 := testutil.EnsureType[repo.DirectRepository](t, rep)
|
||||
|
||||
@@ -34,30 +32,22 @@ func TestTimeFuncWiring(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify wiring for the repo layer
|
||||
if got, want := env.RepositoryWriter.Time(), ft.NowFunc()(); !got.Equal(want) {
|
||||
t.Errorf("times don't match, got %v, want %v", got, want)
|
||||
}
|
||||
got, want := env.RepositoryWriter.Time(), ft.NowFunc()()
|
||||
require.WithinDuration(t, want, got, 0, "times do not match")
|
||||
|
||||
if want, got := ft.Advance(10*time.Minute), env.RepositoryWriter.Time(); !got.Equal(want) {
|
||||
t.Errorf("times don't match, got %v, want %v", got, want)
|
||||
}
|
||||
want, got = ft.Advance(10*time.Minute), env.RepositoryWriter.Time()
|
||||
require.WithinDuration(t, want, got, 0, "times do not match")
|
||||
|
||||
// verify wiring for the content layer
|
||||
nt := ft.Advance(20 * time.Second)
|
||||
|
||||
cid, err := env.RepositoryWriter.ContentManager().WriteContent(ctx, gather.FromSlice([]byte("foo")), "", content.NoCompression)
|
||||
if err != nil {
|
||||
t.Fatal("failed to write content:", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to write content")
|
||||
|
||||
info, err := env.RepositoryWriter.ContentInfo(ctx, cid)
|
||||
if err != nil {
|
||||
t.Fatal("failed to get content info for", cid, err)
|
||||
}
|
||||
|
||||
if got, want := info.Timestamp(), nt; !got.Equal(want) {
|
||||
t.Errorf("content time does not match, got %v, want %v", got, want)
|
||||
}
|
||||
require.NoErrorf(t, err, "failed to get content info for %s", cid)
|
||||
require.WithinDuration(t, nt, info.Timestamp(), 0, "content time does not match")
|
||||
|
||||
// verify wiring for the manifest layer
|
||||
nt = ft.Advance(3 * time.Minute)
|
||||
@@ -65,18 +55,12 @@ func TestTimeFuncWiring(t *testing.T) {
|
||||
labels := map[string]string{"l1": "v1", "l2": "v2", "type": "my-manifest"}
|
||||
|
||||
mid, err := env.RepositoryWriter.PutManifest(ctx, labels, "manifest content")
|
||||
if err != nil {
|
||||
t.Fatal("failed to put manifest:", err)
|
||||
}
|
||||
require.NoError(t, err, "failed to put manifest")
|
||||
|
||||
meta, err := env.RepositoryWriter.GetManifest(ctx, mid, nil)
|
||||
if err != nil {
|
||||
t.Fatal("failed to get manifest metadata:", err)
|
||||
}
|
||||
|
||||
if got, want := meta.ModTime, nt; !got.Equal(want) {
|
||||
t.Errorf("manifest time does not match, got %v, want %v", got, want)
|
||||
}
|
||||
require.NoError(t, err, "failed to get manifest metadata")
|
||||
require.WithinDuration(t, nt, meta.ModTime, 0, "manifest modification time does not match")
|
||||
|
||||
const defaultPermissions = 0o777
|
||||
|
||||
@@ -89,11 +73,7 @@ func TestTimeFuncWiring(t *testing.T) {
|
||||
policyTree := policy.BuildTree(nil, policy.DefaultPolicy)
|
||||
|
||||
s1, err := u.Upload(ctx, sourceDir, policyTree, snapshot.SourceInfo{})
|
||||
if err != nil {
|
||||
t.Fatal("failed to create snapshot:", err)
|
||||
}
|
||||
|
||||
if got, want := nt, s1.StartTime.ToTime(); !got.Equal(want) {
|
||||
t.Fatalf("snapshot time does not match, got: %v, want: %v", got, want)
|
||||
}
|
||||
require.NoError(t, err, "failed to create snapshot")
|
||||
require.WithinDuration(t, nt, s1.StartTime.ToTime(), 0, "snapshot time does not match")
|
||||
}
|
||||
|
||||
@@ -42,8 +42,8 @@ type committedContentIndex struct {
|
||||
v1PerContentOverhead func() int
|
||||
formatProvider format.Provider
|
||||
|
||||
// fetchOne loads one index blob
|
||||
fetchOne func(ctx context.Context, blobID blob.ID, output *gather.WriteBuffer) error
|
||||
// fetchIndexBlob retrieves one index blob from storage
|
||||
fetchIndexBlob func(ctx context.Context, blobID blob.ID, output *gather.WriteBuffer) error
|
||||
|
||||
log logging.Logger
|
||||
}
|
||||
@@ -321,7 +321,7 @@ func (c *committedContentIndex) fetchIndexBlobs(ctx context.Context, isPermissiv
|
||||
for indexBlobID := range ch {
|
||||
data.Reset()
|
||||
|
||||
if err := c.fetchOne(ctx, indexBlobID, &data); err != nil {
|
||||
if err := c.fetchIndexBlob(ctx, indexBlobID, &data); err != nil {
|
||||
if isPermissiveCacheLoading {
|
||||
c.log.Errorf("skipping bad read of index blob %v", indexBlobID)
|
||||
continue
|
||||
@@ -371,7 +371,7 @@ func newCommittedContentIndex(caching *CachingOptions,
|
||||
v1PerContentOverhead func() int,
|
||||
formatProvider format.Provider,
|
||||
permissiveCacheLoading bool,
|
||||
fetchOne func(ctx context.Context, blobID blob.ID, output *gather.WriteBuffer) error,
|
||||
fetchIndexBlob func(ctx context.Context, blobID blob.ID, output *gather.WriteBuffer) error,
|
||||
log logging.Logger,
|
||||
minSweepAge time.Duration,
|
||||
) *committedContentIndex {
|
||||
@@ -393,7 +393,7 @@ func newCommittedContentIndex(caching *CachingOptions,
|
||||
inUse: map[blob.ID]index.Index{},
|
||||
v1PerContentOverhead: v1PerContentOverhead,
|
||||
formatProvider: formatProvider,
|
||||
fetchOne: fetchOne,
|
||||
fetchIndexBlob: fetchIndexBlob,
|
||||
log: log,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
"github.com/kopia/kopia/repo/content/indexblob"
|
||||
)
|
||||
|
||||
// DropDeletedContents rewrites indexes while dropping deleted contents above certain age.
|
||||
func DropDeletedContents(ctx context.Context, rep repo.DirectRepositoryWriter, dropDeletedBefore time.Time, safety SafetyParameters) error {
|
||||
// dropDeletedContents rewrites indexes while dropping deleted contents above certain age.
|
||||
func dropDeletedContents(ctx context.Context, rep repo.DirectRepositoryWriter, dropDeletedBefore time.Time, safety SafetyParameters) error {
|
||||
log(ctx).Infof("Dropping contents deleted before %v", dropDeletedBefore)
|
||||
|
||||
//nolint:wrapcheck
|
||||
|
||||
@@ -418,7 +418,7 @@ func runTaskDropDeletedContentsFull(ctx context.Context, runParams RunParameters
|
||||
log(ctx).Infof("Found safe time to drop indexes: %v", safeDropTime)
|
||||
|
||||
return ReportRun(ctx, runParams.rep, TaskDropDeletedContentsFull, s, func() error {
|
||||
return DropDeletedContents(ctx, runParams.rep, safeDropTime, safety)
|
||||
return dropDeletedContents(ctx, runParams.rep, safeDropTime, safety)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
@@ -238,7 +239,7 @@ func GroupBySource(manifests []*Manifest) [][]*Manifest {
|
||||
|
||||
// SortByTime returns a slice of manifests sorted by start time.
|
||||
func SortByTime(manifests []*Manifest, reverse bool) []*Manifest {
|
||||
result := append([]*Manifest(nil), manifests...)
|
||||
result := slices.Clone(manifests)
|
||||
sort.Slice(result, func(i, j int) bool {
|
||||
return result[i].StartTime > result[j].StartTime == reverse
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user