helpers: Add a comment about file mode for new files

See #5434
This commit is contained in:
Bjørn Erik Pedersen 2018-11-14 17:44:04 +01:00
parent 94f0f7e597
commit fabf026f49
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -563,12 +563,13 @@ func OpenFilesForWriting(fs afero.Fs, filenames ...string) (io.WriteCloser, erro
func OpenFileForWriting(fs afero.Fs, filename string) (afero.File, error) {
filename = filepath.Clean(filename)
// Create will truncate if file already exists.
// os.Create will create any new files with mode 0666 (before umask).
f, err := fs.Create(filename)
if err != nil {
if !os.IsNotExist(err) {
return nil, err
}
if err = fs.MkdirAll(filepath.Dir(filename), 0777); err != nil { // rwx, rw, r before umask
if err = fs.MkdirAll(filepath.Dir(filename), 0777); err != nil { // before umask
return nil, err
}
f, err = fs.Create(filename)