Commit da8efae9 authored by Russ Cox's avatar Russ Cox

cmd/godoc: fix directory read

Undo CL 5783076 and apply correct fix.

The /doc hack is wrong.  The code to handle this case was
already there and just needs a simple fix:

 	// We didn't find any directories containing Go files.
 	// If some directory returned successfully, use that.
-	if len(all) == 0 && first != nil {
+	if !haveGo {
 		for _, d := range first {
 			haveName[d.Name()] = true
 			all = append(all, d)

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/5783079
parent 376fc748
...@@ -420,17 +420,11 @@ func (ns nameSpace) ReadDir(path string) ([]os.FileInfo, error) { ...@@ -420,17 +420,11 @@ func (ns nameSpace) ReadDir(path string) ([]os.FileInfo, error) {
first = dir first = dir
} }
useFiles := false
// Always include all files under /doc.
if path == "/doc" || strings.HasPrefix(path, "/doc/") {
useFiles = true // always include docs
}
// If we don't yet have Go files in 'all' and this directory // If we don't yet have Go files in 'all' and this directory
// has some, add all the files from this directory. // has some, add all the files from this directory.
// Otherwise, only add subdirectories. // Otherwise, only add subdirectories.
if !useFiles && !haveGo { useFiles := false
if !haveGo {
for _, d := range dir { for _, d := range dir {
if strings.HasSuffix(d.Name(), ".go") { if strings.HasSuffix(d.Name(), ".go") {
useFiles = true useFiles = true
...@@ -451,12 +445,14 @@ func (ns nameSpace) ReadDir(path string) ([]os.FileInfo, error) { ...@@ -451,12 +445,14 @@ func (ns nameSpace) ReadDir(path string) ([]os.FileInfo, error) {
// We didn't find any directories containing Go files. // We didn't find any directories containing Go files.
// If some directory returned successfully, use that. // If some directory returned successfully, use that.
if len(all) == 0 && first != nil { if !haveGo {
for _, d := range first { for _, d := range first {
if !haveName[d.Name()] {
haveName[d.Name()] = true haveName[d.Name()] = true
all = append(all, d) all = append(all, d)
} }
} }
}
// Built union. Add any missing directories needed to reach mount points. // Built union. Add any missing directories needed to reach mount points.
for old := range ns { for old := range ns {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment