From 3a7ba2694d34ee8607ef65e5bf86a2201564f7f3 Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Tue, 2 Jul 2019 16:20:53 +0200 Subject: [PATCH] internal: fix linter errors Fix errors reported by default golangci-lint linters --- internal/config/config.go | 4 ++-- internal/db/db.go | 4 ++-- internal/git-handler/handler.go | 7 ++++++- internal/objectstorage/posixflat/posixflat.go | 1 - internal/testutil/utils.go | 8 ++++---- internal/toolbox/unarchive/unarchive.go | 4 ---- internal/util/git.go | 1 - internal/util/sha.go | 4 ++-- internal/util/slice.go | 4 ++-- 9 files changed, 18 insertions(+), 19 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 7556bd8..effea09 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -280,9 +280,9 @@ func (s *Steps) UnmarshalJSON(b []byte) error { case "run": var s RunStep - switch stepSpec.(type) { + switch stepSpec := stepSpec.(type) { case string: - s.Command = stepSpec.(string) + s.Command = stepSpec default: if err := json.Unmarshal(stepSpecRaw, &s); err != nil { return err diff --git a/internal/db/db.go b/internal/db/db.go index e932ad7..79bb8cb 100644 --- a/internal/db/db.go +++ b/internal/db/db.go @@ -177,12 +177,12 @@ func (db *DB) Do(f func(tx *Tx) error) error { } defer func() { if p := recover(); p != nil { - tx.Rollback() + _ = tx.Rollback() panic(p) } }() if err = f(tx); err != nil { - tx.Rollback() + _ = tx.Rollback() return err } return tx.Commit() diff --git a/internal/git-handler/handler.go b/internal/git-handler/handler.go index 416eba8..751d2bb 100644 --- a/internal/git-handler/handler.go +++ b/internal/git-handler/handler.go @@ -159,6 +159,11 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ctx := r.Context() repoPath, reqType, err := MatchPath(r.URL.Path) + if err != nil { + http.Error(w, err.Error(), http.StatusBadRequest) + return + } + repoAbsPath, exists, err := h.repoAbsPathFunc(h.reposDir, repoPath) if err != nil { if err == ErrWrongRepoPath { @@ -207,7 +212,7 @@ func (h *GitSmartHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "application/x-git-"+serviceName+"-advertisement") - w.Write(res) + _, _ = w.Write(res) case RequestTypeUploadPack: w.Header().Set("Content-Type", "application/x-git-upload-pack-result") diff --git a/internal/objectstorage/posixflat/posixflat.go b/internal/objectstorage/posixflat/posixflat.go index 7e23336..e70afe6 100644 --- a/internal/objectstorage/posixflat/posixflat.go +++ b/internal/objectstorage/posixflat/posixflat.go @@ -171,7 +171,6 @@ func unescape(s string) (string, bool, error) { if nc > splitLength && nc%splitLength == 2 && s[len(s)-2:] == ".f" { hasFileMarker = true s = s[:len(s)-2] - nc -= 2 } if n == 0 && ns == 0 { diff --git a/internal/testutil/utils.go b/internal/testutil/utils.go index fd1bac9..e4ac51d 100644 --- a/internal/testutil/utils.go +++ b/internal/testutil/utils.go @@ -104,8 +104,8 @@ func (p *Process) Kill() { if p.Cmd == nil { panic(fmt.Errorf("p: %s, cmd is empty", p.uid)) } - p.Cmd.Cmd.Process.Signal(os.Kill) - p.Cmd.Wait() + _ = p.Cmd.Cmd.Process.Signal(os.Kill) + _ = p.Cmd.Wait() p.Cmd = nil } @@ -115,8 +115,8 @@ func (p *Process) Stop() { panic(fmt.Errorf("p: %s, cmd is empty", p.uid)) } p.Cmd.Continue() - p.Cmd.Cmd.Process.Signal(os.Interrupt) - p.Cmd.Wait() + _ = p.Cmd.Cmd.Process.Signal(os.Interrupt) + _ = p.Cmd.Wait() p.Cmd = nil } diff --git a/internal/toolbox/unarchive/unarchive.go b/internal/toolbox/unarchive/unarchive.go index d94c6ac..c3ad26f 100644 --- a/internal/toolbox/unarchive/unarchive.go +++ b/internal/toolbox/unarchive/unarchive.go @@ -184,7 +184,3 @@ func writeNewHardLink(fpath string, target string) error { } return nil } - -func isSymlink(fi os.FileInfo) bool { - return fi.Mode()&os.ModeSymlink != 0 -} diff --git a/internal/util/git.go b/internal/util/git.go index 0be9ecd..be9bf89 100644 --- a/internal/util/git.go +++ b/internal/util/git.go @@ -50,7 +50,6 @@ func ParseGitURL(u string) (*url.URL, error) { } type Git struct { - cmd *exec.Cmd GitDir string Env []string } diff --git a/internal/util/sha.go b/internal/util/sha.go index 16788bb..0e8648b 100644 --- a/internal/util/sha.go +++ b/internal/util/sha.go @@ -24,7 +24,7 @@ import ( func EncodeSha1Hex(str string) string { h := sha1.New() // TODO(sgotti) must handle write errors - h.Write([]byte(str)) + _, _ = h.Write([]byte(str)) return hex.EncodeToString(h.Sum(nil)) } @@ -32,6 +32,6 @@ func EncodeSha1Hex(str string) string { func EncodeSha256Hex(str string) string { h := sha256.New() // TODO(sgotti) must handle write errors - h.Write([]byte(str)) + _, _ = h.Write([]byte(str)) return hex.EncodeToString(h.Sum(nil)) } diff --git a/internal/util/slice.go b/internal/util/slice.go index 4bfd609..ea02c78 100644 --- a/internal/util/slice.go +++ b/internal/util/slice.go @@ -51,8 +51,8 @@ func CompareStringSliceNoOrder(a []string, b []string) bool { a = append([]string(nil), a...) b = append([]string(nil), b...) - sort.Sort(sort.StringSlice(a)) - sort.Sort(sort.StringSlice(b)) + sort.Strings(a) + sort.Strings(b) for i, v := range a { if v != b[i] {