From f26e480a77dd8db2c37afaf31239610977639c04 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Fri, 14 Apr 2023 22:33:05 -0700 Subject: [PATCH] lib/storage: fix a bug, which prevents from reading pre-v1.90.0 parts The bug has been introduced in c0b852d50d20e4a38bb84ca470768a577dda850d --- lib/storage/part_header.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/storage/part_header.go b/lib/storage/part_header.go index b54bf39d58..ee446a51fa 100644 --- a/lib/storage/part_header.go +++ b/lib/storage/part_header.go @@ -135,19 +135,20 @@ func (ph *partHeader) MustReadMetadata(partPath string) { ph.Reset() metadataPath := filepath.Join(partPath, metadataFilename) - metadata, err := os.ReadFile(metadataPath) - if err != nil { - if os.IsNotExist(err) { - // This is a part created before v1.90.0. - // Fall back to reading the metadata from the partPath itsel - if err := ph.ParseFromPath(partPath); err != nil { - logger.Panicf("FATAL: cannot parse metadata from %q: %s", partPath, err) - } + if !fs.IsPathExist(metadataPath) { + // This is a part created before v1.90.0. + // Fall back to reading the metadata from the partPath itsel + if err := ph.ParseFromPath(partPath); err != nil { + logger.Panicf("FATAL: cannot parse metadata from %q: %s", partPath, err) + } + } else { + metadata, err := os.ReadFile(metadataPath) + if err != nil { + logger.Panicf("FATAL: cannot read %q: %s", metadataPath, err) + } + if err := json.Unmarshal(metadata, ph); err != nil { + logger.Panicf("FATAL: cannot parse %q: %s", metadataPath, err) } - logger.Panicf("FATAL: cannot read %q: %s", metadataPath, err) - } - if err := json.Unmarshal(metadata, ph); err != nil { - logger.Panicf("FATAL: cannot parse %q: %s", metadataPath, err) } // Perform various checks