Skip to content

Commit 1309f0c

Browse files
RichardoCgopherbot
authored andcommitted
os: document that WriteFile is not atomic
Fixes #56173 Change-Id: I03a3ad769c99c0bdb78b1d757173d630879fd4dd GitHub-Last-Rev: e3e31fa GitHub-Pull-Request: #56282 Reviewed-on: https://go-review.googlesource.com/c/go/+/443495 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Knyszek <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]>
1 parent d931b3b commit 1309f0c

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/os/file.go

+2
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ func ReadFile(name string) ([]byte, error) {
710710
// WriteFile writes data to the named file, creating it if necessary.
711711
// If the file does not exist, WriteFile creates it with permissions perm (before umask);
712712
// otherwise WriteFile truncates it before writing, without changing permissions.
713+
// Since Writefile requires multiple system calls to complete, a failure mid-operation
714+
// can leave the file in a partially written state.
713715
func WriteFile(name string, data []byte, perm FileMode) error {
714716
f, err := OpenFile(name, O_WRONLY|O_CREATE|O_TRUNC, perm)
715717
if err != nil {

0 commit comments

Comments
 (0)