Skip to content

Commit 34817dd

Browse files
oioojBryan C. Mills
authored and
Bryan C. Mills
committed
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/158117 Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 5fae09b commit 34817dd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/cmd/go/internal/clean/clean.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,9 @@ func runClean(cmd *base.Command, args []string) {
152152
prev, _ := strconv.ParseInt(strings.TrimSpace(string(buf)), 10, 64)
153153
if now > prev {
154154
if err = f.Truncate(0); err == nil {
155-
_, err = fmt.Fprintf(f, "%d\n", now)
155+
if _, err = f.Seek(0, 0); err == nil {
156+
_, err = fmt.Fprintf(f, "%d\n", now)
157+
}
156158
}
157159
}
158160
if closeErr := f.Close(); err == nil {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# go clean -testcache
2+
# should work (see golang.org/issue/29757).
3+
cd x
4+
go test x_test.go
5+
go clean -testcache
6+
go test x_test.go
7+
! stdout 'cached'
8+
9+
10+
-- x/x_test.go --
11+
package x_test
12+
import (
13+
"testing"
14+
)
15+
func TestMain(t *testing.T) {
16+
}

0 commit comments

Comments
 (0)