CreateFile safely writes the contents of data to filePath, ensuring that all data has been fsynced as well as the containing directory of the file.
(filePath string, data io.Reader)
| 91 | // CreateFile safely writes the contents of data to filePath, ensuring that all data |
| 92 | // has been fsynced as well as the containing directory of the file. |
| 93 | func CreateFile(filePath string, data io.Reader) error { |
| 94 | f, err := Create(filePath) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | |
| 99 | _, err = io.Copy(f, data) |
| 100 | merr := multierror.New(err) |
| 101 | merr.Add(f.Close()) |
| 102 | return merr.Err() |
| 103 | } |