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

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

View as plain text