mirror of
https://github.com/restic/restic.git
synced 2025-12-10 23:51:46 +00:00
Fix linter warnings
This commit is contained in:
@@ -168,7 +168,7 @@ func (s *statefulOutput) PrintPatternJSON(path string, node *restic.Node) {
|
||||
}
|
||||
if s.newsn != s.oldsn {
|
||||
if s.oldsn != nil {
|
||||
_, _ = s.stdout.Write([]byte(fmt.Sprintf("],\"hits\":%d,\"snapshot\":%q},", s.hits, s.oldsn.ID())))
|
||||
_, _ = fmt.Fprintf(s.stdout, "],\"hits\":%d,\"snapshot\":%q},", s.hits, s.oldsn.ID())
|
||||
}
|
||||
_, _ = s.stdout.Write([]byte(`{"matches":[`))
|
||||
s.oldsn = s.newsn
|
||||
@@ -255,7 +255,7 @@ func (s *statefulOutput) Finish() {
|
||||
if s.JSON {
|
||||
// do some finishing up
|
||||
if s.oldsn != nil {
|
||||
_, _ = s.stdout.Write([]byte(fmt.Sprintf("],\"hits\":%d,\"snapshot\":%q}", s.hits, s.oldsn.ID())))
|
||||
_, _ = fmt.Fprintf(s.stdout, "],\"hits\":%d,\"snapshot\":%q}", s.hits, s.oldsn.ID())
|
||||
}
|
||||
if s.inuse {
|
||||
_, _ = s.stdout.Write([]byte("]\n"))
|
||||
|
||||
@@ -398,7 +398,7 @@ func TestRestoreNoMetadataOnIgnoredIntermediateDirs(t *testing.T) {
|
||||
fi, err := os.Stat(f2)
|
||||
rtest.OK(t, err)
|
||||
|
||||
rtest.Assert(t, fi.ModTime() == time.Unix(0, 0),
|
||||
rtest.Assert(t, fi.ModTime().Equal(time.Unix(0, 0)),
|
||||
"meta data of intermediate directory hasn't been restore")
|
||||
}
|
||||
|
||||
|
||||
@@ -498,6 +498,7 @@ func innerOpen(ctx context.Context, s string, gopts GlobalOptions, opts options.
|
||||
}
|
||||
|
||||
if errors.Is(err, backend.ErrNoRepository) {
|
||||
//nolint:staticcheck // capitalized error string is intentional
|
||||
return nil, fmt.Errorf("Fatal: %w at %v: %v", ErrNoRepository, location.StripPassword(gopts.backends, s), err)
|
||||
}
|
||||
if err != nil {
|
||||
@@ -552,6 +553,7 @@ func open(ctx context.Context, s string, gopts GlobalOptions, opts options.Optio
|
||||
// check if config is there
|
||||
fi, err := be.Stat(ctx, backend.Handle{Type: restic.ConfigFile})
|
||||
if be.IsNotExist(err) {
|
||||
//nolint:staticcheck // capitalized error string is intentional
|
||||
return nil, fmt.Errorf("Fatal: %w: unable to open config file: %v\nIs there a repository at the following location?\n%v", ErrNoRepository, err, location.StripPassword(gopts.backends, s))
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -45,10 +45,7 @@ func readPEMCertKey(filename string) (certs []byte, key []byte, err error) {
|
||||
}
|
||||
|
||||
var block *pem.Block
|
||||
for {
|
||||
if len(data) == 0 {
|
||||
break
|
||||
}
|
||||
for len(data) > 0 {
|
||||
block, data = pem.Decode(data)
|
||||
if block == nil {
|
||||
break
|
||||
|
||||
@@ -34,6 +34,7 @@ func isPath(s string) bool {
|
||||
|
||||
// check for drive paths
|
||||
drive := s[0]
|
||||
//nolint:staticcheck // de morgan's law makes this harder to read
|
||||
if !(drive >= 'a' && drive <= 'z') && !(drive >= 'A' && drive <= 'Z') {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -79,8 +79,8 @@ func TestListAPI(t *testing.T) {
|
||||
t.Logf("req %v %v, accept: %v", req.Method, req.URL.Path, req.Header["Accept"])
|
||||
|
||||
var err error
|
||||
switch {
|
||||
case req.Method == "GET":
|
||||
switch req.Method {
|
||||
case "GET":
|
||||
// list files in data/
|
||||
res.Header().Set("Content-Type", test.ContentType)
|
||||
_, err = res.Write([]byte(test.Data))
|
||||
@@ -89,7 +89,7 @@ func TestListAPI(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return
|
||||
case req.Method == "HEAD":
|
||||
case "HEAD":
|
||||
// stat file in data/, use the first two bytes in the name
|
||||
// of the file as the size :)
|
||||
filename := req.URL.Path[6:]
|
||||
|
||||
@@ -116,13 +116,13 @@ func TestMatch(t *testing.T) {
|
||||
|
||||
// Test with native path separator
|
||||
if filepath.Separator != '/' {
|
||||
pattern := strings.Replace(test.pattern, "/", string(filepath.Separator), -1)
|
||||
pattern := strings.ReplaceAll(test.pattern, "/", string(filepath.Separator))
|
||||
// Test with pattern as native
|
||||
t.Run("pattern-native", func(t *testing.T) {
|
||||
testpattern(t, pattern, test.path, test.match)
|
||||
})
|
||||
|
||||
path := strings.Replace(test.path, "/", string(filepath.Separator), -1)
|
||||
path := strings.ReplaceAll(test.path, "/", string(filepath.Separator))
|
||||
t.Run("path-native", func(t *testing.T) {
|
||||
// Test with path as native
|
||||
testpattern(t, test.pattern, path, test.match)
|
||||
@@ -206,13 +206,13 @@ func TestChildMatch(t *testing.T) {
|
||||
|
||||
// Test with native path separator
|
||||
if filepath.Separator != '/' {
|
||||
pattern := strings.Replace(test.pattern, "/", string(filepath.Separator), -1)
|
||||
pattern := strings.ReplaceAll(test.pattern, "/", string(filepath.Separator))
|
||||
// Test with pattern as native
|
||||
t.Run("pattern-native", func(t *testing.T) {
|
||||
testchildpattern(t, pattern, test.path, test.match)
|
||||
})
|
||||
|
||||
path := strings.Replace(test.path, "/", string(filepath.Separator), -1)
|
||||
path := strings.ReplaceAll(test.path, "/", string(filepath.Separator))
|
||||
t.Run("path-native", func(t *testing.T) {
|
||||
// Test with path as native
|
||||
testchildpattern(t, test.pattern, path, test.match)
|
||||
|
||||
@@ -253,11 +253,7 @@ func TestFSReaderDir(t *testing.T) {
|
||||
})
|
||||
test.OK(t, err)
|
||||
dir := path.Dir(tst.filename)
|
||||
for {
|
||||
if dir == "/" || dir == "." {
|
||||
break
|
||||
}
|
||||
|
||||
for dir != "/" && dir != "." {
|
||||
fi, err := fs.Lstat(dir)
|
||||
test.OK(t, err)
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
@@ -296,5 +295,5 @@ func TestNodeRestoreMetadataError(t *testing.T) {
|
||||
// This will fail because the target file does not exist
|
||||
err := NodeRestoreMetadata(node, nodePath, func(msg string) { rtest.OK(t, fmt.Errorf("Warning triggered for path: %s: %s", nodePath, msg)) },
|
||||
func(_ string) bool { return true })
|
||||
test.Assert(t, errors.Is(err, os.ErrNotExist), "failed for an unexpected reason")
|
||||
rtest.Assert(t, errors.Is(err, os.ErrNotExist), "failed for an unexpected reason")
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func (p *Packer) Finalize() error {
|
||||
encryptedHeader = binary.LittleEndian.AppendUint32(encryptedHeader, uint32(len(encryptedHeader)))
|
||||
|
||||
if err := verifyHeader(p.k, encryptedHeader, p.blobs); err != nil {
|
||||
//nolint:revive // ignore linter warnings about error message spelling
|
||||
//nolint:revive,staticcheck // ignore linter warnings about error message spelling
|
||||
return fmt.Errorf("Detected data corruption while writing pack-file header: %w\nCorrupted data is either caused by hardware issues or software bugs. Please open an issue at https://github.com/restic/restic/issues/new/choose for further troubleshooting.", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -395,7 +395,7 @@ func (r *Repository) saveAndEncrypt(ctx context.Context, t restic.BlobType, data
|
||||
ciphertext = r.key.Seal(ciphertext, nonce, data, nil)
|
||||
|
||||
if err := r.verifyCiphertext(ciphertext, uncompressedLength, id); err != nil {
|
||||
//nolint:revive // ignore linter warnings about error message spelling
|
||||
//nolint:revive,staticcheck // ignore linter warnings about error message spelling
|
||||
return 0, fmt.Errorf("Detected data corruption while saving blob %v: %w\nCorrupted blobs are either caused by hardware issues or software bugs. Please open an issue at https://github.com/restic/restic/issues/new/choose for further troubleshooting.", id, err)
|
||||
}
|
||||
|
||||
@@ -500,7 +500,7 @@ func (r *Repository) saveUnpacked(ctx context.Context, t restic.FileType, buf []
|
||||
ciphertext = r.key.Seal(ciphertext, nonce, p, nil)
|
||||
|
||||
if err := r.verifyUnpacked(ciphertext, t, buf); err != nil {
|
||||
//nolint:revive // ignore linter warnings about error message spelling
|
||||
//nolint:revive,staticcheck // ignore linter warnings about error message spelling
|
||||
return restic.ID{}, fmt.Errorf("Detected data corruption while saving file of type %v: %w\nCorrupted data is either caused by hardware issues or software bugs. Please open an issue at https://github.com/restic/restic/issues/new/choose for further troubleshooting.", t, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestBucketWidth(t *testing.T) {
|
||||
|
||||
b := e.buckets.Back().Value.(*rateBucket)
|
||||
rtest.Assert(t, b.totalBytes == 2, "b.totalBytes is %d, want 2", b.totalBytes)
|
||||
rtest.Assert(t, b.end == when.Add(bucketWidth), "b.end is %v, want %v", b.end, when.Add(bucketWidth))
|
||||
rtest.Assert(t, b.end.Equal(when.Add(bucketWidth)), "b.end is %v, want %v", b.end, when.Add(bucketWidth))
|
||||
|
||||
// Recording a byte outside the bucket width causes another bucket.
|
||||
e.recordBytes(when.Add(bucketWidth), 1)
|
||||
@@ -72,7 +72,7 @@ func TestBucketWidth(t *testing.T) {
|
||||
|
||||
b = e.buckets.Back().Value.(*rateBucket)
|
||||
rtest.Assert(t, b.totalBytes == 1, "b.totalBytes is %d, want 1", b.totalBytes)
|
||||
rtest.Assert(t, b.end == when.Add(2*bucketWidth), "b.end is %v, want %v", b.end, when.Add(bucketWidth))
|
||||
rtest.Assert(t, b.end.Equal(when.Add(2*bucketWidth)), "b.end is %v, want %v", b.end, when.Add(bucketWidth))
|
||||
|
||||
// Recording a byte after a longer delay creates a sparse bucket list.
|
||||
e.recordBytes(when.Add(time.Hour+time.Millisecond), 7)
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
// GetProgressChannel returns a channel with which a single listener
|
||||
// receives each incoming signal.
|
||||
func GetProgressChannel() <-chan os.Signal {
|
||||
signals.Once.Do(func() {
|
||||
signals.once.Do(func() {
|
||||
signals.ch = make(chan os.Signal, 1)
|
||||
setupSignals()
|
||||
})
|
||||
@@ -19,6 +19,6 @@ func GetProgressChannel() <-chan os.Signal {
|
||||
// XXX The fact that signals is a single global variable means that only one
|
||||
// listener receives each incoming signal.
|
||||
var signals struct {
|
||||
ch chan os.Signal
|
||||
sync.Once
|
||||
ch chan os.Signal
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user