~john-koepi/ubuntu/trusty/golang/default

« back to all changes in this revision

Viewing changes to src/cmd/godoc/dirtrees.go

  • Committer: Bazaar Package Importer
  • Author(s): Ondřej Surý
  • Date: 2011-08-03 17:04:59 UTC
  • mfrom: (14.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20110803170459-wzd99m3567y80ila
Tags: 1:59-1
* Imported Upstream version 59
* Refresh patches to a new release
* Fix FTBFS on ARM (Closes: #634270)
* Update version.bash to work with Debian packaging and not hg
  repository

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
        "go/doc"
12
12
        "go/parser"
13
13
        "go/token"
14
 
        "io/ioutil"
15
14
        "log"
16
 
        "os"
17
15
        "path/filepath"
18
16
        "strings"
19
17
        "unicode"
29
27
}
30
28
 
31
29
 
32
 
func isGoFile(f *os.FileInfo) bool {
33
 
        return f.IsRegular() &&
34
 
                !strings.HasPrefix(f.Name, ".") && // ignore .files
35
 
                filepath.Ext(f.Name) == ".go"
36
 
}
37
 
 
38
 
 
39
 
func isPkgFile(f *os.FileInfo) bool {
40
 
        return isGoFile(f) &&
41
 
                !strings.HasSuffix(f.Name, "_test.go") // ignore test files
42
 
}
43
 
 
44
 
 
45
 
func isPkgDir(f *os.FileInfo) bool {
46
 
        return f.IsDirectory() && len(f.Name) > 0 && f.Name[0] != '_'
 
30
func isGoFile(fi FileInfo) bool {
 
31
        name := fi.Name()
 
32
        return fi.IsRegular() &&
 
33
                len(name) > 0 && name[0] != '.' && // ignore .files
 
34
                filepath.Ext(name) == ".go"
 
35
}
 
36
 
 
37
 
 
38
func isPkgFile(fi FileInfo) bool {
 
39
        return isGoFile(fi) &&
 
40
                !strings.HasSuffix(fi.Name(), "_test.go") // ignore test files
 
41
}
 
42
 
 
43
 
 
44
func isPkgDir(fi FileInfo) bool {
 
45
        name := fi.Name()
 
46
        return fi.IsDirectory() && len(name) > 0 &&
 
47
                name[0] != '_' && name[0] != '.' // ignore _files and .files
47
48
}
48
49
 
49
50
 
101
102
                return &Directory{depth, path, name, "", nil}
102
103
        }
103
104
 
104
 
        list, err := ioutil.ReadDir(path)
 
105
        list, err := fs.ReadDir(path)
105
106
        if err != nil {
106
107
                // newDirTree is called with a path that should be a package
107
108
                // directory; errors here should not happen, but if they do,
108
109
                // we want to know about them
109
 
                log.Printf("ioutil.ReadDir(%s): %s", path, err)
 
110
                log.Printf("ReadDir(%s): %s", path, err)
110
111
        }
111
112
 
112
113
        // determine number of subdirectories and if there are package files
123
124
                        // though the directory doesn't contain any real package files - was bug)
124
125
                        if synopses[0] == "" {
125
126
                                // no "optimal" package synopsis yet; continue to collect synopses
126
 
                                file, err := parser.ParseFile(fset, filepath.Join(path, d.Name), nil,
 
127
                                file, err := parser.ParseFile(fset, filepath.Join(path, d.Name()), nil,
127
128
                                        parser.ParseComments|parser.PackageClauseOnly)
128
129
                                if err == nil {
129
130
                                        hasPkgFiles = true
156
157
                i := 0
157
158
                for _, d := range list {
158
159
                        if isPkgDir(d) {
159
 
                                dd := b.newDirTree(fset, filepath.Join(path, d.Name), d.Name, depth+1)
 
160
                                name := d.Name()
 
161
                                dd := b.newDirTree(fset, filepath.Join(path, name), name, depth+1)
160
162
                                if dd != nil {
161
163
                                        dirs[i] = dd
162
164
                                        i++
195
197
// (i.e., in this case the tree may contain directories w/o any package files).
196
198
//
197
199
func newDirectory(root string, pathFilter func(string) bool, maxDepth int) *Directory {
198
 
        // The root could be a symbolic link so use os.Stat not os.Lstat.
199
 
        d, err := os.Stat(root)
 
200
        // The root could be a symbolic link so use Stat not Lstat.
 
201
        d, err := fs.Stat(root)
200
202
        // If we fail here, report detailed error messages; otherwise
201
203
        // is is hard to see why a directory tree was not built.
202
204
        switch {
213
215
        b := treeBuilder{pathFilter, maxDepth}
214
216
        // the file set provided is only for local parsing, no position
215
217
        // information escapes and thus we don't need to save the set
216
 
        return b.newDirTree(token.NewFileSet(), root, d.Name, 0)
 
218
        return b.newDirTree(token.NewFileSet(), root, d.Name(), 0)
217
219
}
218
220
 
219
221
 
266
268
 
267
269
// lookup looks for the *Directory for a given path, relative to dir.
268
270
func (dir *Directory) lookup(path string) *Directory {
269
 
        d := strings.Split(dir.Path, string(filepath.Separator), -1)
270
 
        p := strings.Split(path, string(filepath.Separator), -1)
 
271
        d := strings.Split(dir.Path, string(filepath.Separator))
 
272
        p := strings.Split(path, string(filepath.Separator))
271
273
        i := 0
272
274
        for i < len(d) {
273
275
                if i >= len(p) || d[i] != p[i] {