From 1309f0c51d730c87337a167acb70c86da4bb04be Mon Sep 17 00:00:00 2001 From: Richard Tweed Date: Thu, 10 Nov 2022 00:04:07 +0000 Subject: [PATCH] os: document that WriteFile is not atomic Fixes #56173 Change-Id: I03a3ad769c99c0bdb78b1d757173d630879fd4dd GitHub-Last-Rev: e3e31fa0b95aba363b13c45f562e3a4c8b31f2cc GitHub-Pull-Request: golang/go#56282 Reviewed-on: https://go-review.googlesource.com/c/go/+/443495 TryBot-Result: Gopher Robot Reviewed-by: Michael Knyszek Reviewed-by: Rob Pike Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- src/os/file.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/os/file.go b/src/os/file.go index 0a26850c41..070ccd0264 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -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 { -- 2.50.0