]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/cache: remove log.txt from the cache directory
authorBryan C. Mills <bcmills@google.com>
Fri, 15 Mar 2019 13:10:09 +0000 (09:10 -0400)
committerBryan C. Mills <bcmills@google.com>
Fri, 15 Mar 2019 21:25:01 +0000 (21:25 +0000)
Also remove an existing log.txt in the cache directory during
'go clean -cache' if it exists.

Fixes #25323

Change-Id: I1c6e20554db0edc6d850a7b4379d71ef5844eaea
Reviewed-on: https://go-review.googlesource.com/c/go/+/167741
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
src/cmd/go/internal/cache/cache.go
src/cmd/go/internal/cache/cache_test.go
src/cmd/go/internal/clean/clean.go

index ab84cf6302c0d1ec952db6dc0a53bfb7a84aad8e..3e386a08815d832d9a0698db65bac3c4ed9e84b3 100644 (file)
@@ -33,7 +33,6 @@ type OutputID [HashSize]byte
 // A Cache is a package cache, backed by a file system directory tree.
 type Cache struct {
        dir string
-       log *os.File
        now func() time.Time
 }
 
@@ -63,13 +62,8 @@ func Open(dir string) (*Cache, error) {
                        return nil, err
                }
        }
-       f, err := os.OpenFile(filepath.Join(dir, "log.txt"), os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
-       if err != nil {
-               return nil, err
-       }
        c := &Cache{
                dir: dir,
-               log: f,
                now: time.Now,
        }
        return c, nil
@@ -141,7 +135,6 @@ type Entry struct {
 // get is Get but does not respect verify mode, so that Put can use it.
 func (c *Cache) get(id ActionID) (Entry, error) {
        missing := func() (Entry, error) {
-               fmt.Fprintf(c.log, "%d miss %x\n", c.now().Unix(), id)
                return Entry{}, errMissing
        }
        f, err := os.Open(c.fileName(id, "a"))
@@ -184,8 +177,6 @@ func (c *Cache) get(id ActionID) (Entry, error) {
                return missing()
        }
 
-       fmt.Fprintf(c.log, "%d get %x\n", c.now().Unix(), id)
-
        c.used(c.fileName(id, "a"))
 
        return Entry{buf, size, time.Unix(0, tm)}, nil
@@ -349,7 +340,6 @@ func (c *Cache) putIndexEntry(id ActionID, out OutputID, size int64, allowVerify
        }
        os.Chtimes(file, c.now(), c.now()) // mainly for tests
 
-       fmt.Fprintf(c.log, "%d put %x %x %d\n", c.now().Unix(), id, out, size)
        return nil
 }
 
index d3dafccd137f2116c228862f08179a4bea3162e5..7229bc4cec49c335cff2e23633bc56f001f2b791 100644 (file)
@@ -144,55 +144,6 @@ func TestVerifyPanic(t *testing.T) {
        t.Fatal("mismatched Put did not panic in verify mode")
 }
 
-func TestCacheLog(t *testing.T) {
-       dir, err := ioutil.TempDir("", "cachetest-")
-       if err != nil {
-               t.Fatal(err)
-       }
-       defer os.RemoveAll(dir)
-
-       c, err := Open(dir)
-       if err != nil {
-               t.Fatalf("Open: %v", err)
-       }
-       c.now = func() time.Time { return time.Unix(1e9, 0) }
-
-       id := ActionID(dummyID(1))
-       c.Get(id)
-       c.PutBytes(id, []byte("abc"))
-       c.Get(id)
-
-       c, err = Open(dir)
-       if err != nil {
-               t.Fatalf("Open #2: %v", err)
-       }
-       c.now = func() time.Time { return time.Unix(1e9+1, 0) }
-       c.Get(id)
-
-       id2 := ActionID(dummyID(2))
-       c.Get(id2)
-       c.PutBytes(id2, []byte("abc"))
-       c.Get(id2)
-       c.Get(id)
-
-       data, err := ioutil.ReadFile(filepath.Join(dir, "log.txt"))
-       if err != nil {
-               t.Fatal(err)
-       }
-       want := `1000000000 miss 0100000000000000000000000000000000000000000000000000000000000000
-1000000000 put 0100000000000000000000000000000000000000000000000000000000000000 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad 3
-1000000000 get 0100000000000000000000000000000000000000000000000000000000000000
-1000000001 get 0100000000000000000000000000000000000000000000000000000000000000
-1000000001 miss 0200000000000000000000000000000000000000000000000000000000000000
-1000000001 put 0200000000000000000000000000000000000000000000000000000000000000 ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad 3
-1000000001 get 0200000000000000000000000000000000000000000000000000000000000000
-1000000001 get 0100000000000000000000000000000000000000000000000000000000000000
-`
-       if string(data) != want {
-               t.Fatalf("log:\n%s\nwant:\n%s", string(data), want)
-       }
-}
-
 func dummyID(x int) [HashSize]byte {
        var out [HashSize]byte
        binary.LittleEndian.PutUint64(out[:], uint64(x))
index 3389d5f18b591b49156f5742d3b9fa0f4853a3f2..f7d80ff6dc8a13074110e28408dc54268dccbf66 100644 (file)
@@ -132,11 +132,11 @@ func runClean(cmd *base.Command, args []string) {
                        // and not something that we want to remove. Also, we'd like to preserve
                        // the access log for future analysis, even if the cache is cleared.
                        subdirs, _ := filepath.Glob(filepath.Join(dir, "[0-9a-f][0-9a-f]"))
+                       printedErrors := false
                        if len(subdirs) > 0 {
                                if cfg.BuildN || cfg.BuildX {
                                        b.Showcmd("", "rm -r %s", strings.Join(subdirs, " "))
                                }
-                               printedErrors := false
                                for _, d := range subdirs {
                                        // Only print the first error - there may be many.
                                        // This also mimics what os.RemoveAll(dir) would do.
@@ -146,6 +146,12 @@ func runClean(cmd *base.Command, args []string) {
                                        }
                                }
                        }
+
+                       logFile := filepath.Join(dir, "log.txt")
+                       if err := os.RemoveAll(logFile); err != nil && !printedErrors {
+                               printedErrors = true
+                               base.Errorf("go clean -cache: %v", err)
+                       }
                }
        }