Black Lives Matter. Support the Equal Justice Initiative.

Source file src/cmd/go/internal/modload/stat_openfile.go

Documentation: cmd/go/internal/modload

     1  // Copyright 2019 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 (js && wasm) || plan9
     6  // +build js,wasm plan9
     7  
     8  // On plan9, per http://9p.io/magic/man2html/2/access: “Since file permissions
     9  // are checked by the server and group information is not known to the client,
    10  // access must open the file to check permissions.”
    11  //
    12  // aix and js,wasm are similar, in that they do not define syscall.Access.
    13  
    14  package modload
    15  
    16  import (
    17  	"io/fs"
    18  	"os"
    19  )
    20  
    21  // hasWritePerm reports whether the current user has permission to write to the
    22  // file with the given info.
    23  func hasWritePerm(path string, _ fs.FileInfo) bool {
    24  	if f, err := os.OpenFile(path, os.O_WRONLY, 0); err == nil {
    25  		f.Close()
    26  		return true
    27  	}
    28  	return false
    29  }
    30  

View as plain text