]> Cypherpunks repositories - gostls13.git/commitdiff
os: don't return Chmod's error from Mkdir and OpenFile
authorKato Kazuyoshi <kato.kazuyoshi@gmail.com>
Tue, 23 Dec 2014 05:05:07 +0000 (21:05 -0800)
committerRuss Cox <rsc@golang.org>
Fri, 20 Mar 2015 18:33:00 +0000 (18:33 +0000)
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>
src/os/file.go
src/os/file_unix.go

index 79e8fc33882bd79b4a0fa572a05a1c591d1e8cff..f332bc83462825645bf3016f4d2372028fbc6623 100644 (file)
@@ -204,14 +204,15 @@ func (f *File) WriteString(s string) (ret int, err error) {
 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
 }
 
index fbe05c61a06c837ed57e3e4fa747b7153ceea340..3fb70d6bc17e49ee21f20aaf7751d8ebdb7ae132 100644 (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
-       if chmod && e == nil {
-               e = Chmod(name, perm)
+       if chmod {
+               Chmod(name, perm)
        }
 
        // There's a race here with fork/exec, which we are