1
0
mirror of https://github.com/golang/go synced 2024-11-19 02:24:41 -07:00

cmd/gofmt: don't permit -w with stdin

Also: use 0x644 file permission if a new file
is created (should not happen anymore, though).

LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/126610044
This commit is contained in:
Robert Griesemer 2014-08-25 15:29:47 -07:00
parent dff17f4617
commit 236cf308c2

View File

@ -122,7 +122,7 @@ func processFile(filename string, in io.Reader, out io.Writer, stdin bool) error
fmt.Fprintln(out, filename)
}
if *write {
err = ioutil.WriteFile(filename, res, 0)
err = ioutil.WriteFile(filename, res, 0644)
if err != nil {
return err
}
@ -186,6 +186,11 @@ func gofmtMain() {
initRewrite()
if flag.NArg() == 0 {
if *write {
fmt.Fprintln(os.Stderr, "error: cannot use -w with standard input")
exitCode = 2
return
}
if err := processFile("<standard input>", os.Stdin, os.Stdout, true); err != nil {
report(err)
}