Skip to content

Commit

Permalink
Merge pull request #59 from mostlikelee/puppet-file-descriptor
Browse files Browse the repository at this point in the history
bugfix: ensure file descriptor close on puppet file
  • Loading branch information
grahamgilbert authored Nov 19, 2024
2 parents a7faf84 + 6ba0fc7 commit b83872c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tables/puppet/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,28 @@ func yamlPath() string {
}

func getPuppetYaml() (*PuppetInfo, error) {

var yamlData PuppetInfo

yamlFile, err := os.Open(yamlPath())
if err != nil {
log.Print(err)
return &yamlData, err
}
defer yamlFile.Close()

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(yamlFile)
if err != nil {
return &yamlData, err
}

yamlString := buf.String()
yamlString = strings.Replace(yamlString, "\r", "\n", -1)

err = yaml.Unmarshal([]byte(yamlString), &yamlData)
if err != nil {
return &yamlData, err
}
yamlFile.Close()

return &yamlData, nil
}

0 comments on commit b83872c

Please sign in to comment.