}
-// Maximum directory depth, adjust as needed.
-const maxDirDepth = 24
-
// 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
// subdirectories containing package files (transitively). If a non-nil
// pathFilter is provided, directory paths additionally must be accepted
-// by the filter (i.e., pathFilter(path) must be true). If maxDepth is
-// too shallow, the leaf nodes are assumed to contain package files even if
-// their contents are not known (i.e., in this case the tree may contain
-// directories w/o any package files).
+// by the filter (i.e., pathFilter(path) must be true). If a value >= 0 is
+// provided for maxDepth, nodes at larger depths are pruned as well; they
+// are assumed to contain package files even if their contents are not known
+// (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 {
d, err := os.Lstat(root)
if err != nil || !isPkgDir(d) {
return nil
}
+ if maxDepth < 0 {
+ maxDepth = 1e6 // "infinity"
+ }
b := treeBuilder{pathFilter, maxDepth}
return b.newDirTree(root, d.Name, 0)
}
// for each user-defined file system mapping, compute
// respective directory tree w/o filter for accuracy
fsMap.Iterate(func(path string, value *RWValue) bool {
- value.set(newDirectory(path, nil, maxDirDepth))
+ value.set(newDirectory(path, nil, -1))
return true
})
// for each user-defined file system mapping, compute
// respective directory tree quickly using pathFilter
go fsMap.Iterate(func(path string, value *RWValue) bool {
- value.set(newDirectory(path, getPathFilter(), maxDirDepth))
+ value.set(newDirectory(path, getPathFilter(), -1))
return true
})
}
}
if dir == nil {
- // no directory tree present (either early after startup
- // or command-line mode, or we don't have a tree for the
- // directory yet; e.g. google3); compute one level for this page
- dir = newDirectory(abspath, getPathFilter(), 1)
+ // no directory tree present (too early after startup or
+ // command-line mode); compute one level for this page
+ // note: cannot use path filter here because in general
+ // it doesn't contain the fsTree path
+ dir = newDirectory(abspath, nil, 1)
}
return PageInfo{abspath, plist, past, pdoc, dir.listing(true), h.isPkg, nil}
// TODO(gri): The directory tree may be temporarily out-of-sync.
// Consider keeping separate time stamps so the web-
// page can indicate this discrepancy.
- fsTree.set(newDirectory(*goroot, nil, maxDirDepth))
+ fsTree.set(newDirectory(*goroot, nil, -1))
fallthrough
case 1:
// sync failed because no files changed;
// 1) set timestamp right away so that the indexer is kicked on
fsTree.set(nil)
// 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).
initDirTrees()