forked from mirror/afero
Work around root directory Open/Stat corner case leading to panic
See https://github.com/spf13/afero/pull/146#issuecomment-470840725
This commit is contained in:
parent
4f00b06400
commit
d5bfeca89b
|
@ -148,7 +148,12 @@ func (f *File) Readdirnames(count int) (names []string, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (f *File) Stat() (os.FileInfo, error) { return f.zipfile.FileInfo(), nil }
|
||||
func (f *File) Stat() (os.FileInfo, error) {
|
||||
if f.zipfile == nil {
|
||||
return &pseudoRoot{}, nil
|
||||
}
|
||||
return f.zipfile.FileInfo(), nil
|
||||
}
|
||||
|
||||
func (f *File) Sync() error { return nil }
|
||||
|
||||
|
|
|
@ -38,6 +38,17 @@ func TestZipFS(t *testing.T) {
|
|||
t.Errorf("expected to get <aaaabbbb>, got <%s>", string(buf))
|
||||
}
|
||||
|
||||
d, err := a.Open("/")
|
||||
if d == nil {
|
||||
t.Error(`Open("/") returns nil`)
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf(`Open("/"): err = %v`, err)
|
||||
}
|
||||
if s, _ := d.Stat(); !s.IsDir() {
|
||||
t.Error(`expected root ("/") to be a directory`)
|
||||
}
|
||||
|
||||
buf = make([]byte, 8192)
|
||||
if n, err := f.Read(buf); err != nil {
|
||||
t.Error(err)
|
||||
|
@ -51,6 +62,7 @@ func TestZipFS(t *testing.T) {
|
|||
path string
|
||||
dir bool
|
||||
}{
|
||||
{"/", true},
|
||||
{"testDir1", true},
|
||||
{"testDir1/testFile", false},
|
||||
{"testFile", false},
|
||||
|
|
Loading…
Reference in New Issue