Fix issues reported by semgrep

This commit is contained in:
Alexander Neumann 2020-12-11 09:41:59 +01:00
parent 7facc8ccc1
commit 36c5d39c2c
5 changed files with 6 additions and 26 deletions

View File

@ -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() {

View File

@ -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)

View File

@ -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

View File

@ -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 },
})

View File

@ -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{})