diff options
author | Nigel Tao <nigeltao@golang.org> | 2012-05-09 10:43:15 +1000 |
---|---|---|
committer | Nigel Tao <nigeltao@golang.org> | 2012-05-09 10:43:15 +1000 |
commit | fce0aed3f4e2f1b5a42ee9f089504d0ef8066d3b (patch) | |
tree | 69f273a967a524e5909d10f052ce11856d8eea6c /src/cmd | |
parent | 68a6798ca1f30b7ab43cf1105888b259af7ae2f8 (diff) | |
download | go-fce0aed3f4e2f1b5a42ee9f089504d0ef8066d3b.tar.gz |
go: fix the import path "./..." not matching ".".
Tested manually.
Fixes issue 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
http://codereview.appspot.com/6194056
Diffstat (limited to 'src/cmd')
-rw-r--r-- | src/cmd/go/main.go | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 73c2f54a7..93a412428 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 } |