diff --git a/weed/command/fix.go b/weed/command/fix.go index 6339fc88a0..eb318fb18c 100644 --- a/weed/command/fix.go +++ b/weed/command/fix.go @@ -197,7 +197,7 @@ func fixEcxFromShardsInDir(basePath string, files []fs.DirEntry) bool { func SaveToIdx(scaner *VolumeFileScanner4Fix, idxName string) (ret error) { idxFile, err := os.OpenFile(idxName, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { - return + return err } defer func() { idxFile.Close() diff --git a/weed/command/fix_test.go b/weed/command/fix_test.go index d74c7d8917..f4d1e8abc5 100644 --- a/weed/command/fix_test.go +++ b/weed/command/fix_test.go @@ -260,3 +260,11 @@ func TestFixTruncatedDeleteKeepsKeyDeleted(t *testing.T) { } } } + +func TestSaveToIdxReportsOpenError(t *testing.T) { + nm := needle_map.NewMemDb() + defer nm.Close() + if err := SaveToIdx(&VolumeFileScanner4Fix{nm: nm}, t.TempDir()); err == nil { + t.Error("expected an error when the .idx path cannot be opened") + } +}