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
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@dmitshur
Copy link
Contributor

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 This label describes issues relating to any tools in the x/tools repository. label Sep 27, 2019
@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed Tools This label describes issues relating to any tools in the x/tools repository. labels Sep 27, 2019
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. 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

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

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 27, 2019
@gopherbot
Copy link

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

@golang golang locked and limited conversation to collaborators Nov 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants