Skip to content

Commit

Permalink
Eliminate another root-path-related corner case
Browse files Browse the repository at this point in the history
  • Loading branch information
hillu committed Mar 30, 2020
1 parent d5bfeca commit 72cabd5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 7 additions & 5 deletions zipfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 3 additions & 0 deletions zipfs/zipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 72cabd5

Please sign in to comment.