...

Source file src/cmd/go/internal/toolchain/umask_unix.go

Documentation: cmd/go/internal/toolchain

     1  // Copyright 2023 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build darwin || freebsd || linux || netbsd || openbsd
     6  
     7  package toolchain
     8  
     9  import (
    10  	"io/fs"
    11  	"syscall"
    12  )
    13  
    14  // sysWriteBits determines which bits to OR into the mode to make a directory writable.
    15  // It must be called when there are no other file system operations happening.
    16  func sysWriteBits() fs.FileMode {
    17  	// Read current umask. There's no way to read it without also setting it,
    18  	// so set it conservatively and then restore the original one.
    19  	m := syscall.Umask(0o777)
    20  	syscall.Umask(m)    // restore bits
    21  	if m&0o22 == 0o22 { // group and world are unwritable by default
    22  		return 0o700
    23  	}
    24  	if m&0o2 == 0o2 { // group is writable by default, but not world
    25  		return 0o770
    26  	}
    27  	return 0o777 // everything is writable by default
    28  }
    29  

View as plain text