mirror of
https://github.com/golang/go
synced 2024-11-18 08:54:45 -07:00
cmd/goimports: set correct permissions on Windows
As of Go 1.14, WriteFile on Windows will set read-only on existing files if you pass 0 for perms. Pass the pre-existing permissions. Updates golang/go#38225. Change-Id: I3174469efd4dc4c7eacc8522386a0712cfa39d11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/229297 Reviewed-by: Ian Cottrell <iancottrell@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
a466788a31
commit
01e6875574
@ -160,7 +160,12 @@ func processFile(filename string, in io.Reader, out io.Writer, argType argumentT
|
||||
// filename is "<standard input>"
|
||||
return errors.New("can't use -w on stdin")
|
||||
}
|
||||
err = ioutil.WriteFile(filename, res, 0)
|
||||
// On Windows, we need to re-set the permissions from the file. See golang/go#38225.
|
||||
var perms os.FileMode
|
||||
if fi, err := os.Stat(filename); err == nil {
|
||||
perms = fi.Mode() & os.ModePerm
|
||||
}
|
||||
err = ioutil.WriteFile(filename, res, perms)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user