From 36c5d39c2c664450b2463e67509079026f2042f6 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 11 Dec 2020 09:41:59 +0100 Subject: [PATCH] Fix issues reported by semgrep --- internal/backend/azure/azure_test.go | 8 ++------ internal/migrations/s3_layout.go | 2 +- internal/repository/repository.go | 7 +------ internal/restorer/restorer.go | 7 +------ internal/restorer/restorer_test.go | 8 +------- 5 files changed, 6 insertions(+), 26 deletions(-) diff --git a/internal/backend/azure/azure_test.go b/internal/backend/azure/azure_test.go index 9b971f238..8d6284cf5 100644 --- a/internal/backend/azure/azure_test.go +++ b/internal/backend/azure/azure_test.go @@ -141,9 +141,7 @@ func TestUploadLargeFile(t *testing.T) { azcfg, err := azure.ParseConfig(os.Getenv("RESTIC_TEST_AZURE_REPOSITORY")) if err != nil { - if err != nil { - t.Fatal(err) - } + t.Fatal(err) } cfg := azcfg.(azure.Config) @@ -158,9 +156,7 @@ func TestUploadLargeFile(t *testing.T) { be, err := azure.Create(cfg, tr) if err != nil { - if err != nil { - t.Fatal(err) - } + t.Fatal(err) } defer func() { diff --git a/internal/migrations/s3_layout.go b/internal/migrations/s3_layout.go index 33af6bb23..877b44c84 100644 --- a/internal/migrations/s3_layout.go +++ b/internal/migrations/s3_layout.go @@ -42,7 +42,7 @@ func retry(max int, fail func(err error), f func() error) error { for i := 0; i < max; i++ { err = f() if err == nil { - return err + return nil } if fail != nil { fail(err) diff --git a/internal/repository/repository.go b/internal/repository/repository.go index 98811a31e..fbc72726f 100644 --- a/internal/repository/repository.go +++ b/internal/repository/repository.go @@ -517,12 +517,7 @@ func (r *Repository) LoadIndex(ctx context.Context) error { } // remove index files from the cache which have been removed in the repo - err = r.PrepareCache(validIndex) - if err != nil { - return err - } - - return nil + return r.PrepareCache(validIndex) } const listPackParallelism = 10 diff --git a/internal/restorer/restorer.go b/internal/restorer/restorer.go index c07209071..292241498 100644 --- a/internal/restorer/restorer.go +++ b/internal/restorer/restorer.go @@ -351,12 +351,7 @@ func (res *Restorer) VerifyFiles(ctx context.Context, dst string) (int, error) { offset += int64(length) } - err = file.Close() - if err != nil { - return err - } - - return nil + return file.Close() }, leaveDir: func(node *restic.Node, target, location string) error { return nil }, }) diff --git a/internal/restorer/restorer_test.go b/internal/restorer/restorer_test.go index 86f2158bd..247f2ac4d 100644 --- a/internal/restorer/restorer_test.go +++ b/internal/restorer/restorer_test.go @@ -141,12 +141,6 @@ func saveSnapshot(t testing.TB, repo restic.Repository, snapshot Snapshot) (*res return sn, id } -// toSlash converts the OS specific path dir to a slash-separated path. -func toSlash(dir string) string { - data := strings.Split(dir, string(filepath.Separator)) - return strings.Join(data, "/") -} - func TestRestorer(t *testing.T) { var tests = []struct { Snapshot @@ -354,7 +348,7 @@ func TestRestorer(t *testing.T) { errors := make(map[string]map[string]struct{}) res.Error = func(location string, err error) error { - location = toSlash(location) + location = filepath.ToSlash(location) t.Logf("restore returned error for %q: %v", location, err) if errors[location] == nil { errors[location] = make(map[string]struct{})