Skip to content

Commit

Permalink
Don't produce an empty file if generate fails
Browse files Browse the repository at this point in the history
  • Loading branch information
quite committed May 2, 2024
1 parent 65735e8 commit 884b00a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/age-plugin-tkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ func run() int {
le.Printf("OpenFile failed: %s\n", err)
return 1
}
defer func() {
if err := f.Close(); err != nil {
le.Printf("Close failed: %s\n", err)
}
}()
out = f
}
if !generate(out, noTouchFlag == false) {
success := generate(out, noTouchFlag == false)
if outputFlag != "" {
if err := out.Close(); err != nil {
le.Printf("Close failed: %s\n", err)
}
}
if !success {
if outputFlag != "" {
if err := os.Remove(outputFlag); err != nil {
le.Printf("Remove failed: %s\n", err)
}
}
return 1
}
return 0
Expand Down

0 comments on commit 884b00a

Please sign in to comment.