run golangci-lint and apply suggested fixes
This commit is contained in:
@@ -108,8 +108,7 @@ func (t *datasetPathTree) WalkTopDown(parent []string, visitor DatasetPathsVisit
|
||||
|
||||
func newDatasetPathTree(initialComps []string) (t *datasetPathTree) {
|
||||
t = &datasetPathTree{}
|
||||
var cur *datasetPathTree
|
||||
cur = t
|
||||
cur := t
|
||||
for i, comp := range initialComps {
|
||||
cur.Component = comp
|
||||
cur.FilledIn = true
|
||||
|
||||
@@ -31,6 +31,9 @@ func ZFSSetReplicationCursor(fs *DatasetPath, snapname string) (guid uint64, err
|
||||
return 0, errors.Wrap(err, "zfs: replication cursor: get snapshot createtxg")
|
||||
}
|
||||
snapGuid, err := strconv.ParseUint(propsSnap.Get("guid"), 10, 64)
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "zfs: replication cursor: parse snapshot guid")
|
||||
}
|
||||
bookmarkPath := fmt.Sprintf("%s#%s", fs.ToString(), ReplicationCursorBookmarkName)
|
||||
propsBookmark, err := zfsGet(bookmarkPath, []string{"createtxg"}, sourceAny)
|
||||
_, bookmarkNotExistErr := err.(*DatasetDoesNotExist)
|
||||
|
||||
+9
-16
@@ -3,13 +3,13 @@ package zfs
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,7 @@ type VersionType string
|
||||
|
||||
const (
|
||||
Bookmark VersionType = "bookmark"
|
||||
Snapshot = "snapshot"
|
||||
Snapshot VersionType = "snapshot"
|
||||
)
|
||||
|
||||
func (t VersionType) DelimiterChar() string {
|
||||
@@ -37,14 +37,14 @@ func (t VersionType) String() string {
|
||||
|
||||
func DecomposeVersionString(v string) (fs string, versionType VersionType, name string, err error) {
|
||||
if len(v) < 3 {
|
||||
err = errors.New(fmt.Sprintf("snapshot or bookmark name implausibly short: %s", v))
|
||||
err = fmt.Errorf("snapshot or bookmark name implausibly short: %s", v)
|
||||
return
|
||||
}
|
||||
|
||||
snapSplit := strings.SplitN(v, "@", 2)
|
||||
bookmarkSplit := strings.SplitN(v, "#", 2)
|
||||
if len(snapSplit)*len(bookmarkSplit) != 2 {
|
||||
err = errors.New(fmt.Sprintf("dataset cannot be snapshot and bookmark at the same time: %s", v))
|
||||
err = fmt.Errorf("dataset cannot be snapshot and bookmark at the same time: %s", v)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -122,12 +122,12 @@ func ZFSListFilesystemVersions(fs *DatasetPath, filter FilesystemVersionFilter)
|
||||
}
|
||||
|
||||
if v.Guid, err = strconv.ParseUint(line[1], 10, 64); err != nil {
|
||||
err = errors.New(fmt.Sprintf("cannot parse GUID: %s", err.Error()))
|
||||
err = errors.Wrap(err, "cannot parse GUID")
|
||||
return
|
||||
}
|
||||
|
||||
if v.CreateTXG, err = strconv.ParseUint(line[2], 10, 64); err != nil {
|
||||
err = errors.New(fmt.Sprintf("cannot parse CreateTXG: %s", err.Error()))
|
||||
err = errors.Wrap(err, "cannot parse CreateTXG")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -160,16 +160,9 @@ func ZFSDestroyFilesystemVersion(filesystem *DatasetPath, version *FilesystemVer
|
||||
datasetPath := version.ToAbsPath(filesystem)
|
||||
|
||||
// Sanity check...
|
||||
if strings.IndexAny(datasetPath, "@#") == -1 {
|
||||
return fmt.Errorf("sanity check failed: no @ character found in dataset path: %s", datasetPath)
|
||||
if !strings.ContainsAny(datasetPath, "@#") {
|
||||
return fmt.Errorf("sanity check failed: no @ or # character found in %q", datasetPath)
|
||||
}
|
||||
|
||||
err = ZFSDestroy(datasetPath)
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Check for EBUSY, special meaning to us
|
||||
return
|
||||
|
||||
return ZFSDestroy(datasetPath)
|
||||
}
|
||||
|
||||
+4
-4
@@ -67,7 +67,6 @@ func (p *DatasetPath) TrimPrefix(prefix *DatasetPath) {
|
||||
for i := 0; i < newlen; i++ {
|
||||
p.comps[i] = oldcomps[prelen+i]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (p *DatasetPath) TrimNPrefixComps(n int) {
|
||||
@@ -251,7 +250,9 @@ func ZFSListChan(ctx context.Context, out chan ZFSListResult, properties []strin
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
cmd.Wait()
|
||||
// discard the error, this defer is only relevant if we return while parsing the output
|
||||
// in which case we'll return an 'unexpected output' error and not the exit status
|
||||
_ = cmd.Wait()
|
||||
}()
|
||||
|
||||
s := bufio.NewScanner(stdout)
|
||||
@@ -283,7 +284,6 @@ func ZFSListChan(ctx context.Context, out chan ZFSListResult, properties []strin
|
||||
sendResult(nil, s.Err())
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func validateRelativeZFSVersion(s string) error {
|
||||
@@ -731,7 +731,7 @@ func ZFSRecv(ctx context.Context, fs string, streamCopier StreamCopier, opts Rec
|
||||
{
|
||||
vs, err := ZFSListFilesystemVersions(fsdp, nil)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("cannot list versions to rollback is required: %s", err)
|
||||
return fmt.Errorf("cannot list versions for rollback for forced receive: %s", err)
|
||||
}
|
||||
for _, v := range vs {
|
||||
if v.Type == Snapshot {
|
||||
|
||||
@@ -13,6 +13,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
//nolint[:deadcode,unused]
|
||||
func debug(format string, args ...interface{}) {
|
||||
if debugEnabled {
|
||||
fmt.Fprintf(os.Stderr, "zfs: %s\n", fmt.Sprintf(format, args...))
|
||||
|
||||
Reference in New Issue
Block a user