Skip to content

Commit

Permalink
Fix "karmor profile --save" command
Browse files Browse the repository at this point in the history
  • Loading branch information
Affan-7 committed Dec 15, 2024
1 parent 8843f36 commit d7e5d79
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions profile/Client/profileClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,17 +379,36 @@ func AggregateSummary(inputMap map[Profile]*Frequency, Operation string) map[Pro

func convertToJSON(Operation string, data []Profile) {
var jsonArray []string
jsonByte, _ := json.MarshalIndent(data, " ", " ")
jsonByte, err := json.MarshalIndent(data, " ", " ")
if err != nil {
log.Fatal("Cannot marshal JSON", err)
}

//unmarshalling here because it is marshalled two times for some reason
if err := json.Unmarshal(jsonByte, &jsonArray); err != nil {
fmt.Println("Error parsing JSON array:", err)
log.Fatal("Cannot unmarshal JSON", err)
}

if len(jsonArray) > 0 {
filepath := "Profile_Summary/"
err := os.MkdirAll(filepath, 0600)
err = os.WriteFile(filepath+Operation+".json", []byte(jsonArray[0]), 0600)
err := os.MkdirAll(filepath, 0700)
if err != nil {
log.Fatal("Cannot create directory", err)
}

// Create file
file, err := os.Create(filepath + Operation + ".json")
if err != nil {
panic(err)
log.Fatal("Cannot create file", err)
}
defer file.Close()

// Write JSON array to file
for _, line := range jsonArray {
_, err := file.WriteString(line + "\n")
if err != nil {
log.Fatal("Cannot write to file", err)
}
}
}
}
Expand Down

0 comments on commit d7e5d79

Please sign in to comment.