Permalink
Browse files

fix(util.go) make writeFileSynced return error properly

  • Loading branch information...
1 parent 4a4b739 commit 8ca39ae2237115edc31fd6d8312daac290a1cb87 @xiang90 xiang90 committed Jan 15, 2014
Showing with 11 additions and 5 deletions.
  1. +11 −5 util.go
View
16 util.go
@@ -15,11 +15,17 @@ func writeFileSynced(filename string, data []byte, perm os.FileMode) error {
if err != nil {
return err
}
+
n, err := f.Write(data)
- f.Sync()
- f.Close()
- if err == nil && n < len(data) {
- err = io.ErrShortWrite
+ if n < len(data) {
+ f.Close()
+ return io.ErrShortWrite
+ }
+
+ err = f.Sync()
+ if err != nil {
+ return err
}
- return err
+
+ return f.Close()
}

0 comments on commit 8ca39ae

Please sign in to comment.