From 02b9f09012b4b58925522eda3612cfcc7f28139a Mon Sep 17 00:00:00 2001 From: HuangYi Date: Thu, 9 Feb 2023 02:08:27 +0800 Subject: [PATCH] fix lint warnings --- wal.go | 13 +++++++++---- wal_test.go | 17 +++++++++++------ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/wal.go b/wal.go index ab5eac8..a27c68a 100644 --- a/wal.go +++ b/wal.go @@ -7,7 +7,6 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "os" "path/filepath" "strconv" @@ -173,7 +172,7 @@ func (l *Log) pushCache(segIdx int) { // load all the segments. This operation also cleans up any START/END segments. func (l *Log) load() error { - fis, err := ioutil.ReadDir(l.path) + fis, err := os.ReadDir(l.path) if err != nil { return err } @@ -530,14 +529,14 @@ func (l *Log) findSegment(index uint64) int { } func (l *Log) loadSegmentEntries(s *segment) error { - data, err := ioutil.ReadFile(s.path) + data, err := os.ReadFile(s.path) if err != nil { return err } ebuf := data var epos []bpos var pos int - for exidx := s.index; len(data) > 0; exidx++ { + for len(data) > 0 { var n int if l.opts.LogFormat == JSON { n, err = loadNextJSONEntry(data) @@ -742,6 +741,9 @@ func (l *Log) truncateFront(index uint64) (err error) { } return f.Close() }() + if err != nil { + return err + } // Rename the TEMP file to it's START file name. startName := filepath.Join(l.path, segmentName(index)+".START") if err = os.Rename(tempName, startName); err != nil { @@ -848,6 +850,9 @@ func (l *Log) truncateBack(index uint64) (err error) { } return f.Close() }() + if err != nil { + return err + } // Rename the TEMP file to it's END file name. endName := filepath.Join(l.path, segmentName(s.index)+".END") if err = os.Rename(tempName, endName); err != nil { diff --git a/wal_test.go b/wal_test.go index b23a002..4843fc6 100644 --- a/wal_test.go +++ b/wal_test.go @@ -414,7 +414,9 @@ func testLog(t *testing.T, opts *Options, N int) { } N++ - l.Sync() + if err = l.Sync(); err != nil { + t.Fatal(err) + } testFirstLast(t, l, uint64(N-1), uint64(N), nil) } @@ -519,29 +521,32 @@ func TestOutliers(t *testing.T) { t.Run("fail-corrupted-tail-json", func(t *testing.T) { defer os.RemoveAll("testlog/corrupt-tail") opts := makeOpts(512, true, JSON) - os.MkdirAll("testlog/corrupt-tail", 0777) - ioutil.WriteFile( + if err := os.MkdirAll("testlog/corrupt-tail", 0777); err != nil { + t.Fatal(err) + } + + _ = ioutil.WriteFile( "testlog/corrupt-tail/00000000000000000001", []byte("\n"), 0666) if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt { l.Close() t.Fatalf("expected %v, got %v", ErrCorrupt, err) } - ioutil.WriteFile( + _ = ioutil.WriteFile( "testlog/corrupt-tail/00000000000000000001", []byte(`{}`+"\n"), 0666) if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt { l.Close() t.Fatalf("expected %v, got %v", ErrCorrupt, err) } - ioutil.WriteFile( + _ = ioutil.WriteFile( "testlog/corrupt-tail/00000000000000000001", []byte(`{"index":"1"}`+"\n"), 0666) if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt { l.Close() t.Fatalf("expected %v, got %v", ErrCorrupt, err) } - ioutil.WriteFile( + _ = ioutil.WriteFile( "testlog/corrupt-tail/00000000000000000001", []byte(`{"index":"1","data":"?"}`), 0666) if l, err := Open("testlog/corrupt-tail", opts); err != ErrCorrupt {