diff --git a/lib/mergeset/table.go b/lib/mergeset/table.go index 73e95870e..a10ce4a58 100644 --- a/lib/mergeset/table.go +++ b/lib/mergeset/table.go @@ -1477,17 +1477,17 @@ func mustWritePartNames(pws []*partWrapper, dstDir string) { func mustReadPartNames(srcDir string) []string { partNamesPath := filepath.Join(srcDir, partsFilename) - data, err := os.ReadFile(partNamesPath) - if err == nil { + if fs.IsPathExist(partNamesPath) { + data, err := os.ReadFile(partNamesPath) + if err != nil { + logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err) + } var partNames []string if err := json.Unmarshal(data, &partNames); err != nil { logger.Panicf("FATAL: cannot parse %s: %s", partNamesPath, err) } return partNames } - if !os.IsNotExist(err) { - logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err) - } // The partsFilename is missing. This is the upgrade from versions previous to v1.90.0. // Read part names from directories under srcDir des := fs.MustReadDir(srcDir) diff --git a/lib/storage/partition.go b/lib/storage/partition.go index 8b344453f..85e4611df 100644 --- a/lib/storage/partition.go +++ b/lib/storage/partition.go @@ -1903,17 +1903,17 @@ func getPartNames(pws []*partWrapper) []string { func mustReadPartNames(smallPartsPath, bigPartsPath string) ([]string, []string) { partNamesPath := filepath.Join(smallPartsPath, partsFilename) - data, err := os.ReadFile(partNamesPath) - if err == nil { + if fs.IsPathExist(partNamesPath) { + data, err := os.ReadFile(partNamesPath) + if err != nil { + logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err) + } var partNames partNamesJSON if err := json.Unmarshal(data, &partNames); err != nil { logger.Panicf("FATAL: cannot parse %s: %s", partNamesPath, err) } return partNames.Small, partNames.Big } - if !os.IsNotExist(err) { - logger.Panicf("FATAL: cannot read %s file: %s", partsFilename, err) - } // The partsFilename is missing. This is the upgrade from versions previous to v1.90.0. // Read part names from smallPartsPath and bigPartsPath directories partNamesSmall := mustReadPartNamesFromDir(smallPartsPath)