Skip to content

Commit

Permalink
chore: conversion: enable gosec
Browse files Browse the repository at this point in the history
  • Loading branch information
dsonck92 committed Jul 10, 2024
1 parent 09dcc49 commit 3a7b93d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion conversion/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ linters:
- prealloc
- nestif
- lll
- gosec
- gocritic
- gocognit
- funlen
Expand Down
19 changes: 12 additions & 7 deletions conversion/processor/pdf_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
package processor

import (
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"strconv"
Expand All @@ -37,22 +39,25 @@ func NewPDFProcessor() *PDFProcessor {
}

func (p *PDFProcessor) TextFromPDF(inputPath string) (*string, error) {
tmpPath := filepath.FromSlash(os.TempDir() + "/" + helper.NewID() + ".txt")
tmpPath := filepath.Join(os.TempDir(), helper.NewID()+".txt")

if err := infra.NewCommand().Exec("pdftotext", inputPath, tmpPath); err != nil {
return nil, err
}

defer func(path string) {
_, err := os.Stat(path)
if os.IsExist(err) {
if err := os.Remove(path); err != nil {
infra.GetLogger().Error(err)
}
if err := os.Remove(path); errors.Is(err, fs.ErrNotExist) {
return
} else if err != nil {
infra.GetLogger().Error(err)
}
}(tmpPath)
b, err := os.ReadFile(tmpPath)

b, err := os.ReadFile(tmpPath) //nolint:gosec // Known path
if err != nil {
return nil, err
}

return helper.ToPtr(strings.TrimSpace(string(b))), nil
}

Expand Down

0 comments on commit 3a7b93d

Please sign in to comment.