Commit 236cf308 authored by Robert Griesemer's avatar Robert Griesemer

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
parent dff17f46
......@@ -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)
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment