1
0
mirror of https://github.com/golang/go synced 2024-11-22 02:04:40 -07:00

godoc: better handling of deep directory trees

also: fix a logic error with filter use at startup

R=rsc
CC=golang-dev
https://golang.org/cl/2184044
This commit is contained in:
Robert Griesemer 2010-09-14 18:58:09 -07:00
parent 4398768b84
commit 7f0ddd682a
3 changed files with 16 additions and 15 deletions

View File

@ -171,24 +171,24 @@ func (b *treeBuilder) newDirTree(path, name string, depth int) *Directory {
} }
// Maximum directory depth, adjust as needed.
const maxDirDepth = 24
// newDirectory creates a new package directory tree with at most maxDepth // newDirectory creates a new package directory tree with at most maxDepth
// levels, anchored at root. The result tree is pruned such that it only // levels, anchored at root. The result tree is pruned such that it only
// contains directories that contain package files or that contain // contains directories that contain package files or that contain
// subdirectories containing package files (transitively). If a non-nil // subdirectories containing package files (transitively). If a non-nil
// pathFilter is provided, directory paths additionally must be accepted // pathFilter is provided, directory paths additionally must be accepted
// by the filter (i.e., pathFilter(path) must be true). If maxDepth is // by the filter (i.e., pathFilter(path) must be true). If a value >= 0 is
// too shallow, the leaf nodes are assumed to contain package files even if // provided for maxDepth, nodes at larger depths are pruned as well; they
// their contents are not known (i.e., in this case the tree may contain // are assumed to contain package files even if their contents are not known
// 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) d, err := os.Lstat(root)
if err != nil || !isPkgDir(d) { if err != nil || !isPkgDir(d) {
return nil return nil
} }
if maxDepth < 0 {
maxDepth = 1e6 // "infinity"
}
b := treeBuilder{pathFilter, maxDepth} b := treeBuilder{pathFilter, maxDepth}
return b.newDirTree(root, d.Name, 0) return b.newDirTree(root, d.Name, 0)
} }

View File

@ -155,7 +155,7 @@ func updateFilterFile() {
// for each user-defined file system mapping, compute // for each user-defined file system mapping, compute
// respective directory tree w/o filter for accuracy // respective directory tree w/o filter for accuracy
fsMap.Iterate(func(path string, value *RWValue) bool { fsMap.Iterate(func(path string, value *RWValue) bool {
value.set(newDirectory(path, nil, maxDirDepth)) value.set(newDirectory(path, nil, -1))
return true return true
}) })
@ -194,7 +194,7 @@ func initDirTrees() {
// for each user-defined file system mapping, compute // for each user-defined file system mapping, compute
// respective directory tree quickly using pathFilter // respective directory tree quickly using pathFilter
go fsMap.Iterate(func(path string, value *RWValue) bool { go fsMap.Iterate(func(path string, value *RWValue) bool {
value.set(newDirectory(path, getPathFilter(), maxDirDepth)) value.set(newDirectory(path, getPathFilter(), -1))
return true return true
}) })
@ -1203,10 +1203,11 @@ func (h *httpHandler) getPageInfo(abspath, relpath, pkgname string, mode PageInf
} }
} }
if dir == nil { if dir == nil {
// no directory tree present (either early after startup // no directory tree present (too early after startup or
// or command-line mode, or we don't have a tree for the // command-line mode); compute one level for this page
// directory yet; e.g. google3); compute one level for this page // note: cannot use path filter here because in general
dir = newDirectory(abspath, getPathFilter(), 1) // it doesn't contain the fsTree path
dir = newDirectory(abspath, nil, 1)
} }
return PageInfo{abspath, plist, past, pdoc, dir.listing(true), h.isPkg, nil} return PageInfo{abspath, plist, past, pdoc, dir.listing(true), h.isPkg, nil}

View File

@ -127,7 +127,7 @@ func dosync(c *http.Conn, r *http.Request) {
// TODO(gri): The directory tree may be temporarily out-of-sync. // TODO(gri): The directory tree may be temporarily out-of-sync.
// Consider keeping separate time stamps so the web- // Consider keeping separate time stamps so the web-
// page can indicate this discrepancy. // page can indicate this discrepancy.
fsTree.set(newDirectory(*goroot, nil, maxDirDepth)) fsTree.set(newDirectory(*goroot, nil, -1))
fallthrough fallthrough
case 1: case 1:
// sync failed because no files changed; // sync failed because no files changed;
@ -259,7 +259,7 @@ func main() {
// 1) set timestamp right away so that the indexer is kicked on // 1) set timestamp right away so that the indexer is kicked on
fsTree.set(nil) fsTree.set(nil)
// 2) compute initial directory tree in a goroutine so that launch is quick // 2) compute initial directory tree in a goroutine so that launch is quick
go func() { fsTree.set(newDirectory(*goroot, nil, maxDirDepth)) }() go func() { fsTree.set(newDirectory(*goroot, nil, -1)) }()
// Initialize directory trees for user-defined file systems (-path flag). // Initialize directory trees for user-defined file systems (-path flag).
initDirTrees() initDirTrees()