Skip to content

Commit 27ccb41

Browse files
committed
godoc: accept symbolic links as path names provided to -path
When providing addition file systems to godoc via -path, the path names may be symbolic links. Follow them. Also: better logging of error and special conditions. R=r, dsymonds, r2 CC=golang-dev https://golang.org/cl/4217045
1 parent 176eb49 commit 27ccb41

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

src/cmd/godoc/dirtrees.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"go/parser"
1313
"go/token"
1414
"io/ioutil"
15+
"log"
1516
"os"
1617
pathutil "path"
1718
"strings"
@@ -100,7 +101,13 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
100101
return &Directory{depth, path, name, "", nil}
101102
}
102103

103-
list, _ := ioutil.ReadDir(path) // ignore errors
104+
list, err := ioutil.ReadDir(path)
105+
if err != nil {
106+
// newDirTree is called with a path that should be a package
107+
// directory; errors here should not happen, but if they do,
108+
// we want to know about them
109+
log.Printf("ioutil.ReadDir(%s): %s", path, err)
110+
}
104111

105112
// determine number of subdirectories and if there are package files
106113
ndirs := 0
@@ -188,8 +195,16 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
188195
// (i.e., in this case the tree may contain directories w/o any package files).
189196
//
190197
func newDirectory(root string, pathFilter func(string) bool, maxDepth int) *Directory {
191-
d, err := os.Lstat(root)
192-
if err != nil || !isPkgDir(d) {
198+
// The root could be a symbolic link so use os.Stat not os.Lstat.
199+
d, err := os.Stat(root)
200+
// If we fail here, report detailed error messages; otherwise
201+
// is is hard to see why a directory tree was not built.
202+
switch {
203+
case err != nil:
204+
log.Printf("newDirectory(%s): %s", root, err)
205+
return nil
206+
case !isPkgDir(d):
207+
log.Printf("newDirectory(%s): not a package directory", root)
193208
return nil
194209
}
195210
if maxDepth < 0 {

src/cmd/godoc/godoc.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,10 @@ func initDirTrees() {
213213
if *filter != "" {
214214
list, err := readDirList(*filter)
215215
if err != nil {
216-
log.Printf("%s", err)
217-
} else if len(list) == 0 {
218-
log.Printf("no directory paths in file %s", *filter)
216+
log.Printf("readDirList(%s): %s", *filter, err)
217+
}
218+
if *verbose || len(list) == 0 {
219+
log.Printf("found %d directory paths in file %s", len(list), *filter)
219220
}
220221
setPathFilter(list)
221222
}

0 commit comments

Comments
 (0)