1
0
Fork 0
mirror of https://github.com/Luzifer/tex-api.git synced 2024-11-08 08:10:09 +00:00

Lint: Fix linter errors

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2023-09-06 18:30:36 +02:00
parent 4937284b0e
commit 3364efc57b
Signed by: luzifer
GPG key ID: D91C3E91E4CAD6F5
3 changed files with 28 additions and 5 deletions

1
.gitignore vendored
View file

@ -1,3 +1,4 @@
/.default_env
/.storage
/fake-build.sh
tex-api

View file

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

View file

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