Skip to content

Commit

Permalink
another attempt at cleaning up filepath
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Wasilewski <[email protected]>
  • Loading branch information
mwasilew2 committed Jan 24, 2024
1 parent b89d328 commit 1da3dc6
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/cmd/profile/usage_view_csv_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,15 @@ func usageViewCSVCommand() *cli.Command {
// save response to a file
var filePath string
if !ctx.IsSet(flagUsageViewCSVFile.Name) {
filePath = fmt.Sprintf("./usage-%s-%s-%s.csv", args.aspect, args.since, args.until)
basePath, err := os.Getwd()
if err != nil {
return fmt.Errorf("failed to get base path: %w", err)
}
filePath = fmt.Sprintf(basePath+"/usage-%s-%s-%s.csv", args.aspect, args.since, args.until)
} else {
filePath = filepath.Clean(ctx.String(flagUsageViewCSVFile.Name))
filePath = ctx.String(flagUsageViewCSVFile.Name)
}
fd, err := os.OpenFile(filePath, os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)
fd, err := os.OpenFile(filepath.Clean(filePath), os.O_CREATE|os.O_WRONLY|os.O_EXCL, 0600)
if err != nil {
return fmt.Errorf("failed to open a file descriptor: %w", err)
}
Expand Down

0 comments on commit 1da3dc6

Please sign in to comment.