From c8332198f42d0c5eb4e6345fe3fc935283dd5a9d Mon Sep 17 00:00:00 2001 From: Nigel Tao Date: Wed, 9 May 2012 10:43:15 +1000 Subject: [PATCH] go: fix the import path "./..." not matching ".". Tested manually. Fixes #3554. Before: $ cd $GOROOT/src/pkg $ go list io io $ go list io/... io io/ioutil $ cd $GOROOT/src/pkg/io $ go list . io $ go list ./... io/ioutil After: $ cd $GOROOT/src/pkg $ go list io io $ go list io/... io io/ioutil $ cd $GOROOT/src/pkg/io $ go list . io $ go list ./... io io/ioutil $ go list ././... io io/ioutil $ go list ././.././io/... io io/ioutil $ go list ../image image $ go list ../image/... image image/color image/draw image/gif image/jpeg image/png $ go list ../.../template html/template text/template $ cd $GOROOT/src/pkg $ go list ./io io $ go list ./io/... io io/ioutil $ go list ./.../pprof net/http/pprof runtime/pprof $ go list ./compress can't load package: package compress: no Go source files in /home/nigeltao/go/src/pkg/compress $ go list ./compress/... compress/bzip2 compress/flate compress/gzip compress/lzw compress/zlib $ cd $GOROOT/src/pkg/code.google.com $ go list ./p/leveldb-go/... code.google.com/p/leveldb-go/leveldb code.google.com/p/leveldb-go/leveldb/crc code.google.com/p/leveldb-go/leveldb/db code.google.com/p/leveldb-go/leveldb/memdb code.google.com/p/leveldb-go/leveldb/memfs code.google.com/p/leveldb-go/leveldb/record code.google.com/p/leveldb-go/leveldb/table code.google.com/p/leveldb-go/manualtest/filelock $ go list ./p/.../truetype code.google.com/p/freetype-go/example/truetype code.google.com/p/freetype-go/freetype/truetype $ go list ./p/.../example warning: "./p/.../example" matched no packages $ go list ./p/.../example/... code.google.com/p/freetype-go/example/freetype code.google.com/p/freetype-go/example/gamma code.google.com/p/freetype-go/example/raster code.google.com/p/freetype-go/example/round code.google.com/p/freetype-go/example/truetype code.google.com/p/x-go-binding/example/imgview code.google.com/p/x-go-binding/example/xgb R=rsc CC=golang-dev https://golang.org/cl/6194056 --- src/cmd/go/main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 73c2f54a765..93a41242880 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -500,13 +500,25 @@ func matchPackagesInFS(pattern string) []string { var pkgs []string filepath.Walk(dir, func(path string, fi os.FileInfo, err error) error { - if err != nil || !fi.IsDir() || path == dir { + if err != nil || !fi.IsDir() { return nil } + if path == dir { + // filepath.Walk starts at dir and recurses. For the recursive case, + // the path is the result of filepath.Join, which calls filepath.Clean. + // The initial case is not Cleaned, though, so we do this explicitly. + // + // This converts a path like "./io/" to "io". Without this step, running + // "cd $GOROOT/src/pkg; go list ./io/..." would incorrectly skip the io + // package, because prepending the prefix "./" to the unclean path would + // result in "././io", and match("././io") returns false. + path = filepath.Clean(path) + } - // Avoid .foo, _foo, and testdata directory trees. + // Avoid .foo, _foo, and testdata directory trees, but do not avoid "." or "..". _, elem := filepath.Split(path) - if strings.HasPrefix(elem, ".") || strings.HasPrefix(elem, "_") || elem == "testdata" { + dot := strings.HasPrefix(elem, ".") && elem != "." && elem != ".." + if dot || strings.HasPrefix(elem, "_") || elem == "testdata" { return filepath.SkipDir }