浏览代码

chore(internal): linter complaints

Jakob Borg 4 月之前
父节点
当前提交
e25de22705
共有 4 个文件被更改,包括 8 次插入4 次删除
  1. 1 0
      .golangci.yml
  2. 1 0
      internal/db/metrics.go
  3. 2 2
      internal/db/typed.go
  4. 4 2
      internal/protoutil/protoutil.go

+ 1 - 0
.golangci.yml

@@ -51,6 +51,7 @@ linters:
       - std-error-handling
       - std-error-handling
     paths:
     paths:
       - internal/gen
       - internal/gen
+      - internal/db/olddb
       - cmd/dev
       - cmd/dev
       - repos
       - repos
       - third_party$
       - third_party$

+ 1 - 0
internal/db/metrics.go

@@ -21,6 +21,7 @@ var (
 		Namespace: "syncthing",
 		Namespace: "syncthing",
 		Subsystem: "db",
 		Subsystem: "db",
 		Name:      "operations_current",
 		Name:      "operations_current",
+		Help:      "Number of database operations currently ongoing, per folder and operation",
 	}, []string{"folder", "operation"})
 	}, []string{"folder", "operation"})
 	metricTotalOperationSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
 	metricTotalOperationSeconds = promauto.NewCounterVec(prometheus.CounterOpts{
 		Namespace: "syncthing",
 		Namespace: "syncthing",

+ 2 - 2
internal/db/typed.go

@@ -37,7 +37,7 @@ func NewTyped(db KV, prefix string) *Typed {
 // is overwritten.
 // is overwritten.
 func (n *Typed) PutInt64(key string, val int64) error {
 func (n *Typed) PutInt64(key string, val int64) error {
 	var valBs [8]byte
 	var valBs [8]byte
-	binary.BigEndian.PutUint64(valBs[:], uint64(val))
+	binary.BigEndian.PutUint64(valBs[:], uint64(val)) //nolint:gosec
 	return n.db.PutKV(n.prefixedKey(key), valBs[:])
 	return n.db.PutKV(n.prefixedKey(key), valBs[:])
 }
 }
 
 
@@ -49,7 +49,7 @@ func (n *Typed) Int64(key string) (int64, bool, error) {
 		return 0, false, filterNotFound(err)
 		return 0, false, filterNotFound(err)
 	}
 	}
 	val := binary.BigEndian.Uint64(valBs)
 	val := binary.BigEndian.Uint64(valBs)
-	return int64(val), true, nil
+	return int64(val), true, nil //nolint:gosec
 }
 }
 
 
 // PutTime stores a new time.Time. Any existing value (even if of another
 // PutTime stores a new time.Time. Any existing value (even if of another

+ 4 - 2
internal/protoutil/protoutil.go

@@ -7,14 +7,16 @@
 package protoutil
 package protoutil
 
 
 import (
 import (
-	"fmt"
+	"errors"
 
 
 	"google.golang.org/protobuf/proto"
 	"google.golang.org/protobuf/proto"
 )
 )
 
 
+var errBufferTooSmall = errors.New("buffer too small")
+
 func MarshalTo(buf []byte, pb proto.Message) (int, error) {
 func MarshalTo(buf []byte, pb proto.Message) (int, error) {
 	if sz := proto.Size(pb); len(buf) < sz {
 	if sz := proto.Size(pb); len(buf) < sz {
-		return 0, fmt.Errorf("buffer too small")
+		return 0, errBufferTooSmall
 	} else if sz == 0 {
 	} else if sz == 0 {
 		return 0, nil
 		return 0, nil
 	}
 	}