Skip to content

Commit

Permalink
ipfs: all - use new Closed(EBADF) error kind
Browse files Browse the repository at this point in the history
  • Loading branch information
djdv committed Feb 3, 2024
1 parent 19a7b7a commit ae840b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 32 deletions.
24 changes: 10 additions & 14 deletions internal/filesystem/ipfs/ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -554,17 +554,15 @@ func (id *ipfsDirectory) Read([]byte) (int, error) {

func (id *ipfsDirectory) StreamDir() <-chan filesystem.StreamDirEntry {
const op = "streamdir"
stream := id.stream
if stream == nil {
errs := make(chan filesystem.StreamDirEntry, 1)
// TODO: We don't have an error kind
// that translates into EBADF
errs <- newErrorEntry(
fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.IO),
)
return errs
if stream := id.stream; stream != nil {
return stream.ch
}
return stream.ch
errs := make(chan filesystem.StreamDirEntry, 1)
errs <- newErrorEntry(
fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed),
)
close(errs)
return errs
}

func (id *ipfsDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
Expand All @@ -574,9 +572,7 @@ func (id *ipfsDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
}
stream := id.stream
if stream == nil {
// TODO: We don't have an error kind
// that translates into EBADF
return nil, fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.IO)
return nil, fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed)
}
var (
ctx = stream.Context
Expand All @@ -597,7 +593,7 @@ func (id *ipfsDirectory) Close() error {
id.stream = nil
return nil
}
return fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.InvalidItem)
return fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed)
}

func linkLimitError(op, name string, limit uint) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/filesystem/ipfs/keyfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func (kd *keyDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
}
stream := kd.stream
if stream == nil {
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
}
var (
ctx = stream.Context
Expand All @@ -415,7 +415,7 @@ func (kd *keyDirectory) Close() error {
kd.stream = nil
return nil
}
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.InvalidItem)
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
}

func pathWithoutNamespace(key coreiface.Key) string {
Expand Down
26 changes: 10 additions & 16 deletions internal/filesystem/ipfs/pinfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,7 @@ func (pd *pinDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
}
stream := pd.stream
if stream == nil {
// TODO: We don't have an error kind
// that translates into EBADF
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
}
var (
ctx = stream.Context
Expand All @@ -363,17 +361,15 @@ func (pd *pinDirectory) ReadDir(count int) ([]fs.DirEntry, error) {

func (pd *pinDirectory) StreamDir() <-chan filesystem.StreamDirEntry {
const op = "streamdir"
stream := pd.stream
if stream == nil {
errs := make(chan filesystem.StreamDirEntry, 1)
// TODO: We don't have an error kind
// that translates into EBADF
errs <- newErrorEntry(
fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO),
)
return errs
if stream := pd.stream; stream != nil {
return stream.ch
}
return stream.ch
errs := make(chan filesystem.StreamDirEntry, 1)
errs <- newErrorEntry(
fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed),
)
close(errs)
return errs
}

func (pd *pinDirectory) Close() error {
Expand All @@ -383,9 +379,7 @@ func (pd *pinDirectory) Close() error {
pd.stream = nil
return nil
}
// TODO: We don't have an error kind
// that translates into EBADF
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
}

func (pe *pinDirEntry) Name() string {
Expand Down

0 comments on commit ae840b4

Please sign in to comment.