From 236cf308c298b49d64d32a76f5ee242a2b3bc1b4 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 25 Aug 2014 15:29:47 -0700 Subject: [PATCH] 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 --- src/cmd/gofmt/gofmt.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index f7d30d84052..f322a2b0a07 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -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("", os.Stdin, os.Stdout, true); err != nil { report(err) }