mirror of
https://github.com/kopia/kopia.git
synced 2026-10-23 14:48:53 -04:00
refactor(general): minor miscellaneous cleanups (#4074)
Cleanups: - use non-format variants of Log/Print with no additional args; - fold in Fprintf call with no args into the following one; - add missing arg placeholder in format strings; - use require.Positive instead of Greater(..., 0); - rename function to fillWithZeros to avoid collision with builtin clear; - define type for context key to avoid collisions.
This commit is contained in:
1 parent
6902738e0d
commit
948162dce5
11 files changed
+22
-22
No files matched your search
+4
-5
@@ -96,7 +96,7 @@ func (l *jsonList) begin(o *jsonOutput) {
|
||||
l.o = o
|
||||
|
||||
if o.jsonOutput {
|
||||
fmt.Fprintf(l.o.out, "[") //nolint:errcheck
|
||||
fmt.Fprint(l.o.out, "[") //nolint:errcheck
|
||||
|
||||
if !o.jsonIndent {
|
||||
l.separator = "\n "
|
||||
@@ -107,16 +107,15 @@ func (l *jsonList) begin(o *jsonOutput) {
|
||||
func (l *jsonList) end() {
|
||||
if l.o.jsonOutput {
|
||||
if !l.o.jsonIndent {
|
||||
fmt.Fprintf(l.o.out, "\n") //nolint:errcheck
|
||||
fmt.Fprint(l.o.out, "\n") //nolint:errcheck
|
||||
}
|
||||
|
||||
fmt.Fprintf(l.o.out, "]") //nolint:errcheck
|
||||
fmt.Fprint(l.o.out, "]") //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
func (l *jsonList) emit(v interface{}) {
|
||||
fmt.Fprintf(l.o.out, l.separator) //nolint:errcheck
|
||||
fmt.Fprintf(l.o.out, "%s", l.o.jsonBytes(v)) //nolint:errcheck
|
||||
fmt.Fprintf(l.o.out, "%s%s", l.separator, l.o.jsonBytes(v)) //nolint:errcheck
|
||||
|
||||
if l.o.jsonIndent {
|
||||
l.separator = ","
|
||||
|
||||
@@ -314,7 +314,7 @@ func TestGatherBytesReaderAtVariableInputBufferSizes(t *testing.T) {
|
||||
|
||||
// write the generated data
|
||||
n, err := preWrt.Write(buf)
|
||||
require.NoErrorf(t, err, "Write() faiiled, inputBufferSize: %8", tc.inputBufferSize)
|
||||
require.NoErrorf(t, err, "Write() faiiled, inputBufferSize: %v", tc.inputBufferSize)
|
||||
require.Equalf(t, defaultAllocator.chunkSize, preWrt.alloc.chunkSize,
|
||||
"this test expects that the default-allocator will be used, but we are using: %#v", preWrt.alloc)
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ func TestLogManager_AutoFlush(t *testing.T) {
|
||||
var b [1024]byte
|
||||
|
||||
rand.Read(b[:])
|
||||
l.Infof(hex.EncodeToString(b[:]))
|
||||
l.Info(hex.EncodeToString(b[:]))
|
||||
}
|
||||
|
||||
w.Wait(ctx)
|
||||
|
||||
@@ -748,7 +748,7 @@ func compareMetadata(tb testing.TB, a, b versionMetadata) {
|
||||
// deletion-marker metadata is not returned by the delete blob operation,
|
||||
// and can only be retrieved later by listing versions.
|
||||
if !a.IsDeleteMarker {
|
||||
require.Equalf(tb, a.Version, b.Version, "blob versions do not match a:%v b:v", a, b)
|
||||
require.Equalf(tb, a.Version, b.Version, "blob versions do not match a:%v b:%v", a, b)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -833,7 +833,7 @@ func (bm *WriteManager) WriteContent(ctx context.Context, data gather.Bytes, pre
|
||||
logbuf.AppendInt64(previousWriteTime)
|
||||
}
|
||||
|
||||
bm.log.Debugf(logbuf.String())
|
||||
bm.log.Debug(logbuf.String())
|
||||
|
||||
return contentID, bm.addToPackUnlocked(ctx, contentID, data, false, comp, previousWriteTime, mp)
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ func (sm *SharedManager) preparePackDataContent(mp format.MutableParameters, pp
|
||||
sb.AppendUint32(info.PackedLength)
|
||||
sb.AppendString(" d:")
|
||||
sb.AppendBoolean(info.Deleted)
|
||||
sm.log.Debugf(sb.String())
|
||||
sm.log.Debug(sb.String())
|
||||
|
||||
packFileIndex.Add(info)
|
||||
}
|
||||
|
||||
@@ -179,7 +179,7 @@ func (r *ReedSolomonCrcECC) Encrypt(input gather.Bytes, _ []byte, output *gather
|
||||
|
||||
// WriteBuffer does not clear the data, so we must clear the padding
|
||||
if lengthSize+len(copied) < len(inputBytes) {
|
||||
clear(inputBytes[lengthSize+len(copied):])
|
||||
fillWithZeros(inputBytes[lengthSize+len(copied):])
|
||||
}
|
||||
|
||||
// Compute and store ECC + checksum
|
||||
@@ -261,7 +261,7 @@ func (r *ReedSolomonCrcECC) Decrypt(input gather.Bytes, _ []byte, output *gather
|
||||
|
||||
// WriteBuffer does not clear the data, so we must clear the padding
|
||||
if len(copied) < len(inputBytes) {
|
||||
clear(inputBytes[len(copied):])
|
||||
fillWithZeros(inputBytes[len(copied):])
|
||||
}
|
||||
|
||||
eccBytes := inputBytes[:parityPlusCrcSizeInBlock*sizes.Blocks]
|
||||
|
||||
@@ -34,9 +34,9 @@ func applyPercent(val int, percent float32) int {
|
||||
return int(math.Floor(float64(val) * float64(percent)))
|
||||
}
|
||||
|
||||
func clear(bytes []byte) {
|
||||
for i := range bytes {
|
||||
bytes[i] = 0
|
||||
func fillWithZeros(b []byte) {
|
||||
for i := range b {
|
||||
b[i] = 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -740,7 +740,7 @@ func TestParallelUploadUploadsBlobsInParallel(t *testing.T) {
|
||||
|
||||
require.NoError(t, th.repo.Flush(ctx))
|
||||
|
||||
require.Greater(t, maxParallelCalls.Load(), int32(0))
|
||||
require.Positive(t, maxParallelCalls.Load())
|
||||
}
|
||||
|
||||
func randomBytes(n int64) []byte {
|
||||
|
||||
@@ -218,7 +218,7 @@ func TestConsistencyWhenKill9AfterModify(t *testing.T) {
|
||||
|
||||
o, err := cmd.CombinedOutput()
|
||||
require.NoError(t, err)
|
||||
t.Logf(string(o))
|
||||
t.Log(string(o))
|
||||
|
||||
// create snapshot with StderrPipe
|
||||
cmd = exec.Command(kopiaExe, "snap", "create", newDir, "--json", "--parallel=1")
|
||||
@@ -240,9 +240,8 @@ func TestConsistencyWhenKill9AfterModify(t *testing.T) {
|
||||
stdout, err := bm.RestoreGivenOrRandomSnapshot("", restoreDir)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Logf(stdout)
|
||||
|
||||
t.Logf("Compare restored data and original data:")
|
||||
t.Log(stdout)
|
||||
t.Log("Compare restored data and original data:")
|
||||
CompareDirs(t, restoreDir, cmpDir)
|
||||
}
|
||||
|
||||
@@ -267,7 +266,7 @@ func killOnCondition(t *testing.T, cmd *exec.Cmd) {
|
||||
|
||||
for scanner.Scan() {
|
||||
output := scanner.Text()
|
||||
t.Logf(output)
|
||||
t.Log(output)
|
||||
|
||||
// Check if the output contains the "hashing" etc.
|
||||
if strings.Contains(output, "hashing") && strings.Contains(output, "hashed") && strings.Contains(output, "uploaded") {
|
||||
|
||||
@@ -12,7 +12,9 @@ import (
|
||||
|
||||
const nameLen int = 2
|
||||
|
||||
var clientKey = struct{}{}
|
||||
type clientKeyT struct{}
|
||||
|
||||
var clientKey clientKeyT
|
||||
|
||||
// Client is a unique client for use in multiclient robustness tests.
|
||||
type Client struct {
|
||||
|
||||
Reference in new issue
Block a user