...

Text file src/cmd/go/testdata/script/list_issue_70600.txt

Documentation: cmd/go/testdata/script

     1# Test that the go command does not panic if it tries to read
     2# a file from the cache that has an index entry, but is missing
     3# an entry for the output. This test creates that situation by
     4# running a go list (creating index and output cache entries for
     5# the module index) and then removing just the output entries.
     6
     7[short] skip 'runs go build'
     8
     9go build -o roe$GOEXE ./remove_output_entries.go
    10
    11# populate new cache
    12env GOCACHE=$WORK/newcache
    13go list runtime
    14
    15# remove output entries and check the panic doesn't happen
    16exec ./roe$GOEXE $WORK/newcache
    17go list runtime
    18
    19-- remove_output_entries.go --
    20package main
    21
    22import (
    23	"io/fs"
    24	"log"
    25	"os"
    26	"path/filepath"
    27	"strings"
    28)
    29
    30func main() {
    31	cachedir := os.Args[1]
    32	err := filepath.WalkDir(cachedir, func(path string, d fs.DirEntry, err error) error {
    33		if strings.HasSuffix(path, "-d") { // output entries end in "-d"
    34			if err := os.RemoveAll(path); err != nil {
    35				return err
    36			}
    37		}
    38		return nil
    39	})
    40	if err != nil {
    41		log.Fatal(err)
    42	}
    43}

View as plain text