lib/{mergeset,storage}: make mustReadPartNames() code more clear

This commit is contained in:
Aliaksandr Valialkin 2023-04-14 23:16:26 -07:00
parent d739511f5b
commit 8b15f93426
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
2 changed files with 10 additions and 10 deletions

View file

@ -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)

View file

@ -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)