Skip to content

Commit

Permalink
code-review
Browse files Browse the repository at this point in the history
  • Loading branch information
spennymac committed Mar 26, 2024
1 parent 12ecebe commit c98c36d
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ func removeAll(fs billy.Basic, path string) error {
// WriteFile writes data to a file named by filename in the given filesystem.
// If the file does not exist, WriteFile creates it with permissions perm;
// otherwise WriteFile truncates it before writing.
func WriteFile(fs billy.Basic, filename string, data []byte, perm os.FileMode) error {
func WriteFile(fs billy.Basic, filename string, data []byte, perm os.FileMode) (err error) {
f, err := fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
return err
}
defer func() {
if f != nil {
_ = f.Close()
err = f.Close()
}
}()

Expand All @@ -112,13 +112,7 @@ func WriteFile(fs billy.Basic, filename string, data []byte, perm os.FileMode) e
err = io.ErrShortWrite
}

err1 := f.Close()
f = nil
if err == nil {
err = err1
}

return err
return nil
}

// Random number state.
Expand Down Expand Up @@ -248,7 +242,7 @@ func ReadFile(fs billy.Basic, name string) ([]byte, error) {
return nil, err
}

defer func() { _ = f.Close() }()
defer f.Close()

var size int
if info, err := fs.Stat(name); err == nil {
Expand Down

0 comments on commit c98c36d

Please sign in to comment.