os: document that WriteFile is not atomic

Fixes #56173

Change-Id: I03a3ad769c99c0bdb78b1d757173d630879fd4dd
GitHub-Last-Rev: e3e31fa0b9
GitHub-Pull-Request: golang/go#56282
Reviewed-on: https://go-review.googlesource.com/c/go/+/443495
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Richard Tweed 2022-11-10 00:04:07 +00:00 committed by Gopher Robot
parent d931b3b771
commit 1309f0c51d

View file

@ -710,6 +710,8 @@ func ReadFile(name string) ([]byte, error) {
// 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 failure mid-operation
// can leave the file in a partially written state.
func WriteFile(name string, data []byte, perm FileMode) error {
f, err := OpenFile(name, O_WRONLY|O_CREATE|O_TRUNC, perm)
if err != nil {