Skip to content

x/tools/godoc/vfs/zipfs: ReadDir("/") returns error "file not found: /" #12743

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

Closed
jdhenke opened this issue Sep 24, 2015 · 6 comments
Closed

Comments

@jdhenke
Copy link

jdhenke commented Sep 24, 2015

go version go1.5 darwin/amd64

I created a vfs.FileSystem using zipfs and ReadDir("/") returns nil, "file not found: /".

I expected it to return a slice of os.FileInfo for the files at the root of the zip file and a nil error.

I've written tests and a fix but need guidance on next steps. Please advise!


Full Repro Script

See jdhenke/golang-zipfs-error-repro to try it out yourself.

package main

import (
    "archive/zip"
    "bytes"
    "golang.org/x/tools/godoc/vfs/zipfs"
    "io"
    "log"
)

func main() {

    // example files to use
    files := map[string]string{"foo": "foo", "bar/baz": "baz"}

    // create test zip file from above files
    b := new(bytes.Buffer)
    zw := zip.NewWriter(b)
    for file, contents := range files {
        w, err := zw.Create(file)
        if err != nil {
            log.Fatal(err)
        }
        _, err = io.WriteString(w, contents)
        if err != nil {
            log.Fatal(err)
        }
    }
    zw.Close()

    // create zipfs from zip file
    zr, err := zip.NewReader(bytes.NewReader(b.Bytes()), int64(b.Len()))
    if err != nil {
        log.Fatal(err)
    }
    rc := &zip.ReadCloser{
        Reader: *zr,
    }
    fs := zipfs.New(rc, "foo")

    // try to list contents of root directory
    // FAILS HERE!
    infos, err := fs.ReadDir("/")
    if err != nil {
        log.Fatal(err)
    }
    for _, info := range infos {
        log.Printf("Found: %v\n", info.Name())
    }
}

Currently results in:

2015/09/24 18:27:56 file not found: /
exit status 1

With fix, results in:

2015/09/24 19:48:53 Found: bar
2015/09/24 19:48:53 Found: foo
@minux
Copy link
Member

minux commented Sep 25, 2015

Does your zip file contain leading / in filenames?

Please ask questions on the mailing list. Thanks.

@minux minux closed this as completed Sep 25, 2015
@jdhenke
Copy link
Author

jdhenke commented Sep 25, 2015

Which mailing list? Sorry if this was the wrong spot. The contribution guidelines suggest filing an issue here as the first place to start.

Appreciate the guidance; eager to help out.

@minux minux reopened this Sep 26, 2015
@bradfitz
Copy link
Contributor

We only built zipfs for godoc, and it's likely that godoc just never needs to read from /, so this bug has just always existed and we never cared since we were the only user. If we had an internal mechanism back then, we probably wouldn't have even made this package public.

If you fix this, be sure to verify and state in your commit message that godoc in zip mode still works.

@rakyll rakyll added this to the Unplanned milestone Sep 28, 2015
@jdhenke
Copy link
Author

jdhenke commented Nov 14, 2015

Here's my current patch. Should I submit it for code review?

@bradfitz
Copy link
Contributor

Sure. We don't review code outside of Gerrit for both practical matters (crappy code review tools elsewhere, in general) and legal paranoia reasons (Gerrit enforces CLA compliance for us).

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/16925 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants