From 3b579248de25c13479e654901852715672db50da Mon Sep 17 00:00:00 2001 From: steven Date: Wed, 9 Oct 2024 17:47:28 +0800 Subject: [PATCH] err handling --- erigon-lib/downloader/downloader.go | 2 +- turbo/snapshotsync/freezeblocks/block_snapshots.go | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/erigon-lib/downloader/downloader.go b/erigon-lib/downloader/downloader.go index ee1c749a5f8..2eb60f4fdb1 100644 --- a/erigon-lib/downloader/downloader.go +++ b/erigon-lib/downloader/downloader.go @@ -2976,7 +2976,7 @@ func (d *Downloader) torrentCompleted(tName string, tHash metainfo.Hash) { } // create commitment file for .seg/.idx files - if !strings.HasSuffix(tName, ".seg") || !strings.HasSuffix(tName, ".idx") { + if !strings.HasSuffix(tName, ".seg") && !strings.HasSuffix(tName, ".idx") { return } tName = strings.ReplaceAll(tName, ".seg", ".txt") diff --git a/turbo/snapshotsync/freezeblocks/block_snapshots.go b/turbo/snapshotsync/freezeblocks/block_snapshots.go index 2fa5987a51f..b67638e97d6 100644 --- a/turbo/snapshotsync/freezeblocks/block_snapshots.go +++ b/turbo/snapshotsync/freezeblocks/block_snapshots.go @@ -757,11 +757,16 @@ func (s *RoSnapshots) integrityCheck(fName string) bool { func integrityCheck(dir, fName string) bool { file := filepath.Join(dir, fName) f, err := os.Stat(file) - if os.IsNotExist(err) { + if err != nil { + log.Warn("[snapshots] integrityCheck", "err", err) return false } torrentFile := filepath.Join(dir, fName) + ".torrent" - if _, err := os.Stat(torrentFile); os.IsNotExist(err) { + _, err = os.Stat(torrentFile) + if err != nil { + if !os.IsNotExist(err) { + log.Warn("[snapshots] integrityCheck", "err", err) + } // torrent file not exists means that file is created locally, in this case file must be complete return true } @@ -769,7 +774,10 @@ func integrityCheck(dir, fName string) bool { fName = strings.ReplaceAll(fName, ".idx", ".txt") commitmentFile := filepath.Join(dir, "commitment", fName) cf, err := os.Stat(commitmentFile) - if os.IsNotExist(err) { + if err != nil { + if !os.IsNotExist(err) { + log.Warn("[snapshots] integrityCheck", "err", err) + } return false } if cf.ModTime().After(f.ModTime()) {