瀏覽代碼

Update GoDoc for ioutils on atomic writers

Unlike its stdlib counterparts, AtomicFileWriter does not take into
consideration umask due to its use of chmod. Failure to recognize this
may cause subtle problems like the one described in #47498.

Therefore the documentation has been updated to let users know that
umask is not taken into consideration when using AtomicFileWriter.

Closes #47516.

Signed-off-by: Antonio Aguilar <antonio@zoftko.com>
Antonio Aguilar 1 年之前
父節點
當前提交
57a12a372f
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      pkg/ioutils/fswriters.go

+ 3 - 1
pkg/ioutils/fswriters.go

@@ -9,6 +9,7 @@ import (
 // NewAtomicFileWriter returns WriteCloser so that writing to it writes to a
 // NewAtomicFileWriter returns WriteCloser so that writing to it writes to a
 // temporary file and closing it atomically changes the temporary file to
 // temporary file and closing it atomically changes the temporary file to
 // destination path. Writing and closing concurrently is not allowed.
 // destination path. Writing and closing concurrently is not allowed.
+// NOTE: umask is not considered for the file's permissions.
 func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error) {
 func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, error) {
 	f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
 	f, err := os.CreateTemp(filepath.Dir(filename), ".tmp-"+filepath.Base(filename))
 	if err != nil {
 	if err != nil {
@@ -26,7 +27,8 @@ func NewAtomicFileWriter(filename string, perm os.FileMode) (io.WriteCloser, err
 	}, nil
 	}, nil
 }
 }
 
 
-// AtomicWriteFile atomically writes data to a file named by filename.
+// AtomicWriteFile atomically writes data to a file named by filename and with the specified permission bits.
+// NOTE: umask is not considered for the file's permissions.
 func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
 func AtomicWriteFile(filename string, data []byte, perm os.FileMode) error {
 	f, err := NewAtomicFileWriter(filename, perm)
 	f, err := NewAtomicFileWriter(filename, perm)
 	if err != nil {
 	if err != nil {