Skip to content

Commit

Permalink
No error on delete if file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
deanishe committed Jul 1, 2019
1 parent c00e544 commit 5ae0e9d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions util/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,17 @@ func WriteFile(filename string, data []byte, perm os.FileMode) error {
if err != nil {
return err
}
defer f.Close()

name = f.Name()
defer func(p string) {
defer func() {
// Ensure tempfile is deleted
if err := os.Remove(p); err != nil {
log.Printf("[ERROR] delete tempfile %q: %v", PrettyPath(p), err)
if err := os.Remove(name); err != nil {
if !os.IsNotExist(err) {
log.Printf("[ERROR] tempfile: %v", err)
}
}
}(name)
defer f.Close()
}()

if err := ioutil.WriteFile(name, data, perm); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
)

// AwGoVersion is the semantic version number of this library.
const AwGoVersion = "0.20.1"
const AwGoVersion = "0.20.2"

// Default Workflow settings. Can be changed with the corresponding Options.
//
Expand Down

0 comments on commit 5ae0e9d

Please sign in to comment.