]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/clean: fix clean -testcache does not clean test cache
authorBaokun Lee <nototon@gmail.com>
Wed, 16 Jan 2019 10:53:35 +0000 (18:53 +0800)
committerBryan C. Mills <bcmills@google.com>
Wed, 16 Jan 2019 14:03:10 +0000 (14:03 +0000)
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 <bcmills@google.com>
src/cmd/go/internal/clean/clean.go
src/cmd/go/testdata/script/clean_testcache.txt [new file with mode: 0644]

index 32cc80736df4b84796f9e7bc3784aebbcb7fe274..27121ed2ae679b1cfc155852065aca41622bfd3c 100644 (file)
@@ -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 {
diff --git a/src/cmd/go/testdata/script/clean_testcache.txt b/src/cmd/go/testdata/script/clean_testcache.txt
new file mode 100644 (file)
index 0000000..a2d592d
--- /dev/null
@@ -0,0 +1,16 @@
+# 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