Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/godoc/vfs: NameSpace.ReadDir sometimes doesn't include all files in overlapping directories #34571

Closed
dmitshur opened this issue Sep 27, 2019 · 2 comments
Labels
Milestone

Comments

@dmitshur
Copy link
Member

@dmitshur dmitshur commented Sep 27, 2019

vfs.NameSpace.ReadDir is documented to:

Logically, ReadDir must return the union of all the directories that are named by path. In order to avoid misinterpreting Go packages, of all the directories that contain Go source code, we only include the files from the first, but we include subdirectories from all.

Consider the following case, where there are no .go files in either directory, yet ReadDir fails to include files from both directories:

package main

import (
	"fmt"
	"log"

	"golang.org/x/tools/godoc/vfs"
	"golang.org/x/tools/godoc/vfs/mapfs"
)

func main() {
	fs := vfs.NameSpace{}
	fs.Bind("/", mapfs.New(map[string]string{
		"doc/a.txt":          "1",
		"doc/b.txt":          "1",
		"doc/dir1/empty.txt": "",
	}), "/", vfs.BindReplace)
	fs.Bind("/", mapfs.New(map[string]string{
		"doc/a.txt":          "22",
		"doc/dir2/empty.txt": "",
	}), "/", vfs.BindBefore)

	fis, err := fs.ReadDir("/doc")
	if err != nil {
		log.Fatalln(err)
	}
	for _, fi := range fis {
		fmt.Println(fi.Name(), fi.Size())
	}
}

It produces output:

a.txt 2
dir1 0
dir2 0

But should produce:

a.txt 2
b.txt 1
dir1 0
dir2 0

This bug came up in the past, and was fixed by CL 5783076. If re-applied today, it fixes the problem again. But it was replaced with a more general fix in CL 5783079, which causes the issue to occur under the above conditions.

/cc @jayconrod

@gopherbot gopherbot added this to the Unreleased milestone Sep 27, 2019
@gopherbot gopherbot added the Tools label Sep 27, 2019
@dmitshur dmitshur added NeedsInvestigation and removed Tools labels Sep 27, 2019
@gopherbot gopherbot added the Tools label Sep 27, 2019
@dmitshur dmitshur changed the title x/tools/godoc/vfs: NameSpace.ReadDir sometimes doesn't include union of all directories when there aren't any .go files x/tools/godoc/vfs: NameSpace.ReadDir sometimes doesn't include all files in overlapping directories Sep 27, 2019
@gopherbot
Copy link

@gopherbot gopherbot commented Sep 27, 2019

Change https://golang.org/cl/197801 mentions this issue: x/tools/godoc/vfs: fix union logic in NameSpace.ReadDir

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 6, 2019

Change https://golang.org/cl/205661 mentions this issue: godoc/vfs: include dirs needed to reach mount points in Stat

Bogdan-D pushed a commit to Bogdan-D/godocx that referenced this issue Nov 13, 2019
ReadDir now returns files from directories in all matching mount
points if no Go files are present in any of them. The behavior now
matches the documentation.

Fixes golang/go#34571

Change-Id: I3a0c8d49a5906ec33ebe9e3efea9d2b9d267506c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/197801
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.