1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:34:53 -07:00

os: don't return Chmod's error from Mkdir and OpenFile

Mkdir and OpenFile call Chmod internally on *BSD and Solaris,
because these OSes don't handle the sticky bit correctly.

However Chmod's error should be ignored. It shouldn't hide
the fact that a file itself is created.

Fixes #8383

Change-Id: Ia2e0b2ba72712d73a0a48ba5a263432e0fff31a5
Reviewed-on: https://go-review.googlesource.com/2057
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Kato Kazuyoshi 2014-12-22 21:05:07 -08:00 committed by Russ Cox
parent 69b2f70fa1
commit 9c0b145e4c
2 changed files with 8 additions and 7 deletions

View File

@ -204,14 +204,15 @@ func (f *File) WriteString(s string) (ret int, err error) {
func Mkdir(name string, perm FileMode) error { func Mkdir(name string, perm FileMode) error {
e := syscall.Mkdir(name, syscallMode(perm)) e := syscall.Mkdir(name, syscallMode(perm))
// mkdir(2) itself won't handle the sticky bit on *BSD and Solaris
if !supportsCreateWithStickyBit && e == nil && perm&ModeSticky != 0 {
e = Chmod(name, perm)
}
if e != nil { if e != nil {
return &PathError{"mkdir", name, e} return &PathError{"mkdir", name, e}
} }
// mkdir(2) itself won't handle the sticky bit on *BSD and Solaris
if !supportsCreateWithStickyBit && perm&ModeSticky != 0 {
Chmod(name, perm)
}
return nil return nil
} }

View File

@ -88,8 +88,8 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) {
} }
// open(2) itself won't handle the sticky bit on *BSD and Solaris // open(2) itself won't handle the sticky bit on *BSD and Solaris
if chmod && e == nil { if chmod {
e = Chmod(name, perm) Chmod(name, perm)
} }
// There's a race here with fork/exec, which we are // There's a race here with fork/exec, which we are