Skip to content

Commit

Permalink
Bugfixes in fs.go
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Aug 6, 2024
1 parent dc87071 commit 19e974c
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions system/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import (
"github.com/pkg/errors"
)

var (
_ fs.FS = (*FS)(nil)
_ fs.StatFS = (*FS)(nil)
)
var _ fs.FS = (*FS)(nil)

// An FS provides access to a hierarchical file system.
//
Expand Down Expand Up @@ -53,6 +50,10 @@ func (f FS) Open(name string) (fs.File, error) {
}
}

if name == "." {
name = ""
}

path, node, err := f.Resolve(f.Ctx, name)
if err != nil {
return nil, &fs.PathError{
Expand Down Expand Up @@ -88,20 +89,6 @@ func clean(name string) string {
return name
}

// Stat returns a FileInfo describing the file.
// If there is an error, it should be of type *PathError.
func (f FS) Stat(name string) (fs.FileInfo, error) {
path, node, err := f.Resolve(f.Ctx, name)
if err != nil {
return nil, err
}

return &ipfsNode{
Path: path,
Node: node,
}, nil
}

var (
_ fs.FileInfo = (*ipfsNode)(nil)
_ fs.ReadDirFile = (*ipfsNode)(nil)
Expand Down Expand Up @@ -210,7 +197,7 @@ func (n ipfsNode) ReadDir(max int) (entries []fs.DirEntry, err error) {

var subpath path.Path
if subpath, err = path.Join(n.Path, name); err != nil {
break
return
}

entries = append(entries, &ipfsNode{
Expand All @@ -224,10 +211,10 @@ func (n ipfsNode) ReadDir(max int) (entries []fs.DirEntry, err error) {
}

// If we get here, it's because the iterator stopped. It either
// failed or is exhausted.

if err == nil && iter.Err() != nil {
err = iter.Err() // iterator failed
// failed or is exhausted. Any other error has already caused us
// to return.
if err = iter.Err(); err == nil {
err = io.EOF // exhausted
}

return
Expand Down

0 comments on commit 19e974c

Please sign in to comment.