diff --git a/cmd-x-index-all.go b/cmd-x-index-all.go index db06ffdf..1eae0589 100644 --- a/cmd-x-index-all.go +++ b/cmd-x-index-all.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "errors" "fmt" "io" "math/rand" @@ -211,7 +212,7 @@ func createAllIndexes( for { _cid, sectionLength, block, err := rd.NextNode() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return nil, err @@ -611,7 +612,7 @@ func verifyAllIndexes( for { _cid, sectionLength, block, err := rd.NextNode() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return err diff --git a/gsfa/manifest/manifest.go b/gsfa/manifest/manifest.go index 1cc71516..4f6a7799 100644 --- a/gsfa/manifest/manifest.go +++ b/gsfa/manifest/manifest.go @@ -2,6 +2,7 @@ package manifest import ( "encoding/binary" + "errors" "fmt" "io" "os" @@ -213,7 +214,7 @@ func (m *Manifest) readAllContent() (Values, error) { values := make([][2]uint64, 0, currentContentSize/16) for { _, err := io.ReadFull(sectionReader, buf) - if err == io.EOF { + if errors.Is(err, io.EOF) { break } if err != nil { diff --git a/index-cid-to-offset.go b/index-cid-to-offset.go index ceae6a0e..2907f1db 100644 --- a/index-cid-to-offset.go +++ b/index-cid-to-offset.go @@ -89,7 +89,7 @@ func CreateIndex_cid2offset(ctx context.Context, tmpDir string, carPath string, for { c, sectionLength, err := rd.NextInfo() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return "", err diff --git a/readahead/readahead.go b/readahead/readahead.go index a804bb71..124514b0 100644 --- a/readahead/readahead.go +++ b/readahead/readahead.go @@ -2,6 +2,7 @@ package readahead import ( "bytes" + "errors" "fmt" "io" "os" @@ -78,7 +79,7 @@ func (cr *CachingReader) Read(p []byte) (int, error) { if n > 0 { cr.buffer.Write(tmp[:n]) } - if err == io.EOF && cr.buffer.Len() == 0 { + if errors.Is(err, io.EOF) && cr.buffer.Len() == 0 { // If EOF is reached and buffer is empty, return EOF return 0, io.EOF } diff --git a/readers.go b/readers.go index 5fb53e1e..f5770033 100644 --- a/readers.go +++ b/readers.go @@ -172,7 +172,7 @@ func isDirEmpty(dir string) (bool, error) { defer file.Close() _, err = file.Readdir(1) - if err == io.EOF { + if errors.Is(err, io.EOF) { return true, nil } return false, err @@ -202,7 +202,7 @@ func carCountItems(carPath string) (uint64, error) { for { _, _, err := rd.NextInfo() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return 0, err @@ -230,7 +230,7 @@ func carCountItemsByFirstByte(carPath string) (map[byte]uint64, error) { for { _, _, block, err := rd.NextNode() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return nil, err diff --git a/store/index/gc.go b/store/index/gc.go index d9e6c8b2..ebfadde5 100644 --- a/store/index/gc.go +++ b/store/index/gc.go @@ -8,6 +8,7 @@ package index import ( "context" "encoding/binary" + "errors" "fmt" "io" "os" @@ -308,7 +309,7 @@ func (index *Index) reapIndexRecords(ctx context.Context, fileNum uint32, indexP return false, ctx.Err() } if _, err = file.ReadAt(sizeBuf, pos); err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { // Finished reading entire index. break } @@ -348,7 +349,7 @@ func (index *Index) reapIndexRecords(ctx context.Context, fileNum uint32, indexP } data := scratch[:size] if _, err = file.ReadAt(data, pos+sizePrefixSize); err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { // The data has not been written yet, or the file is corrupt. // Take the data we are able to use and move on. break diff --git a/store/index/index.go b/store/index/index.go index 83a68779..66015daa 100644 --- a/store/index/index.go +++ b/store/index/index.go @@ -10,6 +10,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "io" "os" @@ -362,7 +363,7 @@ func scanIndexFile(ctx context.Context, basePath string, fileNum uint32, buckets var i int for { if _, err = file.ReadAt(sizeBuffer, pos); err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { // Finished reading entire index. break } @@ -392,7 +393,7 @@ func scanIndexFile(ctx context.Context, basePath string, fileNum uint32, buckets } data := scratch[:size] if _, err = file.ReadAt(data, pos); err != nil { - if err == io.ErrUnexpectedEOF || err == io.EOF { + if err == io.ErrUnexpectedEOF || errors.Is(err, io.EOF) { // The file is corrupt since the expected data could not be // read. Take the usable data and move on. log.Errorw("Unexpected EOF scanning index record", "file", indexPath) @@ -1059,7 +1060,7 @@ func (iter *RawIterator) Next() ([]byte, types.Position, bool, error) { _, err := iter.file.ReadAt(sizeBuf, iter.pos) if err != nil { iter.file.Close() - if err == io.EOF { + if errors.Is(err, io.EOF) { iter.file = nil iter.fileNum++ return iter.Next() @@ -1488,7 +1489,7 @@ func MoveFiles(indexPath, newDir string) error { for { fileName, err := fileIter.next() if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return err diff --git a/store/index/upgrade.go b/store/index/upgrade.go index 5d6ce441..09a3b2ab 100644 --- a/store/index/upgrade.go +++ b/store/index/upgrade.go @@ -9,6 +9,7 @@ import ( "bufio" "context" "encoding/binary" + "errors" "fmt" "io" "os" @@ -91,7 +92,7 @@ func chunkOldIndex(ctx context.Context, file *os.File, name string, fileSizeLimi for { _, err = io.ReadFull(reader, sizeBuffer) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return 0, err diff --git a/store/index/upgrade_test.go b/store/index/upgrade_test.go index b00baf36..30846c9d 100644 --- a/store/index/upgrade_test.go +++ b/store/index/upgrade_test.go @@ -104,7 +104,7 @@ func testScanIndexFile(file *os.File, fileNum uint32, buckets Buckets, prevSize for { _, err := io.ReadFull(buffered, sizeBuffer) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return err @@ -119,7 +119,7 @@ func testScanIndexFile(file *os.File, fileNum uint32, buckets Buckets, prevSize data := scratch[:size] _, err = io.ReadFull(buffered, data) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { return errors.New("unexpected EOF") } return err diff --git a/store/primary/gsfaprimary/gsfaprimary.go b/store/primary/gsfaprimary/gsfaprimary.go index 5779d404..d0463422 100644 --- a/store/primary/gsfaprimary/gsfaprimary.go +++ b/store/primary/gsfaprimary/gsfaprimary.go @@ -496,7 +496,7 @@ func (iter *Iterator) Next() ([]byte, []byte, error) { _, err := iter.file.ReadAt(data, pos) if err != nil { iter.file.Close() - // if err == io.EOF { + // if errors.Is(err, io.EOF) { // err = io.ErrUnexpectedEOF // } return nil, nil, err diff --git a/store/primary/gsfaprimary/upgrade_test.go b/store/primary/gsfaprimary/upgrade_test.go index 0b99202b..f8626cbc 100644 --- a/store/primary/gsfaprimary/upgrade_test.go +++ b/store/primary/gsfaprimary/upgrade_test.go @@ -130,7 +130,7 @@ func testScanPrimaryFile(file *os.File) ([][]byte, error) { for { _, err := io.ReadFull(buffered, sizeBuffer) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return nil, err @@ -143,7 +143,7 @@ func testScanPrimaryFile(file *os.File) ([][]byte, error) { data := scratch[:size] _, err = io.ReadFull(buffered, data) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { return nil, errors.New("unexpected EOF") } return nil, err diff --git a/store/primary/sig2epochprimary/upgrade_test.go b/store/primary/sig2epochprimary/upgrade_test.go index 4ea0bdfe..ad33b55c 100644 --- a/store/primary/sig2epochprimary/upgrade_test.go +++ b/store/primary/sig2epochprimary/upgrade_test.go @@ -130,7 +130,7 @@ func testScanPrimaryFile(file *os.File) ([][]byte, error) { for { _, err := io.ReadFull(buffered, sizeBuffer) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { break } return nil, err @@ -143,7 +143,7 @@ func testScanPrimaryFile(file *os.File) ([][]byte, error) { data := scratch[:size] _, err = io.ReadFull(buffered, data) if err != nil { - if err == io.EOF { + if errors.Is(err, io.EOF) { return nil, errors.New("unexpected EOF") } return nil, err diff --git a/store/store_test.go b/store/store_test.go index faba3c2d..9591150b 100644 --- a/store/store_test.go +++ b/store/store_test.go @@ -2,6 +2,7 @@ package store_test import ( "context" + "errors" "io" "os" "path/filepath" @@ -89,7 +90,7 @@ func TestUpdate(t *testing.T) { var count int for { key, val, err := storeIter.Next() - if err == io.EOF { + if errors.Is(err, io.EOF) { break } require.Zero(t, count)