internal/godoc: delete RootType

We no longer use GOPATH at all, so all that matters is whether
the directory is GOROOT or not. We don't need the file system
to tell us - we can check whether a known file exists, like
src/math/abs.go.

Change-Id: I9d4efb9d0d3882a4875aa7176ce21ed24ede3f4d
Reviewed-on: https://go-review.googlesource.com/c/website/+/293428
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/_content/lib/godoc/packageroot.html b/_content/lib/godoc/packageroot.html
index c246c79..c7caaba 100644
--- a/_content/lib/godoc/packageroot.html
+++ b/_content/lib/godoc/packageroot.html
@@ -48,7 +48,7 @@
 
 						{{range .List}}
 							<tr>
-							{{if eq .RootType "GOROOT"}}
+							{{if .IsGOROOT}}
 							{{if $.DirFlat}}
 								{{if .HasPkg}}
 										<td class="pkg-name">
diff --git a/internal/godoc/dirtrees.go b/internal/godoc/dirtrees.go
index 54ace12..387d09c 100644
--- a/internal/godoc/dirtrees.go
+++ b/internal/godoc/dirtrees.go
@@ -31,7 +31,7 @@
 	Name     string       // directory name
 	HasPkg   bool         // true if the directory contains at least one package
 	Synopsis string       // package documentation, if any
-	RootType vfs.RootType // root type of the filesystem containing the directory
+	IsGOROOT bool         // is this GOROOT
 	Dirs     []*Directory // subdirectories
 }
 
@@ -203,11 +203,16 @@
 		Name:     name,
 		HasPkg:   hasPkgFiles && show, // TODO(bradfitz): add proper Hide field?
 		Synopsis: synopsis,
-		RootType: b.c.fs.RootType(path),
+		IsGOROOT: isGOROOT(b.c.fs),
 		Dirs:     dirs,
 	}
 }
 
+func isGOROOT(fs vfs.FileSystem) bool {
+	_, err := fs.Lstat("src/math/abs.go")
+	return err == nil
+}
+
 // newDirectory creates a new package directory tree with at most maxDepth
 // levels, anchored at root. The result tree is pruned such that it only
 // contains directories that contain package files or that contain
@@ -302,13 +307,13 @@
 // are useful for presenting an entry in an indented fashion.
 //
 type DirEntry struct {
-	Depth    int          // >= 0
-	Height   int          // = DirList.MaxHeight - Depth, > 0
-	Path     string       // directory path; includes Name, relative to DirList root
-	Name     string       // directory name
-	HasPkg   bool         // true if the directory contains at least one package
-	Synopsis string       // package documentation, if any
-	RootType vfs.RootType // root type of the filesystem containing the direntry
+	Depth    int    // >= 0
+	Height   int    // = DirList.MaxHeight - Depth, > 0
+	Path     string // directory path; includes Name, relative to DirList root
+	Name     string // directory name
+	HasPkg   bool   // true if the directory contains at least one package
+	Synopsis string // package documentation, if any
+	IsGOROOT bool   // root type of the filesystem containing the direntry
 }
 
 type DirList struct {
@@ -319,11 +324,6 @@
 // hasThirdParty checks whether a list of directory entries has packages outside
 // the standard library or not.
 func hasThirdParty(list []DirEntry) bool {
-	for _, entry := range list {
-		if entry.RootType == vfs.RootTypeGoPath {
-			return true
-		}
-	}
 	return false
 }
 
@@ -375,7 +375,7 @@
 		p.Name = d.Name
 		p.HasPkg = d.HasPkg
 		p.Synopsis = d.Synopsis
-		p.RootType = d.RootType
+		p.IsGOROOT = d.IsGOROOT
 		list = append(list, p)
 	}
 
diff --git a/internal/godoc/dirtrees_test.go b/internal/godoc/dirtrees_test.go
index 3fd5cfa..552fe86 100644
--- a/internal/godoc/dirtrees_test.go
+++ b/internal/godoc/dirtrees_test.go
@@ -62,3 +62,20 @@
 		corpus.newDirectory("/", -1)
 	}
 }
+
+func TestIsGOROOT(t *testing.T) {
+	tests := []struct {
+		path     string
+		isGOROOT bool
+	}{
+		{runtime.GOROOT(), true},
+		{"/tmp/", false},
+	}
+
+	for _, item := range tests {
+		fs := vfs.OS(item.path)
+		if isGOROOT(fs) != item.isGOROOT {
+			t.Errorf("%s: isGOROOT = %v, want %v", item.path, !item.isGOROOT, item.isGOROOT)
+		}
+	}
+}
diff --git a/internal/godoc/vfs/emptyvfs.go b/internal/godoc/vfs/emptyvfs.go
index 8712d5e..24954b1 100644
--- a/internal/godoc/vfs/emptyvfs.go
+++ b/internal/godoc/vfs/emptyvfs.go
@@ -57,10 +57,6 @@
 	return "emptyVFS(/)"
 }
 
-func (e *emptyVFS) RootType(path string) RootType {
-	return ""
-}
-
 // These functions below implement os.FileInfo for the single
 // empty emulated directory.
 
diff --git a/internal/godoc/vfs/fs.go b/internal/godoc/vfs/fs.go
index f12d653..2f122b9 100644
--- a/internal/godoc/vfs/fs.go
+++ b/internal/godoc/vfs/fs.go
@@ -50,8 +50,6 @@
 	return fs.Stat(f.fsys, f.fsPath(name))
 }
 
-func (f *fsysToFileSystem) RootType(name string) RootType { return "" }
-
 func (f *fsysToFileSystem) ReadDir(name string) ([]os.FileInfo, error) {
 	dirs, err := fs.ReadDir(f.fsys, f.fsPath(name))
 	var infos []os.FileInfo
diff --git a/internal/godoc/vfs/gatefs/gatefs.go b/internal/godoc/vfs/gatefs/gatefs.go
index 0ed1906..1c2d8fa 100644
--- a/internal/godoc/vfs/gatefs/gatefs.go
+++ b/internal/godoc/vfs/gatefs/gatefs.go
@@ -37,10 +37,6 @@
 	return fmt.Sprintf("gated(%s, %d)", fs.fs.String(), cap(fs.gate))
 }
 
-func (fs gatefs) RootType(path string) vfs.RootType {
-	return fs.fs.RootType(path)
-}
-
 func (fs gatefs) Open(p string) (vfs.ReadSeekCloser, error) {
 	fs.enter()
 	defer fs.leave()
diff --git a/internal/godoc/vfs/gatefs/gatefs_test.go b/internal/godoc/vfs/gatefs/gatefs_test.go
deleted file mode 100644
index 94d7814..0000000
--- a/internal/godoc/vfs/gatefs/gatefs_test.go
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package gatefs_test
-
-import (
-	"os"
-	"runtime"
-	"testing"
-
-	"golang.org/x/website/internal/godoc/vfs"
-	"golang.org/x/website/internal/godoc/vfs/gatefs"
-)
-
-func TestRootType(t *testing.T) {
-	goPath := os.Getenv("GOPATH")
-	var expectedType vfs.RootType
-	if goPath == "" {
-		expectedType = ""
-	} else {
-		expectedType = vfs.RootTypeGoPath
-	}
-	tests := []struct {
-		path   string
-		fsType vfs.RootType
-	}{
-		{runtime.GOROOT(), vfs.RootTypeGoRoot},
-		{goPath, expectedType},
-		{"/tmp/", ""},
-	}
-
-	for _, item := range tests {
-		fs := gatefs.New(vfs.OS(item.path), make(chan bool, 1))
-		if fs.RootType("path") != item.fsType {
-			t.Errorf("unexpected fsType. Expected- %v, Got- %v", item.fsType, fs.RootType("path"))
-		}
-	}
-}
diff --git a/internal/godoc/vfs/mapfs/mapfs.go b/internal/godoc/vfs/mapfs/mapfs.go
index aba9787..e0aebe3 100644
--- a/internal/godoc/vfs/mapfs/mapfs.go
+++ b/internal/godoc/vfs/mapfs/mapfs.go
@@ -42,10 +42,6 @@
 
 func (fs mapFS) String() string { return "mapfs" }
 
-func (fs mapFS) RootType(p string) vfs.RootType {
-	return ""
-}
-
 func (fs mapFS) Close() error { return nil }
 
 func filename(p string) string {
diff --git a/internal/godoc/vfs/namespace.go b/internal/godoc/vfs/namespace.go
index 32c8259..38a6358 100644
--- a/internal/godoc/vfs/namespace.go
+++ b/internal/godoc/vfs/namespace.go
@@ -367,20 +367,6 @@
 	return all, nil
 }
 
-// RootType returns the RootType for the given path in the namespace.
-func (ns NameSpace) RootType(path string) RootType {
-	// We resolve the given path to a list of mountedFS and then return
-	// the root type for the filesystem which contains the path.
-	for _, m := range ns.resolve(path) {
-		_, err := m.fs.ReadDir(m.translate(path))
-		// Found a match, return the filesystem's root type
-		if err == nil {
-			return m.fs.RootType(path)
-		}
-	}
-	return ""
-}
-
 // byName implements sort.Interface.
 type byName []os.FileInfo
 
diff --git a/internal/godoc/vfs/os.go b/internal/godoc/vfs/os.go
index 35d0509..7b6025b 100644
--- a/internal/godoc/vfs/os.go
+++ b/internal/godoc/vfs/os.go
@@ -6,7 +6,6 @@
 
 import (
 	"fmt"
-	"go/build"
 	"io/ioutil"
 	"os"
 	pathpkg "path"
@@ -28,43 +27,15 @@
 // passed to Open has no way to specify a drive letter.  Using a root
 // lets code refer to OS(`c:\`), OS(`d:\`) and so on.
 func OS(root string) FileSystem {
-	var t RootType
-	switch {
-	case root == GOROOT:
-		t = RootTypeGoRoot
-	case isGoPath(root):
-		t = RootTypeGoPath
-	}
-	return osFS{rootPath: root, rootType: t}
+	return osFS{rootPath: root}
 }
 
 type osFS struct {
 	rootPath string
-	rootType RootType
-}
-
-func isGoPath(path string) bool {
-	for _, bp := range filepath.SplitList(build.Default.GOPATH) {
-		for _, gp := range filepath.SplitList(path) {
-			if bp == gp {
-				return true
-			}
-		}
-	}
-	return false
 }
 
 func (root osFS) String() string { return "os(" + root.rootPath + ")" }
 
-// RootType returns the root type for the filesystem.
-//
-// Note that we ignore the path argument because roottype is a property of
-// this filesystem. But for other filesystems, the roottype might need to be
-// dynamically deduced at call time.
-func (root osFS) RootType(path string) RootType {
-	return root.rootType
-}
-
 func (root osFS) resolve(path string) string {
 	// Clean the path so that it cannot possibly begin with ../.
 	// If it did, the result of filepath.Join would be outside the
diff --git a/internal/godoc/vfs/os_test.go b/internal/godoc/vfs/os_test.go
deleted file mode 100644
index 548923e..0000000
--- a/internal/godoc/vfs/os_test.go
+++ /dev/null
@@ -1,38 +0,0 @@
-// Copyright 2018 The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE file.
-
-package vfs_test
-
-import (
-	"os"
-	"runtime"
-	"testing"
-
-	"golang.org/x/website/internal/godoc/vfs"
-)
-
-func TestRootType(t *testing.T) {
-	goPath := os.Getenv("GOPATH")
-	var expectedType vfs.RootType
-	if goPath == "" {
-		expectedType = ""
-	} else {
-		expectedType = vfs.RootTypeGoPath
-	}
-	tests := []struct {
-		path   string
-		fsType vfs.RootType
-	}{
-		{runtime.GOROOT(), vfs.RootTypeGoRoot},
-		{goPath, expectedType},
-		{"/tmp/", ""},
-	}
-
-	for _, item := range tests {
-		fs := vfs.OS(item.path)
-		if fs.RootType("path") != item.fsType {
-			t.Errorf("unexpected fsType. Expected- %v, Got- %v", item.fsType, fs.RootType("path"))
-		}
-	}
-}
diff --git a/internal/godoc/vfs/vfs.go b/internal/godoc/vfs/vfs.go
index 9f0001f..ecc54d0 100644
--- a/internal/godoc/vfs/vfs.go
+++ b/internal/godoc/vfs/vfs.go
@@ -12,18 +12,6 @@
 	"os"
 )
 
-// RootType indicates the type of files contained within a directory.
-//
-// It is used to indicate whether a directory is the root
-// of a GOROOT, a GOPATH, or neither.
-// An empty string represents the case when a directory is neither.
-type RootType string
-
-const (
-	RootTypeGoRoot RootType = "GOROOT"
-	RootTypeGoPath RootType = "GOPATH"
-)
-
 // The FileSystem interface specifies the methods godoc is using
 // to access the file system for which it serves documentation.
 type FileSystem interface {
@@ -31,7 +19,6 @@
 	Lstat(path string) (os.FileInfo, error)
 	Stat(path string) (os.FileInfo, error)
 	ReadDir(path string) ([]os.FileInfo, error)
-	RootType(path string) RootType
 	String() string
 }