diff --git a/internal/filesystem/ipfs/ipfs.go b/internal/filesystem/ipfs/ipfs.go index 6a358527..1b7a67b8 100644 --- a/internal/filesystem/ipfs/ipfs.go +++ b/internal/filesystem/ipfs/ipfs.go @@ -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) { @@ -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 @@ -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 { diff --git a/internal/filesystem/ipfs/keyfs.go b/internal/filesystem/ipfs/keyfs.go index 1c699f26..39c18b30 100644 --- a/internal/filesystem/ipfs/keyfs.go +++ b/internal/filesystem/ipfs/keyfs.go @@ -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 @@ -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 { diff --git a/internal/filesystem/ipfs/pinfs.go b/internal/filesystem/ipfs/pinfs.go index dd17c171..10e299e2 100644 --- a/internal/filesystem/ipfs/pinfs.go +++ b/internal/filesystem/ipfs/pinfs.go @@ -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 @@ -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 { @@ -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 {