forked from mirror/afero
Eliminate another root-path-related corner case
This commit is contained in:
parent
d5bfeca89b
commit
72cabd552e
|
@ -103,16 +103,18 @@ func (f *File) Write(p []byte) (n int, err error) { return 0, syscall.EPERM }
|
|||
|
||||
func (f *File) WriteAt(p []byte, off int64) (n int, err error) { return 0, syscall.EPERM }
|
||||
|
||||
func (f *File) Name() string { return f.zipfile.Name }
|
||||
func (f *File) Name() string {
|
||||
if f.zipfile == nil {
|
||||
return string(filepath.Separator)
|
||||
}
|
||||
return filepath.Join(splitpath(f.zipfile.Name))
|
||||
}
|
||||
|
||||
func (f *File) getDirEntries() (map[string]*zip.File, error) {
|
||||
if !f.isdir {
|
||||
return nil, syscall.ENOTDIR
|
||||
}
|
||||
name := string(filepath.Separator)
|
||||
if f.zipfile != nil {
|
||||
name = filepath.Join(splitpath(f.zipfile.Name))
|
||||
}
|
||||
name := f.Name()
|
||||
entries, ok := f.fs.files[name]
|
||||
if !ok {
|
||||
return nil, &os.PathError{Op: "readdir", Path: name, Err: syscall.ENOENT}
|
||||
|
|
|
@ -48,6 +48,9 @@ func TestZipFS(t *testing.T) {
|
|||
if s, _ := d.Stat(); !s.IsDir() {
|
||||
t.Error(`expected root ("/") to be a directory`)
|
||||
}
|
||||
if n := d.Name(); n != "/" {
|
||||
t.Errorf("Wrong Name() of root directory: Expected: '/', got '%s'", n)
|
||||
}
|
||||
|
||||
buf = make([]byte, 8192)
|
||||
if n, err := f.Read(buf); err != nil {
|
||||
|
|
Loading…
Reference in New Issue