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

     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  go build -o roe$GOEXE ./remove_output_entries.go
     8  
     9  # populate new cache
    10  env GOCACHE=$WORK/newcache
    11  go list runtime
    12  
    13  # remove output entries and check the panic doesn't happen
    14  exec ./roe$GOEXE $WORK/newcache
    15  go list runtime
    16  
    17  -- remove_output_entries.go --
    18  package main
    19  
    20  import (
    21  	"io/fs"
    22  	"log"
    23  	"os"
    24  	"path/filepath"
    25  	"strings"
    26  )
    27  
    28  func main() {
    29  	cachedir := os.Args[1]
    30  	err := filepath.WalkDir(cachedir, func(path string, d fs.DirEntry, err error) error {
    31  		if strings.HasSuffix(path, "-d") { // output entries end in "-d"
    32  			if err := os.RemoveAll(path); err != nil {
    33  				return err
    34  			}
    35  		}
    36  		return nil
    37  	})
    38  	if err != nil {
    39  		log.Fatal(err)
    40  	}
    41  }

View as plain text