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>
diff --git a/src/os/file.go b/src/os/file.go
index 79e8fc3..f332bc8 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -204,14 +204,15 @@
func Mkdir(name string, perm FileMode) error {
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 {
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
}
diff --git a/src/os/file_unix.go b/src/os/file_unix.go
index fbe05c6..3fb70d6 100644
--- a/src/os/file_unix.go
+++ b/src/os/file_unix.go
@@ -88,8 +88,8 @@
}
// open(2) itself won't handle the sticky bit on *BSD and Solaris
- if chmod && e == nil {
- e = Chmod(name, perm)
+ if chmod {
+ Chmod(name, perm)
}
// There's a race here with fork/exec, which we are