From cc1d11a94459158da830d2b3f0609aca08da4f2c Mon Sep 17 00:00:00 2001 From: Owen Rumney Date: Thu, 24 Mar 2022 09:16:24 +0000 Subject: [PATCH] chore: Update version of Docker base image - tidy up some code - imports for logrus - ranges that have pointless code Signed-off-by: Owen Rumney --- Dockerfile | 2 +- internal/app/squealer/scan/directory_scanner.go | 8 ++++++-- internal/app/squealer/scan/git_scanner.go | 15 +++++++-------- internal/app/squealer/scan/signals_unix.go | 3 ++- internal/app/squealer/scan/signals_windows.go | 3 ++- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index 36d97a2..80ab233 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine +FROM alpine:3.15.2 # use a non-privileged user USER nobody diff --git a/internal/app/squealer/scan/directory_scanner.go b/internal/app/squealer/scan/directory_scanner.go index fd30008..3615f16 100644 --- a/internal/app/squealer/scan/directory_scanner.go +++ b/internal/app/squealer/scan/directory_scanner.go @@ -1,11 +1,12 @@ package scan import ( - "github.com/owenrumney/squealer/internal/app/squealer/match" - "github.com/owenrumney/squealer/internal/app/squealer/mertics" "io/ioutil" "os" "path/filepath" + + "github.com/owenrumney/squealer/internal/app/squealer/match" + "github.com/owenrumney/squealer/internal/app/squealer/mertics" ) type directoryScanner struct { @@ -38,6 +39,9 @@ func newDirectoryScanner(sc ScannerConfig) (*directoryScanner, error) { func (d directoryScanner) Scan() ([]match.Transgression, error) { return nil, filepath.Walk(d.workingDirectory, func(path string, info os.FileInfo, err error) error { + if err != nil { + return err + } if info.IsDir() || shouldIgnore(path, d.ignorePaths, d.ignoreExtensions) { return nil } diff --git a/internal/app/squealer/scan/git_scanner.go b/internal/app/squealer/scan/git_scanner.go index f33f15b..e7e1e2c 100644 --- a/internal/app/squealer/scan/git_scanner.go +++ b/internal/app/squealer/scan/git_scanner.go @@ -9,7 +9,6 @@ import ( "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/plumbing" "github.com/go-git/go-git/v5/plumbing/object" - "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus" "github.com/owenrumney/squealer/internal/app/squealer/match" @@ -76,10 +75,10 @@ func (s *gitScanner) Scan() ([]match.Transgression, error) { var useCommitShaList = false if s.commitListFile != "" { - logrus.Debug("limiting the commit list check") + log.Debug("limiting the commit list check") s.commitShas, _ = s.processSpecificCommits() useCommitShaList = len(s.commitShas) > 0 - logrus.Debugf("commit limited to %d commits", len(s.commitShas)) + log.Debugf("commit limited to %d commits", len(s.commitShas)) } commits, err := s.getRelevantCommitIter(client) @@ -132,7 +131,7 @@ func (s *gitScanner) Scan() ([]match.Transgression, error) { s.metrics.IncrementCommitsProcessed() } if err != nil && err != io.EOF { - logrus.WithError(err).Error("error was not null or an EOF") + log.WithError(err).Error("error was not null or an EOF") } close(ch) @@ -262,7 +261,7 @@ func (s *gitScanner) getRelevantCommitIter(client *git.Repository) (object.Commi var err error if headRef != plumbing.ZeroHash { - logrus.Infof("starting at hash %s", headRef.String()) + log.Infof("starting at hash %s", headRef.String()) commits, err = client.Log(&git.LogOptions{ From: headRef, All: false, @@ -272,7 +271,7 @@ func (s *gitScanner) getRelevantCommitIter(client *git.Repository) (object.Commi return nil, err } } else { - logrus.Info("No head was found, scanning all commits") + log.Info("No head was found, scanning all commits") commits, err = client.CommitObjects() if err != nil { return nil, err @@ -299,14 +298,14 @@ func (s *gitScanner) processSpecificCommits() (map[string]bool, error) { var commitShas = make(map[string]bool) for r.Scan() { c := r.Text() - logrus.Debugf("adding commit limit to %s", c) + log.Debugf("adding commit limit to %s", c) commitShas[c] = true } return commitShas, nil } func (s *gitScanner) isNotValidCommit(commitSha string) bool { - logrus.Tracef("Checking validity of commit %s", commitSha) + log.Tracef("Checking validity of commit %s", commitSha) _, ok := s.commitShas[commitSha] return !ok } diff --git a/internal/app/squealer/scan/signals_unix.go b/internal/app/squealer/scan/signals_unix.go index 929bc15..45c6fb8 100644 --- a/internal/app/squealer/scan/signals_unix.go +++ b/internal/app/squealer/scan/signals_unix.go @@ -1,3 +1,4 @@ +//go:build linux || bsd || darwin // +build linux bsd darwin package scan @@ -14,7 +15,7 @@ func (s *gitScanner) monitorSignals(processes int, wg sync.WaitGroup) { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM, syscall.SIGTSTP) go func() { - for _ = range c { + for range c { log.Info("Shutting down workers and exiting...") for i := 0; i < processes; i++ { wg.Done() diff --git a/internal/app/squealer/scan/signals_windows.go b/internal/app/squealer/scan/signals_windows.go index c1b15c7..ab77ca4 100644 --- a/internal/app/squealer/scan/signals_windows.go +++ b/internal/app/squealer/scan/signals_windows.go @@ -1,3 +1,4 @@ +//go:build windows // +build windows package scan @@ -14,7 +15,7 @@ func (s *gitScanner) monitorSignals(processes int, wg sync.WaitGroup) { c := make(chan os.Signal, 2) signal.Notify(c, os.Interrupt, syscall.SIGTERM) go func() { - for _ = range c { + for range c { log.Info("Shutting down workers and exiting...") for i := 0; i < processes; i++ { wg.Done()