diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-08-04 16:40:21 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-08-09 10:59:36 +0300 |
commit | fc6d12cda72720dbea2eed1976f6012661646b1f (patch) | |
tree | 468909042528200b33969cb6295beb01c567acb5 /internal/gitaly/service/repository/apply_gitattributes.go | |
parent | 631638faef0292271e674cefeb87cf3af60f4281 (diff) |
lint: Handle error returned by os.Remove
The change removes os.Remove from lint rules exclusion
and fixes all the places where it causes the issue.
If removal ends up with an error we try to log it if the
logger is accessible. Otherwise the error is just omitted.
We don't return it back to the caller because we don't want
functional changes here.
Diffstat (limited to 'internal/gitaly/service/repository/apply_gitattributes.go')
-rw-r--r-- | internal/gitaly/service/repository/apply_gitattributes.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/internal/gitaly/service/repository/apply_gitattributes.go b/internal/gitaly/service/repository/apply_gitattributes.go index 231894762..138ba60b8 100644 --- a/internal/gitaly/service/repository/apply_gitattributes.go +++ b/internal/gitaly/service/repository/apply_gitattributes.go @@ -9,6 +9,7 @@ import ( "os" "path/filepath" + "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/v14/internal/git" "gitlab.com/gitlab-org/gitaly/v14/internal/git/catfile" "gitlab.com/gitlab-org/gitaly/v14/internal/transaction/txinfo" @@ -62,7 +63,11 @@ func (s *server) applyGitattributes(ctx context.Context, c catfile.Batch, repoPa if err != nil { return status.Errorf(codes.Internal, "ApplyGitAttributes: creating temp file: %v", err) } - defer os.Remove(tempFile.Name()) + defer func() { + if err := os.Remove(tempFile.Name()); err != nil && !errors.Is(err, os.ErrNotExist) { + ctxlogrus.Extract(ctx).WithError(err).Errorf("failed to remove tmp file %q", tempFile.Name()) + } + }() blobObj, err := c.Blob(ctx, git.Revision(blobInfo.Oid)) if err != nil { |