From 4b05dc91b0fe99724721e3545807f3b8f1310c52 Mon Sep 17 00:00:00 2001
From: Ian Lance Taylor <iant@golang.org>
Date: Tue, 26 Feb 2019 06:31:21 -0800
Subject: [PATCH] os: clarify that mode argument is only used if file is
 created

Fixes #30400

Change-Id: Icbd1dda29562afa80c8e37657133a6fe48070ac0
Reviewed-on: https://go-review.googlesource.com/c/163744
Reviewed-by: Rob Pike <r@golang.org>
---
 src/os/file.go | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/os/file.go b/src/os/file.go
index fdead63bfc4..8c25cc0a3b5 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -265,10 +265,10 @@ func Open(name string) (*File, error) {
 	return OpenFile(name, O_RDONLY, 0)
 }
 
-// Create creates the named file with mode 0666 (before umask), truncating
-// it if it already exists. If successful, methods on the returned
-// File can be used for I/O; the associated file descriptor has mode
-// O_RDWR.
+// Create creates or truncates the named file. If the file already exists,
+// it is truncated. If the file does not exist, it is created with mode 0666
+// (before umask). If successful, methods on the returned File can
+// be used for I/O; the associated file descriptor has mode O_RDWR.
 // If there is an error, it will be of type *PathError.
 func Create(name string) (*File, error) {
 	return OpenFile(name, O_RDWR|O_CREATE|O_TRUNC, 0666)
@@ -276,7 +276,8 @@ func Create(name string) (*File, error) {
 
 // OpenFile is the generalized open call; most users will use Open
 // or Create instead. It opens the named file with specified flag
-// (O_RDONLY etc.) and perm (before umask), if applicable. If successful,
+// (O_RDONLY etc.). If the file does not exist, and the O_CREATE flag
+// is passed, it is created with mode perm (before umask). If successful,
 // methods on the returned File can be used for I/O.
 // If there is an error, it will be of type *PathError.
 func OpenFile(name string, flag int, perm FileMode) (*File, error) {
-- 
GitLab