Skip to content

Commit

Permalink
stages/files: add previousReport to result report
Browse files Browse the repository at this point in the history
This change notices if a report already exists and accordingly
nest the report in previousReport.
related to #1214
  • Loading branch information
sohankunkerkar committed Aug 2, 2021
1 parent 25d6d05 commit 61fdbab
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions internal/exec/stages/files/filesystemEntries.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,20 +140,32 @@ func (s *stage) createResultFile() error {
}

s.Logger.PushPrefix("createResultFile")
var prevReport interface{}
prevPath, _ := s.JoinPath(distro.ResultFilePath())

prevData, err := ioutil.ReadFile(prevPath)
if err != nil && !os.IsNotExist(err) {
return fmt.Errorf("reading previous report: %w", err)
}
err = json.Unmarshal(prevData, &prevReport)
if err != nil {
return fmt.Errorf("couldn't unmarshal previous report output: %v", err)
}
defer s.Logger.PopPrefix()

bootIDBytes, err := ioutil.ReadFile(distro.BootIDPath())
if err != nil {
return fmt.Errorf("reading boot ID: %w", err)
}

result := struct {
ProvisioningBootID string `json:"provisioningBootID"`
ProvisioningDate string `json:"provisioningDate"`
UserConfigProvided bool `json:"userConfigProvided"`
ProvisioningBootID string `json:"provisioningBootID"`
ProvisioningDate string `json:"provisioningDate"`
UserConfigProvided bool `json:"userConfigProvided"`
PreviousReport interface{} `json:"previousReport,omitempty"`
}{
ProvisioningBootID: strings.TrimSpace(string(bootIDBytes)),
ProvisioningDate: time.Now().Format(time.RFC3339),
PreviousReport: prevReport,
}
for _, config := range s.State.FetchedConfigs {
if config.Kind == "user" {
Expand Down

0 comments on commit 61fdbab

Please sign in to comment.