Repository: kopia/kopia
Pull request #4704 (2025-07-01 18:35:52)

chore(general): minor cleanups

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/kopia/kopia/pull/4704?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 76.38%. Comparing base [(`cb455c6`)](https://app.codecov.io/gh/kopia/kopia/commit/cb455c699a04e54cb47e25a676d7d65063ce883e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia) to head [(`6fa7df3`)](https://app.codecov.io/gh/kopia/kopia/commit/6fa7df3e97cc33dd7ba430d9d24ecd2cf9cbe1af?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).
> Report is 591 commits behind head on master.

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4704      +/-   ##
==========================================
+ Coverage   75.86%   76.38%   +0.51%     
==========================================
  Files         470      530      +60     
  Lines       37301    40371    +3070     
==========================================
+ Hits        28299    30838    +2539     
- Misses       7071     7494     +423     
- Partials     1931     2039     +108     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/kopia/kopia/pull/4704?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kopia).

<details><summary> :rocket: New features to boost your workflow: </summary>

- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
julio-lopez: cc: @andrason

Patch:
diff --git a/.gometalinter.json b/.gometalinter.json
deleted file mode 100644
index dea60f4a..00000000
--- a/.gometalinter.json
+++ /dev/null
@@ -1,9 +0,0 @@
-{
-    "Disable": ["maligned","gas","gosec"],
-    "Exclude": [
-        "playground/",
-        ".+\\.pb\\.go",
-        ".+_test\\.go"
-    ],
-    "Deadline": "120s"
-}
\ No newline at end of file
diff --git a/repo/content/committed_content_index.go b/repo/content/committed_content_index.go
index 75b52e85..d479852b 100644
--- a/repo/content/committed_content_index.go
+++ b/repo/content/committed_content_index.go
@@ -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,
 	}
 }
diff --git a/repo/maintenance/drop_deleted_contents.go b/repo/maintenance/drop_deleted_contents.go
index 9bb26ae9..3ed8d4ca 100644
--- a/repo/maintenance/drop_deleted_contents.go
+++ b/repo/maintenance/drop_deleted_contents.go
@@ -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
diff --git a/repo/maintenance/maintenance_run.go b/repo/maintenance/maintenance_run.go
index f2638d67..0a3168c6 100644
--- a/repo/maintenance/maintenance_run.go
+++ b/repo/maintenance/maintenance_run.go
@@ -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)
 	})
 }
 
diff --git a/snapshot/manifest.go b/snapshot/manifest.go
index 5a8d44ba..cb7aff2f 100644
--- a/snapshot/manifest.go
+++ b/snapshot/manifest.go
@@ -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
 	})


Test patch:
diff --git a/internal/repotesting/repotesting_test.go b/internal/repotesting/repotesting_test.go
index 53e6a25e..38d4f693 100644
--- a/internal/repotesting/repotesting_test.go
+++ b/internal/repotesting/repotesting_test.go
@@ -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")
 }