mirror of
https://github.com/golang/go.git
synced 2024-10-02 07:47:11 +00:00
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
This commit is contained in:
parent
176eb49d9c
commit
27ccb41c4a
@ -12,6 +12,7 @@ import (
|
|||||||
"go/parser"
|
"go/parser"
|
||||||
"go/token"
|
"go/token"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
pathutil "path"
|
pathutil "path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -100,7 +101,13 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
|
|||||||
return &Directory{depth, path, name, "", nil}
|
return &Directory{depth, path, name, "", nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
list, _ := ioutil.ReadDir(path) // ignore errors
|
list, err := ioutil.ReadDir(path)
|
||||||
|
if err != nil {
|
||||||
|
// newDirTree is called with a path that should be a package
|
||||||
|
// directory; errors here should not happen, but if they do,
|
||||||
|
// we want to know about them
|
||||||
|
log.Printf("ioutil.ReadDir(%s): %s", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
// determine number of subdirectories and if there are package files
|
// determine number of subdirectories and if there are package files
|
||||||
ndirs := 0
|
ndirs := 0
|
||||||
@ -188,8 +195,16 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
|
|||||||
// (i.e., in this case the tree may contain directories w/o any package files).
|
// (i.e., in this case the tree may contain directories w/o any package files).
|
||||||
//
|
//
|
||||||
func newDirectory(root string, pathFilter func(string) bool, maxDepth int) *Directory {
|
func newDirectory(root string, pathFilter func(string) bool, maxDepth int) *Directory {
|
||||||
d, err := os.Lstat(root)
|
// The root could be a symbolic link so use os.Stat not os.Lstat.
|
||||||
if err != nil || !isPkgDir(d) {
|
d, err := os.Stat(root)
|
||||||
|
// If we fail here, report detailed error messages; otherwise
|
||||||
|
// is is hard to see why a directory tree was not built.
|
||||||
|
switch {
|
||||||
|
case err != nil:
|
||||||
|
log.Printf("newDirectory(%s): %s", root, err)
|
||||||
|
return nil
|
||||||
|
case !isPkgDir(d):
|
||||||
|
log.Printf("newDirectory(%s): not a package directory", root)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if maxDepth < 0 {
|
if maxDepth < 0 {
|
||||||
|
@ -213,9 +213,10 @@ func initDirTrees() {
|
|||||||
if *filter != "" {
|
if *filter != "" {
|
||||||
list, err := readDirList(*filter)
|
list, err := readDirList(*filter)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("%s", err)
|
log.Printf("readDirList(%s): %s", *filter, err)
|
||||||
} else if len(list) == 0 {
|
}
|
||||||
log.Printf("no directory paths in file %s", *filter)
|
if *verbose || len(list) == 0 {
|
||||||
|
log.Printf("found %d directory paths in file %s", len(list), *filter)
|
||||||
}
|
}
|
||||||
setPathFilter(list)
|
setPathFilter(list)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user