]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gofmt: don't permit -w with stdin
authorRobert Griesemer <gri@golang.org>
Mon, 25 Aug 2014 22:29:47 +0000 (15:29 -0700)
committerRobert Griesemer <gri@golang.org>
Mon, 25 Aug 2014 22:29:47 +0000 (15:29 -0700)
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

index f7d30d8405276423523f3546a05eedc4569998ea..f322a2b0a0734a37a8abca53a0f0315a554a1133 100644 (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)
                }