From bb20d9e11a23488cd44d9630243990098d484a26 Mon Sep 17 00:00:00 2001 From: Julio Lopez <1953782+julio-lopez@users.noreply.github.com> Date: Wed, 12 Nov 2025 23:12:06 -0800 Subject: [PATCH] chore(ci): enable `wsl_v5:{assign,expr}` linter settings (#4982) Enable wsl_v5 settings: - assign - expr --- .golangci.yml | 3 --- cli/app.go | 1 + cli/command_content_verify.go | 1 + cli/command_policy_edit.go | 1 + cli/command_snapshot_list_test.go | 2 ++ cli/command_snapshot_migrate.go | 1 + cli/command_snapshot_pin_test.go | 1 + cli/config.go | 1 + internal/contentlog/contentlog_json_writer.go | 1 + internal/contentlog/contentlog_logger_test.go | 16 ++++++++++++++++ internal/diff/diff.go | 1 + internal/diff/diff_test.go | 2 ++ internal/gather/gather_write_buffer.go | 1 + internal/hmac/hmac.go | 1 + internal/iocopy/iocopy_test.go | 1 + internal/metrics/metrics_counter_test.go | 1 + .../metrics_duration_distribution_test.go | 2 ++ internal/parallelwork/parallel_work_queue.go | 1 + internal/server/grpc_session.go | 1 + internal/server/server.go | 1 + internal/sleepable/sleepable_timer_test.go | 1 + repo/blob/azure/azure_versioned_test.go | 8 ++++++-- repo/blob/gcs/gcs_versioned_test.go | 8 +++++--- repo/blob/rclone/rclone_storage.go | 1 + repo/blob/s3/s3_versioned_test.go | 2 ++ .../blob/throttling/throttling_semaphore_test.go | 1 + repo/content/content_manager_test.go | 8 ++++++++ repo/content/index/index_v1.go | 1 + repo/content/index/merged_test.go | 1 + repo/ecc/ecc_rs_crc.go | 6 ++++++ .../aes256_gcm_hmac_sha256_encryptor.go | 2 ++ .../chacha20_poly1305_hmac_sha256_encryptor.go | 1 + repo/encryption/encryption_test.go | 1 + repo/maintenance/maintenance_safety_test.go | 1 + repo/manifest/committed_manifest_manager.go | 2 ++ repo/manifest/manifest_manager_test.go | 1 + repo/object/object_writer.go | 1 + repo/open.go | 1 + repo/repository_test.go | 1 + snapshot/upload/upload_estimator_test.go | 1 + snapshot/upload/upload_test.go | 1 + tests/end_to_end_test/restore_test.go | 1 + tests/end_to_end_test/server_start_test.go | 2 ++ tests/end_to_end_test/shallowrestore_test.go | 1 + tests/end_to_end_test/snapshot_actions_test.go | 1 + tests/end_to_end_test/snapshot_create_test.go | 4 +++- .../multiclient_test/framework/harness.go | 1 + tests/robustness/pathlock/path_lock_test.go | 1 + .../socketactivation_test.go | 1 + 49 files changed, 93 insertions(+), 9 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 1ba25cf53..eb61dbc94 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -82,9 +82,6 @@ linters: locale: US wsl_v5: allow-whole-block: true - disable: - - assign - - expr default: all disable: diff --git a/cli/app.go b/cli/app.go index 7d2e319c0..54bd41ef2 100644 --- a/cli/app.go +++ b/cli/app.go @@ -260,6 +260,7 @@ func (c *App) setup(app *kingpin.Application) { _ = app.Flag("help-full", "Show help for all commands, including hidden").Action(func(pc *kingpin.ParseContext) error { _ = app.UsageForContextWithTemplate(pc, 0, kingpin.DefaultUsageTemplate) + c.exitWithError(nil) return nil diff --git a/cli/command_content_verify.go b/cli/command_content_verify.go index 3cb1d3e2e..d820d2d41 100644 --- a/cli/command_content_verify.go +++ b/cli/command_content_verify.go @@ -55,6 +55,7 @@ func (c *commandContentVerify) run(ctx context.Context, rep repo.DirectRepositor go func() { defer wg.Done() + c.getTotalContentCount(subctx, rep, &totalCount) }() diff --git a/cli/command_policy_edit.go b/cli/command_policy_edit.go index 61b04f1bd..6d2bf344d 100644 --- a/cli/command_policy_edit.go +++ b/cli/command_policy_edit.go @@ -119,6 +119,7 @@ func (c *commandPolicyEdit) run(ctx context.Context, rep repo.RepositoryWriter) func prettyJSON(v *policy.Policy) string { var b bytes.Buffer + e := json.NewEncoder(&b) e.SetIndent("", " ") e.Encode(v) //nolint:errcheck,errchkjson diff --git a/cli/command_snapshot_list_test.go b/cli/command_snapshot_list_test.go index 8d906064f..851834be7 100644 --- a/cli/command_snapshot_list_test.go +++ b/cli/command_snapshot_list_test.go @@ -19,6 +19,7 @@ func TestSnapshotList(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) srcdir := testutil.TempDirectory(t) @@ -86,6 +87,7 @@ func TestSnapshotListWithSameFileInMultipleSnapshots(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) srcdir := testutil.TempDirectory(t) diff --git a/cli/command_snapshot_migrate.go b/cli/command_snapshot_migrate.go index 9183cebb2..28c51c8f7 100644 --- a/cli/command_snapshot_migrate.go +++ b/cli/command_snapshot_migrate.go @@ -109,6 +109,7 @@ func (c *commandSnapshotMigrate) run(ctx context.Context, destRepo repo.Reposito uploader := upload.NewUploader(destRepo) uploader.Progress = c.svc.getProgress() activeUploaders[s] = uploader + mu.Unlock() wg.Add(1) diff --git a/cli/command_snapshot_pin_test.go b/cli/command_snapshot_pin_test.go index 38bf778ff..d80b5782a 100644 --- a/cli/command_snapshot_pin_test.go +++ b/cli/command_snapshot_pin_test.go @@ -20,6 +20,7 @@ func TestSnapshotPin(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) srcdir := testutil.TempDirectory(t) diff --git a/cli/config.go b/cli/config.go index 24471340d..f3ca28b5a 100644 --- a/cli/config.go +++ b/cli/config.go @@ -34,6 +34,7 @@ func (c *App) onTerminate(f func()) { case <-s: } + f() }() } diff --git a/internal/contentlog/contentlog_json_writer.go b/internal/contentlog/contentlog_json_writer.go index a02a784d7..54bf5cad4 100644 --- a/internal/contentlog/contentlog_json_writer.go +++ b/internal/contentlog/contentlog_json_writer.go @@ -302,6 +302,7 @@ func (jw *JSONWriter) TimeField(key string, value time.Time) { // appendPaddedInt appends an integer with zero-padding to the buffer. func (jw *JSONWriter) appendPaddedInt(value int64, width int) { var numBuf [64]byte + numStr := strconv.AppendInt(numBuf[:0], value, decimal) numLen := len(numStr) diff --git a/internal/contentlog/contentlog_logger_test.go b/internal/contentlog/contentlog_logger_test.go index d69e4ae9b..b97447c60 100644 --- a/internal/contentlog/contentlog_logger_test.go +++ b/internal/contentlog/contentlog_logger_test.go @@ -62,6 +62,7 @@ func TestLog(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "test message", logEntry["m"]) @@ -88,6 +89,7 @@ func TestLog(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "test message", logEntry["m"]) @@ -126,6 +128,7 @@ func TestLog1(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -165,6 +168,7 @@ func TestLog1(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, tc.message, logEntry["m"]) @@ -192,6 +196,7 @@ func TestLog2(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -219,6 +224,7 @@ func TestLog3(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -248,6 +254,7 @@ func TestLog4(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -279,6 +286,7 @@ func TestLog5(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -312,6 +320,7 @@ func TestLog6(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "processing item", logEntry["m"]) @@ -345,6 +354,7 @@ func TestEmit(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "custom entry", logEntry["message"]) @@ -377,6 +387,7 @@ func TestEmit(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "custom entry", logEntry["message"]) @@ -424,12 +435,14 @@ func TestLoggerMultipleLogs(t *testing.T) { // Check first entry var entry1 map[string]any + err := json.Unmarshal([]byte(lines[0]), &entry1) require.NoError(t, err) require.Equal(t, "first message", entry1["m"]) // Check second entry var entry2 map[string]any + err = json.Unmarshal([]byte(lines[1]), &entry2) require.NoError(t, err) require.Equal(t, "second message", entry2["m"]) @@ -437,6 +450,7 @@ func TestLoggerMultipleLogs(t *testing.T) { // Check third entry var entry3 map[string]any + err = json.Unmarshal([]byte(lines[2]), &entry3) require.NoError(t, err) require.Equal(t, "third message", entry3["m"]) @@ -461,6 +475,7 @@ func TestLoggerErrorHandling(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "error test", logEntry["m"]) @@ -483,6 +498,7 @@ func TestLoggerErrorHandling(t *testing.T) { require.NotEmpty(t, captured) var logEntry map[string]any + err := json.Unmarshal(captured, &logEntry) require.NoError(t, err) require.Equal(t, "error test", logEntry["m"]) diff --git a/internal/diff/diff.go b/internal/diff/diff.go index 1b9f7bcb9..5e81af984 100644 --- a/internal/diff/diff.go +++ b/internal/diff/diff.go @@ -357,6 +357,7 @@ func (c *Comparer) compareFiles(ctx context.Context, f1, f2 fs.File, fname strin } var args []string + args = append(args, c.DiffArguments...) args = append(args, oldName, newName) diff --git a/internal/diff/diff_test.go b/internal/diff/diff_test.go index 66bd7d1d8..7d76bc55b 100644 --- a/internal/diff/diff_test.go +++ b/internal/diff/diff_test.go @@ -550,11 +550,13 @@ func TestGetTwoLatestSnapshots(t *testing.T) { intermediateSnapshotManifestID := mustSaveSnapshot(t, env.RepositoryWriter, manifests["intermediate_snapshot"]) var expectedManifestIDs []manifest.ID + expectedManifestIDs = append(expectedManifestIDs, initialSnapshotManifestID, intermediateSnapshotManifestID) secondLastSnapshot, lastSnapshot, err := diff.GetTwoLatestSnapshotsForASource(ctx, env.RepositoryWriter, snapshotSrc) var gotManifestIDs []manifest.ID + gotManifestIDs = append(gotManifestIDs, secondLastSnapshot.ID, lastSnapshot.ID) require.NoError(t, err) diff --git a/internal/gather/gather_write_buffer.go b/internal/gather/gather_write_buffer.go index 2bafc72f5..ea5e9b70d 100644 --- a/internal/gather/gather_write_buffer.go +++ b/internal/gather/gather_write_buffer.go @@ -161,6 +161,7 @@ func (b *WriteBuffer) Dup() *WriteBuffer { b.mu.Lock() defer b.mu.Unlock() + dup.alloc = b.alloc dup.inner = FromSlice(b.inner.ToByteSlice()) diff --git a/internal/hmac/hmac.go b/internal/hmac/hmac.go index 6bfd022db..087c1fc05 100644 --- a/internal/hmac/hmac.go +++ b/internal/hmac/hmac.go @@ -39,6 +39,7 @@ func VerifyAndStrip(input gather.Bytes, secret []byte, output *gather.WriteBuffe } var sigBuf, actualSignature [sha256.Size]byte + validSignature := h.Sum(sigBuf[:0]) n, err := r.Read(actualSignature[:]) diff --git a/internal/iocopy/iocopy_test.go b/internal/iocopy/iocopy_test.go index c880e98af..5d13fc85a 100644 --- a/internal/iocopy/iocopy_test.go +++ b/internal/iocopy/iocopy_test.go @@ -31,6 +31,7 @@ func TestGetBuffer(t *testing.T) { func TestReleaseBuffer(t *testing.T) { buf := iocopy.GetBuffer() iocopy.ReleaseBuffer(buf) + buf2 := iocopy.GetBuffer() require.Equal(t, &buf[0], &buf2[0], "Buffer was not recycled after ReleaseBuffer") } diff --git a/internal/metrics/metrics_counter_test.go b/internal/metrics/metrics_counter_test.go index 3f1b2f550..df69d928b 100644 --- a/internal/metrics/metrics_counter_test.go +++ b/internal/metrics/metrics_counter_test.go @@ -11,6 +11,7 @@ func TestCounter_Nil(t *testing.T) { var e *metrics.Registry + cnt := e.CounterInt64("aaa", "bbb", nil) require.Nil(t, cnt) cnt.Add(33) diff --git a/internal/metrics/metrics_duration_distribution_test.go b/internal/metrics/metrics_duration_distribution_test.go index 5d7e687b6..85f47f240 100644 --- a/internal/metrics/metrics_duration_distribution_test.go +++ b/internal/metrics/metrics_duration_distribution_test.go @@ -12,6 +12,7 @@ func TestDurationDistribution_Nil(t *testing.T) { var e *metrics.Registry + dist := e.DurationDistribution("aaa", "bbb", metrics.IOLatencyThresholds, nil) require.Nil(t, dist) dist.Observe(time.Second) @@ -20,6 +21,7 @@ func TestDurationDistribution_Nil(t *testing.T) { func TestSizeDistribution_Nil(t *testing.T) { var e *metrics.Registry + cnt := e.SizeDistribution("aaa", "bbb", metrics.ISOBytesThresholds, nil) require.Nil(t, cnt) cnt.Observe(333) diff --git a/internal/parallelwork/parallel_work_queue.go b/internal/parallelwork/parallel_work_queue.go index 2a91f39b7..3a220e20b 100644 --- a/internal/parallelwork/parallel_work_queue.go +++ b/internal/parallelwork/parallel_work_queue.go @@ -154,6 +154,7 @@ func OnNthCompletion(n int, callback CallbackFunc) CallbackFunc { n-- call := n == 0 + mu.Unlock() if call { diff --git a/internal/server/grpc_session.go b/internal/server/grpc_session.go index bcb6f79d9..9be16e9fd 100644 --- a/internal/server/grpc_session.go +++ b/internal/server/grpc_session.go @@ -167,6 +167,7 @@ func (s *Server) Session(srv grpcapi.KopiaRepository_SessionServer) error { func (s *Server) handleSessionRequest(ctx context.Context, dw repo.DirectRepositoryWriter, authz auth.AuthorizationInfo, usernameAtHostname string, req *grpcapi.SessionRequest, respond func(*grpcapi.SessionResponse)) { if req.GetTraceContext() != nil { var tc propagation.TraceContext + ctx = tc.Extract(ctx, propagation.MapCarrier(req.GetTraceContext())) } diff --git a/internal/server/server.go b/internal/server/server.go index 3e33742a3..cb9b75fc5 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -976,6 +976,7 @@ func (s *Server) runSnapshotTask(ctx context.Context, src snapshot.SourceInfo, i } var result notifydata.ManifestWithError + result.Manifest.Source = src defer s.endUpload(ctx, src, &result) diff --git a/internal/sleepable/sleepable_timer_test.go b/internal/sleepable/sleepable_timer_test.go index 7c4eb10e6..bbafdf1f2 100644 --- a/internal/sleepable/sleepable_timer_test.go +++ b/internal/sleepable/sleepable_timer_test.go @@ -134,6 +134,7 @@ func TestTimerConcurrentStop(t *testing.T) { go func() { defer wg.Done() + timer.Stop() }() } diff --git a/repo/blob/azure/azure_versioned_test.go b/repo/blob/azure/azure_versioned_test.go index e6fe6ea30..9dd703f37 100644 --- a/repo/blob/azure/azure_versioned_test.go +++ b/repo/blob/azure/azure_versioned_test.go @@ -103,11 +103,12 @@ func TestGetBlobVersions(t *testing.T) { latestData = "latest version" ) - dataBlobs := []string{originalData, updatedData, latestData} - const blobName = "TestGetBlobVersions" + blobID := blob.ID(blobName) + dataBlobs := []string{originalData, updatedData, latestData} dataTimestamps, err := putBlobs(ctx, st, blobID, dataBlobs) + require.NoError(t, err) pastPIT := dataTimestamps[0].Add(-1 * time.Second) @@ -162,6 +163,7 @@ func TestGetBlobVersions(t *testing.T) { require.NoError(t, err) var tmp gather.WriteBuffer + err = st.GetBlob(ctx, blobID, 0, -1, &tmp) require.ErrorIs(t, err, tt.expectedError) require.Equal(t, tt.expectedBlobData, string(tmp.ToByteSlice())) @@ -212,6 +214,7 @@ func TestGetBlobVersionsWithDeletion(t *testing.T) { dataBlobs := []string{originalData, updatedData} const blobName = "TestGetBlobVersionsWithDeletion" + blobID := blob.ID(blobName) dataTimestamps, err := putBlobs(ctx, st, blobID, dataBlobs) require.NoError(t, err) @@ -235,6 +238,7 @@ func TestGetBlobVersionsWithDeletion(t *testing.T) { require.Equal(t, 1, count) var tmp gather.WriteBuffer + err = st.GetBlob(ctx, blobID, 0, -1, &tmp) require.NoError(t, err) require.Equal(t, updatedData, string(tmp.ToByteSlice())) diff --git a/repo/blob/gcs/gcs_versioned_test.go b/repo/blob/gcs/gcs_versioned_test.go index f30349284..0378c22c2 100644 --- a/repo/blob/gcs/gcs_versioned_test.go +++ b/repo/blob/gcs/gcs_versioned_test.go @@ -105,6 +105,7 @@ func TestGetBlobVersions(t *testing.T) { dataBlobs := []string{originalData, updatedData, latestData} const blobName = "TestGetBlobVersions" + blobID := blob.ID(blobName) dataTimestamps, err := putBlobs(ctx, st, blobID, dataBlobs) require.NoError(t, err) @@ -161,6 +162,7 @@ func TestGetBlobVersions(t *testing.T) { require.NoError(t, err) var tmp gather.WriteBuffer + err = st.GetBlob(ctx, blobID, 0, -1, &tmp) require.ErrorIs(t, err, tt.expectedError) require.Equal(t, tt.expectedBlobData, string(tmp.ToByteSlice())) @@ -206,12 +208,11 @@ func TestGetBlobVersionsWithDeletion(t *testing.T) { const ( originalData = "original" updatedData = "some update" + blobName = "TestGetBlobVersionsWithDeletion" ) - dataBlobs := []string{originalData, updatedData} - - const blobName = "TestGetBlobVersionsWithDeletion" blobID := blob.ID(blobName) + dataBlobs := []string{originalData, updatedData} dataTimestamps, err := putBlobs(ctx, st, blobID, dataBlobs) require.NoError(t, err) @@ -234,6 +235,7 @@ func TestGetBlobVersionsWithDeletion(t *testing.T) { require.Equal(t, 1, count) var tmp gather.WriteBuffer + err = st.GetBlob(ctx, blobID, 0, -1, &tmp) require.NoError(t, err) require.Equal(t, updatedData, string(tmp.ToByteSlice())) diff --git a/repo/blob/rclone/rclone_storage.go b/repo/blob/rclone/rclone_storage.go index def876aa8..4136abf72 100644 --- a/repo/blob/rclone/rclone_storage.go +++ b/repo/blob/rclone/rclone_storage.go @@ -361,6 +361,7 @@ func New(ctx context.Context, opt *Options, isCreate bool) (blob.Storage, error) fingerprintHexString := hex.EncodeToString(fingerprintBytes[:]) var cli http.Client + cli.Transport = &http.Transport{ TLSClientConfig: tlsutil.TLSConfigTrustingSingleCertificate(fingerprintHexString), } diff --git a/repo/blob/s3/s3_versioned_test.go b/repo/blob/s3/s3_versioned_test.go index 77fcd0634..208b1a175 100644 --- a/repo/blob/s3/s3_versioned_test.go +++ b/repo/blob/s3/s3_versioned_test.go @@ -663,7 +663,9 @@ func randLongHex(tb testing.TB, length int) string { b := make([]byte, byteLength) rMu.Lock() + n, err := r.Read(b) + rMu.Unlock() require.NoError(tb, err) diff --git a/repo/blob/throttling/throttling_semaphore_test.go b/repo/blob/throttling/throttling_semaphore_test.go index 6f61f3f99..ca3cd3563 100644 --- a/repo/blob/throttling/throttling_semaphore_test.go +++ b/repo/blob/throttling/throttling_semaphore_test.go @@ -50,6 +50,7 @@ func TestThrottlingSemaphore(t *testing.T) { mu.Lock() concurrency-- + mu.Unlock() s.Release() diff --git a/repo/content/content_manager_test.go b/repo/content/content_manager_test.go index 62ce58b17..d19f8f74a 100644 --- a/repo/content/content_manager_test.go +++ b/repo/content/content_manager_test.go @@ -85,6 +85,7 @@ func (s *contentManagerSuite) TestContentManagerEmptyFlush(t *testing.T) { bm := s.newTestContentManager(t, st) defer bm.CloseShared(ctx) + bm.Flush(ctx) if got, want := len(data), 0; got != want { @@ -99,6 +100,7 @@ func (s *contentManagerSuite) TestContentZeroBytes1(t *testing.T) { bm := s.newTestContentManager(t, st) defer bm.CloseShared(ctx) + contentID := writeContentAndVerify(ctx, t, bm, []byte{}) bm.Flush(ctx) @@ -1054,6 +1056,7 @@ func (s *contentManagerSuite) TestParallelWrites(t *testing.T) { workerLock.RLock() workerWritten[workerID] = append(workerWritten[workerID], id) + workerLock.RUnlock() } }() @@ -1118,6 +1121,7 @@ func (s *contentManagerSuite) TestFlushResumesWriters(t *testing.T) { bm := s.newTestContentManagerWithTweaks(t, fs, nil) defer bm.CloseShared(ctx) + first := writeContentAndVerify(ctx, t, bm, []byte{1, 2, 3}) var second ID @@ -1641,7 +1645,9 @@ func (s *contentManagerSuite) TestIterateContents(t *testing.T) { } mu.Lock() + got[ci.ContentID] = true + mu.Unlock() return nil @@ -1977,6 +1983,7 @@ func (s *contentManagerSuite) verifyVersionCompat(t *testing.T, writeVersion for // now open one more manager mgr = s.newTestContentManager(t, st) defer mgr.CloseShared(ctx) + verifyContentManagerDataSet(ctx, t, mgr, dataSet) } @@ -2211,6 +2218,7 @@ func (s *contentManagerSuite) TestPrefetchContent(t *testing.T) { }) defer bm.CloseShared(ctx) + bm.Flush(ctx) // write 6 x 6 MB content in 2 blobs. diff --git a/repo/content/index/index_v1.go b/repo/content/index/index_v1.go index 1f117062e..fa3ef3c81 100644 --- a/repo/content/index/index_v1.go +++ b/repo/content/index/index_v1.go @@ -92,6 +92,7 @@ func (b *indexV1) entryToInfoStruct(contentID ID, data []byte, result *Info) err result.Deleted = data[12]&0x80 != 0 //nolint:mnd const packOffsetMask = 1<<31 - 1 + result.PackOffset = decodeBigEndianUint32(data[12:]) & packOffsetMask result.PackedLength = decodeBigEndianUint32(data[16:]) result.OriginalLength = result.PackedLength - b.v1PerContentOverhead diff --git a/repo/content/index/merged_test.go b/repo/content/index/merged_test.go index 609980cf8..d4bf407e6 100644 --- a/repo/content/index/merged_test.go +++ b/repo/content/index/merged_test.go @@ -166,6 +166,7 @@ func TestMergedGetInfoError(t *testing.T) { m := Merged{failingIndex{nil, someError}} var info Info + ok, err := m.GetInfo(mustParseID(t, "xabcdef"), &info) require.ErrorIs(t, err, someError) require.False(t, ok) diff --git a/repo/ecc/ecc_rs_crc.go b/repo/ecc/ecc_rs_crc.go index da57ce52a..430eea63a 100644 --- a/repo/ecc/ecc_rs_crc.go +++ b/repo/ecc/ecc_rs_crc.go @@ -172,6 +172,7 @@ func (r *ReedSolomonCrcECC) Encrypt(input gather.Bytes, _ []byte, output *gather // Allocate space for the input + padding var inputBuffer gather.WriteBuffer defer inputBuffer.Close() + inputBytes := inputBuffer.MakeContiguous(dataSizeInBlock * sizes.Blocks) binary.BigEndian.PutUint32(inputBytes[:lengthSize], uint32(input.Length())) //nolint:gosec @@ -185,13 +186,16 @@ func (r *ReedSolomonCrcECC) Encrypt(input gather.Bytes, _ []byte, output *gather // Compute and store ECC + checksum var crcBuffer [crcSize]byte + crcBytes := crcBuffer[:] var eccBuffer gather.WriteBuffer defer eccBuffer.Close() + eccBytes := eccBuffer.MakeContiguous(paritySizeInBlock) var maxShards [256][]byte + shards := maxShards[:sizes.DataShards+sizes.ParityShards] inputPos := 0 @@ -255,6 +259,7 @@ func (r *ReedSolomonCrcECC) Decrypt(input gather.Bytes, _ []byte, output *gather // Allocate space for the input + padding var inputBuffer gather.WriteBuffer defer inputBuffer.Close() + inputBytes := inputBuffer.MakeContiguous((dataPlusCrcSizeInBlock + parityPlusCrcSizeInBlock) * sizes.Blocks) copied := input.AppendToSlice(inputBytes[:0]) @@ -268,6 +273,7 @@ func (r *ReedSolomonCrcECC) Decrypt(input gather.Bytes, _ []byte, output *gather dataBytes := inputBytes[parityPlusCrcSizeInBlock*sizes.Blocks:] var maxShards [256][]byte + shards := maxShards[:sizes.DataShards+sizes.ParityShards] dataPos := 0 diff --git a/repo/encryption/aes256_gcm_hmac_sha256_encryptor.go b/repo/encryption/aes256_gcm_hmac_sha256_encryptor.go index 42fc8a561..15a5a7b8e 100644 --- a/repo/encryption/aes256_gcm_hmac_sha256_encryptor.go +++ b/repo/encryption/aes256_gcm_hmac_sha256_encryptor.go @@ -26,6 +26,7 @@ func (e aes256GCMHmacSha256) aeadForContent(contentID []byte) (cipher.AEAD, erro //nolint:forcetypeassert h := e.hmacPool.Get().(hash.Hash) defer e.hmacPool.Put(h) + h.Reset() if _, err := h.Write(contentID); err != nil { @@ -33,6 +34,7 @@ func (e aes256GCMHmacSha256) aeadForContent(contentID []byte) (cipher.AEAD, erro } var hashBuf [32]byte + key := h.Sum(hashBuf[:0]) c, err := aes.NewCipher(key) diff --git a/repo/encryption/chacha20_poly1305_hmac_sha256_encryptor.go b/repo/encryption/chacha20_poly1305_hmac_sha256_encryptor.go index b56852df7..6bb6ce744 100644 --- a/repo/encryption/chacha20_poly1305_hmac_sha256_encryptor.go +++ b/repo/encryption/chacha20_poly1305_hmac_sha256_encryptor.go @@ -34,6 +34,7 @@ func (e chacha20poly1305hmacSha256Encryptor) aeadForContent(contentID []byte) (c } var hashBuf [32]byte + key := h.Sum(hashBuf[:0]) //nolint:wrapcheck diff --git a/repo/encryption/encryption_test.go b/repo/encryption/encryption_test.go index 0cd69bbe7..68e8314c1 100644 --- a/repo/encryption/encryption_test.go +++ b/repo/encryption/encryption_test.go @@ -144,6 +144,7 @@ func verifyCiphertextSamples(t *testing.T, masterKey, contentID, payload []byte, func() { var v gather.WriteBuffer defer v.Close() + require.NoError(t, enc.Encrypt(gather.FromSlice(payload), contentID, &v)) t.Errorf("missing ciphertext sample for %q: %q,", encryptionAlgo, hex.EncodeToString(payload)) diff --git a/repo/maintenance/maintenance_safety_test.go b/repo/maintenance/maintenance_safety_test.go index 05256c7f2..31929dcea 100644 --- a/repo/maintenance/maintenance_safety_test.go +++ b/repo/maintenance/maintenance_safety_test.go @@ -38,6 +38,7 @@ func (s *formatSpecificTestSuite) TestMaintenanceSafety(t *testing.T) { fmt.Fprintf(ow, "hello world") var err error + objectID, err = ow.Result() return err diff --git a/repo/manifest/committed_manifest_manager.go b/repo/manifest/committed_manifest_manager.go index b8eab50df..662de6a2c 100644 --- a/repo/manifest/committed_manifest_manager.go +++ b/repo/manifest/committed_manifest_manager.go @@ -164,7 +164,9 @@ func (m *committedManifestManager) loadCommittedContentsLocked(ctx context.Conte } mu.Lock() + manifests[ci.ContentID] = man + mu.Unlock() return nil diff --git a/repo/manifest/manifest_manager_test.go b/repo/manifest/manifest_manager_test.go index bbc1bfc90..69dbac114 100644 --- a/repo/manifest/manifest_manager_test.go +++ b/repo/manifest/manifest_manager_test.go @@ -208,6 +208,7 @@ func TestManifestInitCorruptedBlock(t *testing.T) { }{ {"GetRaw", func() error { var raw json.RawMessage + _, err := mgr.Get(ctx, "anything", &raw) return err diff --git a/repo/object/object_writer.go b/repo/object/object_writer.go index 1d60009fc..52f6dc879 100644 --- a/repo/object/object_writer.go +++ b/repo/object/object_writer.go @@ -159,6 +159,7 @@ func (w *objectWriter) flushBufferLocked() error { // acquire write semaphore w.asyncWritesSemaphore <- struct{}{} + w.asyncWritesWG.Add(1) asyncBuf := gather.NewWriteBuffer() diff --git a/repo/open.go b/repo/open.go index ecd22a0f3..df5043d2e 100644 --- a/repo/open.go +++ b/repo/open.go @@ -467,6 +467,7 @@ func upgradeLockMonitor( m.RUnlock() return nil } + m.RUnlock() // upgrade the lock and verify again in-case someone else won the race to refresh diff --git a/repo/repository_test.go b/repo/repository_test.go index 984722425..834ed7558 100644 --- a/repo/repository_test.go +++ b/repo/repository_test.go @@ -550,6 +550,7 @@ func TestInitializeWithNoRetention(t *testing.T) { // are not supplied. var b gather.WriteBuffer defer b.Close() + require.NoError(t, env.RepositoryWriter.BlobStorage().GetBlob(ctx, format.KopiaBlobCfgBlobID, 0, -1, &b)) } diff --git a/snapshot/upload/upload_estimator_test.go b/snapshot/upload/upload_estimator_test.go index 5eb31decc..b723edffb 100644 --- a/snapshot/upload/upload_estimator_test.go +++ b/snapshot/upload/upload_estimator_test.go @@ -88,6 +88,7 @@ func expectSuccessfulEstimation( done := make(chan struct{}) go func() { defer close(done) + estimator.StartEstimation(ctx, func(fc, ts int64) { filesCount = fc totalFileSize = ts diff --git a/snapshot/upload/upload_test.go b/snapshot/upload/upload_test.go index 73c81b98d..5e1491b3b 100644 --- a/snapshot/upload/upload_test.go +++ b/snapshot/upload/upload_test.go @@ -1109,6 +1109,7 @@ func (w *mockLogger) Write(p []byte) (int, error) { parts := strings.SplitN(strings.TrimSpace(string(p)), "\t", 2) var la loggedAction + la.msg = parts[0] if len(parts) == 2 { diff --git a/tests/end_to_end_test/restore_test.go b/tests/end_to_end_test/restore_test.go index 8e6d4dc9f..b5a58c91d 100644 --- a/tests/end_to_end_test/restore_test.go +++ b/tests/end_to_end_test/restore_test.go @@ -944,6 +944,7 @@ func TestRestoreByPathWithoutTarget(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) srcdir := testutil.TempDirectory(t) diff --git a/tests/end_to_end_test/server_start_test.go b/tests/end_to_end_test/server_start_test.go index b1f62e556..1cdb7fe02 100644 --- a/tests/end_to_end_test/server_start_test.go +++ b/tests/end_to_end_test/server_start_test.go @@ -147,6 +147,7 @@ func TestServerStart(t *testing.T) { // make sure root payload is valid JSON for the directory. var dummy map[string]any + err = json.Unmarshal(rootPayload, &dummy) require.NoError(t, err) @@ -442,6 +443,7 @@ func TestServerScheduling(t *testing.T) { emptyDir2 := testutil.TempDirectory(t) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir, "--override-hostname=fake-hostname", "--override-username=fake-username") e.RunAndExpectSuccess(t, "snapshot", "create", emptyDir1) diff --git a/tests/end_to_end_test/shallowrestore_test.go b/tests/end_to_end_test/shallowrestore_test.go index c663b3ddb..516b76bbb 100644 --- a/tests/end_to_end_test/shallowrestore_test.go +++ b/tests/end_to_end_test/shallowrestore_test.go @@ -786,6 +786,7 @@ func getShallowInfo(t *testing.T, srp string) (string, os.FileInfo) { t.Helper() const ENTRYTYPES = 3 + shallowinfos := make([]os.FileInfo, ENTRYTYPES) errors := make([]error, ENTRYTYPES) paths := make([]string, ENTRYTYPES) diff --git a/tests/end_to_end_test/snapshot_actions_test.go b/tests/end_to_end_test/snapshot_actions_test.go index 2b69a8915..2420cada2 100644 --- a/tests/end_to_end_test/snapshot_actions_test.go +++ b/tests/end_to_end_test/snapshot_actions_test.go @@ -383,6 +383,7 @@ func mustReadEnvFile(t *testing.T, fname string) map[string]string { verifyNoError(t, err) defer f.Close() + s := bufio.NewScanner(f) m := map[string]string{} diff --git a/tests/end_to_end_test/snapshot_create_test.go b/tests/end_to_end_test/snapshot_create_test.go index 08a00ceca..968325dfd 100644 --- a/tests/end_to_end_test/snapshot_create_test.go +++ b/tests/end_to_end_test/snapshot_create_test.go @@ -515,6 +515,7 @@ func TestSnapshotCreateWithIgnore(t *testing.T) { } defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) e.RunAndExpectSuccess(t, "snapshot", "create", baseDir) sources := clitestutil.ListSnapshotsAndExpectSuccess(t, e) @@ -557,8 +558,8 @@ func TestSnapshotCreateAllWithManualSnapshot(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") - e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir1) e.RunAndExpectSuccess(t, "snapshot", "create", sharedTestDataDir2) @@ -585,6 +586,7 @@ func TestSnapshotCreateWithStdinStream(t *testing.T) { e := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, runner) defer e.RunAndExpectSuccess(t, "repo", "disconnect") + e.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", e.RepoDir) // Create a temporary pipe file with test data diff --git a/tests/robustness/multiclient_test/framework/harness.go b/tests/robustness/multiclient_test/framework/harness.go index 214ea928b..605a8d8b8 100644 --- a/tests/robustness/multiclient_test/framework/harness.go +++ b/tests/robustness/multiclient_test/framework/harness.go @@ -302,6 +302,7 @@ func (th *TestHarness) GetDirsToLog(ctx context.Context) []string { } var dirList []string + dirList = append(dirList, th.dataRepoPath, // repo under test base dir th.metaRepoPath, // metadata repository base dir diff --git a/tests/robustness/pathlock/path_lock_test.go b/tests/robustness/pathlock/path_lock_test.go index 214c2b505..7db7aed2b 100644 --- a/tests/robustness/pathlock/path_lock_test.go +++ b/tests/robustness/pathlock/path_lock_test.go @@ -303,6 +303,7 @@ func TestPathLockRace(t *testing.T) { } counter++ + lock.Unlock() }() } diff --git a/tests/socketactivation_test/socketactivation_test.go b/tests/socketactivation_test/socketactivation_test.go index aace34475..71cde0c8e 100644 --- a/tests/socketactivation_test/socketactivation_test.go +++ b/tests/socketactivation_test/socketactivation_test.go @@ -153,6 +153,7 @@ func TestServerControlSocketActivatedTooManyFDs(t *testing.T) { l2File.Close() serverStarted <- stderr + close(serverStarted) }()