]> Cypherpunks repositories - gostls13.git/commitdiff
os: document that WriteFile is not atomic
authorRichard Tweed <RichardoC@users.noreply.github.com>
Thu, 10 Nov 2022 00:04:07 +0000 (00:04 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 10 Nov 2022 18:42:44 +0000 (18:42 +0000)
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 <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>

src/os/file.go

index 0a26850c41046e4b656610aeb64c05e0ec0d7489..070ccd0264d023fec0e2feacb3d5e3d5ca9fe128 100644 (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 {