-
Notifications
You must be signed in to change notification settings - Fork 18k
x/tools/godoc/vfs: ReadDir reports files as directories after Bind was called on a file #33495
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
Comments
I have seen it too. I had to modify the log line to see which file. It is /doc/copyright.html. That file is in content/static/doc/. But the vfs.ReadFile call is failing. I will take a look when I have some time. |
Change https://golang.org/cl/189560 mentions this issue: |
Agreed, it is doc/copyright.html. scan = func(dir string) {
fis, err := c.fs.ReadDir(dir)
if err != nil {
log.Printf("updateMetadata: error reading directory %q: %v\n", dir, err)
return
}
for _, fi := range fis {
name := pathpkg.Join(dir, fi.Name())
if fi.IsDir() {
fmt.Println("fi", fi.Name(), "is dir", "scan", name)
scan(name) // recurse
continue
} prints:
Seems odd!!! |
Hmmm...
This logic in for old := range ns {
if hasPathPrefix(old, path) && old != path {
// Find next element after path in old.
elem := old[len(path):]
elem = strings.TrimPrefix(elem, "/")
if i := strings.Index(elem, "/"); i >= 0 {
elem = elem[:i]
}
if !haveName[elem] {
haveName[elem] = true
all = append(all, dirInfo(elem))
}
}
} |
Here's a patch that fixes the issue, I believe. $ git diff
diff --git a/godoc/vfs/namespace.go b/godoc/vfs/namespace.go
index b8a1122d..4e495750 100644
--- a/godoc/vfs/namespace.go
+++ b/godoc/vfs/namespace.go
@@ -366,6 +366,10 @@ func (ns NameSpace) ReadDir(path string) ([]os.FileInfo, error) {
if i := strings.Index(elem, "/"); i >= 0 {
elem = elem[:i]
}
+ stat, _ := ns.Stat(old)
+ if stat != nil && !stat.IsDir() {
+ continue
+ }
if !haveName[elem] {
haveName[elem] = true
all = append(all, dirInfo(elem)) |
Change https://golang.org/cl/189657 mentions this issue: |
I've investigated this a bit. That fix above is a good start and helpful, but it's incomplete. I've identified these two problems. First, it makes it so that directories are skipped altogether if the bound file is inside a more-nested directory. E.g., if there was: ns.Bind("/doc/inner/file.html", newMount, "/doc/inner/file.html", vfs.BindReplace) Doing This can be fixed in a computationally inexpensive way: if Second, it doesn't include the file itself as part of the |
Change https://golang.org/cl/205661 mentions this issue: |
x/tools/godoc has been marked frozen. |
@seankhliao I don't see a frozen notice convention applied to golang.org/x/tools/godoc nor golang.org/x/tools/godoc/vfs. It doesn't seem to be frozen? Does that still need to be done as part of #59056? |
oops, I assumed it was part of https://go-review.googlesource.com/c/tools/+/349051 |
Running golang.googlesource.com/go, x/website and x/tools at tip, I run the
golangorg --index=false
binary and immediately get this log message:It's not clear where this is coming from, which file does not exist, or what action I am supposed to take. (The website loads fine). It might be good to make the error message clearer in this case.
The text was updated successfully, but these errors were encountered: