Skip to content

Commit ae840b4

Browse files
committed
ipfs: all - use new Closed(EBADF) error kind
1 parent 19a7b7a commit ae840b4

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

internal/filesystem/ipfs/ipfs.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -554,17 +554,15 @@ func (id *ipfsDirectory) Read([]byte) (int, error) {
554554

555555
func (id *ipfsDirectory) StreamDir() <-chan filesystem.StreamDirEntry {
556556
const op = "streamdir"
557-
stream := id.stream
558-
if stream == nil {
559-
errs := make(chan filesystem.StreamDirEntry, 1)
560-
// TODO: We don't have an error kind
561-
// that translates into EBADF
562-
errs <- newErrorEntry(
563-
fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.IO),
564-
)
565-
return errs
557+
if stream := id.stream; stream != nil {
558+
return stream.ch
566559
}
567-
return stream.ch
560+
errs := make(chan filesystem.StreamDirEntry, 1)
561+
errs <- newErrorEntry(
562+
fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed),
563+
)
564+
close(errs)
565+
return errs
568566
}
569567

570568
func (id *ipfsDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
@@ -574,9 +572,7 @@ func (id *ipfsDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
574572
}
575573
stream := id.stream
576574
if stream == nil {
577-
// TODO: We don't have an error kind
578-
// that translates into EBADF
579-
return nil, fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.IO)
575+
return nil, fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed)
580576
}
581577
var (
582578
ctx = stream.Context
@@ -597,7 +593,7 @@ func (id *ipfsDirectory) Close() error {
597593
id.stream = nil
598594
return nil
599595
}
600-
return fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.InvalidItem)
596+
return fserrors.New(op, id.info.name, fs.ErrClosed, fserrors.Closed)
601597
}
602598

603599
func linkLimitError(op, name string, limit uint) error {

internal/filesystem/ipfs/keyfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ func (kd *keyDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
391391
}
392392
stream := kd.stream
393393
if stream == nil {
394-
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
394+
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
395395
}
396396
var (
397397
ctx = stream.Context
@@ -415,7 +415,7 @@ func (kd *keyDirectory) Close() error {
415415
kd.stream = nil
416416
return nil
417417
}
418-
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.InvalidItem)
418+
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
419419
}
420420

421421
func pathWithoutNamespace(key coreiface.Key) string {

internal/filesystem/ipfs/pinfs.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ func (pd *pinDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
345345
}
346346
stream := pd.stream
347347
if stream == nil {
348-
// TODO: We don't have an error kind
349-
// that translates into EBADF
350-
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
348+
return nil, fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
351349
}
352350
var (
353351
ctx = stream.Context
@@ -363,17 +361,15 @@ func (pd *pinDirectory) ReadDir(count int) ([]fs.DirEntry, error) {
363361

364362
func (pd *pinDirectory) StreamDir() <-chan filesystem.StreamDirEntry {
365363
const op = "streamdir"
366-
stream := pd.stream
367-
if stream == nil {
368-
errs := make(chan filesystem.StreamDirEntry, 1)
369-
// TODO: We don't have an error kind
370-
// that translates into EBADF
371-
errs <- newErrorEntry(
372-
fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO),
373-
)
374-
return errs
364+
if stream := pd.stream; stream != nil {
365+
return stream.ch
375366
}
376-
return stream.ch
367+
errs := make(chan filesystem.StreamDirEntry, 1)
368+
errs <- newErrorEntry(
369+
fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed),
370+
)
371+
close(errs)
372+
return errs
377373
}
378374

379375
func (pd *pinDirectory) Close() error {
@@ -383,9 +379,7 @@ func (pd *pinDirectory) Close() error {
383379
pd.stream = nil
384380
return nil
385381
}
386-
// TODO: We don't have an error kind
387-
// that translates into EBADF
388-
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.IO)
382+
return fserrors.New(op, filesystem.Root, fs.ErrClosed, fserrors.Closed)
389383
}
390384

391385
func (pe *pinDirEntry) Name() string {

0 commit comments

Comments
 (0)