Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions cmd/transform/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package transform

import (
"context"
"strings"
"fmt"

"github.com/charmbracelet/log"
"github.com/mrz1836/go-sanitize"
sailpoint "github.com/sailpoint-oss/golang-sdk/v2"
v3 "github.com/sailpoint-oss/golang-sdk/v2/api_v3"
"github.com/sailpoint-oss/sailpoint-cli/internal/config"
Expand Down Expand Up @@ -35,8 +36,14 @@ func newDownloadCommand() *cobra.Command {
return sdk.HandleSDKError(resp, err)
}

filenameCounts := make(map[string]int)
for _, v := range transforms {
filename := strings.ReplaceAll(v.Name, " ", "")
baseName := sanitize.PathName(v.Name)
filename := baseName
if count := filenameCounts[baseName]; count > 0 {
filename = fmt.Sprintf("%s-%d", baseName, count)
}
filenameCounts[baseName]++
Comment thread
bhsf-james-pannell marked this conversation as resolved.
Comment thread
bhsf-james-pannell marked this conversation as resolved.

err := output.SaveJSONFile(v, filename, destination)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion internal/output/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ func WriteFile(folderPath string, filePath string, data []byte) error {
}
}

file, err := os.OpenFile(path.Join(folderPath, filePath), os.O_CREATE|os.O_RDWR, 0777)
// O_TRUNC ensures existing file content is removed before writing
file, err := os.OpenFile(path.Join(folderPath, filePath), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0777)
Comment thread
bhsf-james-pannell marked this conversation as resolved.
if err != nil {
return err
}
Comment thread
bhsf-james-pannell marked this conversation as resolved.
Expand Down
Loading