From 3364efc57b5895cb6a8b3702ee93bc541f38dd70 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 6 Sep 2023 18:30:36 +0200 Subject: [PATCH] Lint: Fix linter errors Signed-off-by: Knut Ahlers --- .gitignore | 1 + assets.go | 19 ++++++++++++++++--- jobStatus.go | 13 +++++++++++-- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index d2f72d6..c8a17d9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /.default_env /.storage +/fake-build.sh tex-api diff --git a/assets.go b/assets.go index 66fe40e..24af4da 100644 --- a/assets.go +++ b/assets.go @@ -12,6 +12,7 @@ import ( "github.com/Luzifer/go_helpers/v2/str" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/gofrs/uuid" ) @@ -43,11 +44,15 @@ func buildAssetsTAR(uid uuid.UUID) (io.Reader, error) { if err != nil { return errors.Wrap(err, "opening source file") } + defer func() { + if err := osFile.Close(); err != nil { + logrus.WithError(err).Error("closing output file (leaked fd)") + } + }() if _, err := io.Copy(w, osFile); err != nil { return errors.Wrap(err, "copying source file") } - osFile.Close() // #nosec G104 return nil }) @@ -85,11 +90,15 @@ func buildAssetsZIP(uid uuid.UUID) (io.Reader, error) { if err != nil { return errors.Wrap(err, "opening source file") } + defer func() { + if err := osFile.Close(); err != nil { + logrus.WithError(err).Error("closing output file (leaked fd)") + } + }() if _, err := io.Copy(zipFile, osFile); err != nil { return errors.Wrap(err, "copying source file") } - osFile.Close() // #nosec G104 return nil }) @@ -120,11 +129,15 @@ func getAssetsPDF(uid uuid.UUID) (io.Reader, error) { if err != nil { return errors.Wrap(err, "opening file") } + defer func() { + if err := osFile.Close(); err != nil { + logrus.WithError(err).Error("closing output pdf file (leaked fd)") + } + }() if _, err := io.Copy(buf, osFile); err != nil { return errors.Wrap(err, "reading file") } - osFile.Close() // #nosec G104 found = true return filepath.SkipAll diff --git a/jobStatus.go b/jobStatus.go index 057ba1f..8f47164 100644 --- a/jobStatus.go +++ b/jobStatus.go @@ -9,6 +9,7 @@ import ( "github.com/gofrs/uuid" "github.com/gorilla/mux" "github.com/pkg/errors" + "github.com/sirupsen/logrus" ) type ( @@ -59,7 +60,11 @@ func loadStatusByUUID(uid uuid.UUID) (*jobStatus, error) { if err != nil { return nil, errors.Wrap(err, "opening status file") } - defer f.Close() + defer func() { + if err := f.Close(); err != nil { + logrus.WithError(err).Error("closing status file (leaked fd)") + } + }() if err = json.NewDecoder(f).Decode(&status); err != nil { return nil, errors.Wrap(err, "decoding status file") @@ -79,7 +84,11 @@ func (s jobStatus) Save() error { if err != nil { return errors.Wrap(err, "creating status file") } - defer f.Close() + defer func() { + if err := f.Close(); err != nil { + logrus.WithError(err).Error("closing status file (leaked fd)") + } + }() if err = json.NewEncoder(f).Encode(s); err != nil { return errors.Wrap(err, "encoding status")