Skip to content

Commit

Permalink
refactor, Use the built-in Golang function to open report files, sinc…
Browse files Browse the repository at this point in the history
…e it can error if the file already exists

Part of #296
  • Loading branch information
ruiAzevedo19 committed Jul 31, 2024
1 parent 162e998 commit b1c89fb
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions cmd/eval-dev-quality/cmd/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/symflower/eval-dev-quality/evaluate"
"github.com/symflower/eval-dev-quality/evaluate/report"
"github.com/symflower/eval-dev-quality/log"
"github.com/symflower/eval-dev-quality/util"
)

// Report holds the "report" command.
Expand Down Expand Up @@ -41,19 +42,11 @@ func (command *Report) Execute(args []string) (err error) {
if err = osutil.MkdirAll(filepath.Dir(command.ResultPath)); err != nil {
command.logger.Panicf("ERROR: %s", err)
}
if _, err := os.Stat(filepath.Join(command.ResultPath, "evaluation.csv")); err != nil {
if os.IsNotExist(err) {
evaluationCSVFile, err = os.Create(filepath.Join(command.ResultPath, "evaluation.csv"))
if err != nil {
command.logger.Panicf("ERROR: %s", err)
}
defer evaluationCSVFile.Close()
} else {
command.logger.Panicf("ERROR: %s", err)
}
} else {
command.logger.Panicf("ERROR: an evaluation CSV file already exists in %s", command.ResultPath)

if evaluationCSVFile, err = os.OpenFile(filepath.Join(command.ResultPath, "evaluation.csv"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0755); err != nil {
command.logger.Panicf("ERROR: %s", err)
}
defer evaluationCSVFile.Close()

// Collect all evaluation CSV file paths.
allEvaluationPaths := map[string]bool{}
Expand Down

0 comments on commit b1c89fb

Please sign in to comment.