Commit 34817dd3 authored by Baokun Lee's avatar Baokun Lee Committed by Bryan C. Mills

cmd/go/internal/clean: fix clean -testcache does not clean test cache

Truncate changes the size of the file. It does not change the I/O offset.

Fixes #29757

Change-Id: I1aa9223a86d6a8ce3c0efc3ac1d7d7647b77f589
Reviewed-on: https://go-review.googlesource.com/c/158117Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent 5fae09b7
......@@ -152,7 +152,9 @@ func runClean(cmd *base.Command, args []string) {
prev, _ := strconv.ParseInt(strings.TrimSpace(string(buf)), 10, 64)
if now > prev {
if err = f.Truncate(0); err == nil {
_, err = fmt.Fprintf(f, "%d\n", now)
if _, err = f.Seek(0, 0); err == nil {
_, err = fmt.Fprintf(f, "%d\n", now)
}
}
}
if closeErr := f.Close(); err == nil {
......
# go clean -testcache
# should work (see golang.org/issue/29757).
cd x
go test x_test.go
go clean -testcache
go test x_test.go
! stdout 'cached'
-- x/x_test.go --
package x_test
import (
"testing"
)
func TestMain(t *testing.T) {
}
\ No newline at end of file
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