WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions. Since Writefile requires multiple system calls to complete, a failu
(fs Filesystem, name string, data []byte, perm FileMode)
| 369 | // Since Writefile requires multiple system calls to complete, a failure mid-operation |
| 370 | // can leave the file in a partially written state. |
| 371 | func WriteFile(fs Filesystem, name string, data []byte, perm FileMode) error { |
| 372 | f, err := fs.OpenFile(name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm) |
| 373 | if err != nil { |
| 374 | return err |
| 375 | } |
| 376 | _, err = f.Write(data) |
| 377 | if err1 := f.Close(); err1 != nil && err == nil { |
| 378 | err = err1 |
| 379 | } |
| 380 | return err |
| 381 | } |