Skip to content

Commit

Permalink
cmd/tomledit: simplify write-out code
Browse files Browse the repository at this point in the history
  • Loading branch information
creachadair committed Jun 1, 2023
1 parent 1bc604f commit cb1e193
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions cmd/tomledit/tomledit.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@ func (s *settings) saveDocument(doc *tomledit.Document) error {
if s.Path == "" {
return errors.New("no output -path is set")
}
f, err := atomicfile.New(s.Path, 0600)
if err != nil {
return err
}
defer f.Cancel()
if err := tomledit.Format(f, doc); err != nil {
return fmt.Errorf("formatting output: %w", err)
}
return f.Close()
return atomicfile.Tx(s.Path, 0600, func(f *atomicfile.File) error {
if err := tomledit.Format(f, doc); err != nil {
return fmt.Errorf("formatting output: %w", err)
}
return nil
})
}

0 comments on commit cb1e193

Please sign in to comment.