Skip to content

x/tools/cmd/goimports: truncates input file despite no -w flag #28270

@myitcv

Description

@myitcv

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11.1 linux/amd64

Using goimports as of https://go-review.googlesource.com/c/tools/+/142697, specifically patch set 5:

git fetch https://go.googlesource.com/tools refs/changes/97/142697/5 && git checkout FETCH_HEAD

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/myitcv/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/myitcv/gostuff"
GOPROXY=""
GORACE=""
GOROOT="/home/myitcv/gos"
GOTMPDIR=""
GOTOOLDIR="/home/myitcv/gos/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build893028818=/tmp/go-build -gno-record-gcc-switches"

What did you do?

goimports was "hanging" on this input file so I switched out of my editor and ran this sequence of commands:

$ goimports main.go
(killed with Ctrl-c)
$ gofmt main.go
...
$ goimports -help
...
$ goimports -v -trace main.go
(killed with Ctrl-c)
$ goimports -v main.go 

This last call ran very fast; too fast because main.go had, by this point, been truncated to zero length.

Unfortunately I can't provide a precise repo because the contents of the truncated file have been lost 😄

What did you expect to see?

The input file not to be truncated; no -w flag was provided.

What did you see instead?

Per above.

cc @ianthehat @heschik

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions