fix megacheck issues: os.SEEK_SET is deprecated: Use io.SeekStart, io.SeekCurrent, and io.SeekEnd.

This commit is contained in:
Mario Trangoni 2018-03-21 21:39:43 +01:00
parent 09142e4dd1
commit c0e888e82b
3 changed files with 10 additions and 9 deletions

View file

@ -133,7 +133,7 @@ func (w *Writer) finalizeTail() error {
return err return err
} }
// As the file was pre-allocated, we truncate any superfluous zero bytes. // As the file was pre-allocated, we truncate any superfluous zero bytes.
off, err := tf.Seek(0, os.SEEK_CUR) off, err := tf.Seek(0, io.SeekCurrent)
if err != nil { if err != nil {
return err return err
} }

8
wal.go
View file

@ -290,7 +290,7 @@ func (w *SegmentWAL) truncate(err error, file int, lastOffset int64) error {
w.files = w.files[:file+1] w.files = w.files[:file+1]
// Seek the current file to the last valid offset where we continue writing from. // Seek the current file to the last valid offset where we continue writing from.
_, err = w.files[file].Seek(lastOffset, os.SEEK_SET) _, err = w.files[file].Seek(lastOffset, io.SeekStart)
return err return err
} }
@ -393,7 +393,7 @@ func (w *SegmentWAL) Truncate(mint int64, keep func(uint64) bool) error {
return errors.Wrap(r.Err(), "read candidate WAL files") return errors.Wrap(r.Err(), "read candidate WAL files")
} }
off, err := csf.Seek(0, os.SEEK_CUR) off, err := csf.Seek(0, io.SeekCurrent)
if err != nil { if err != nil {
return err return err
} }
@ -583,7 +583,7 @@ func (w *SegmentWAL) cut() error {
// in the new segment. // in the new segment.
go func() { go func() {
w.actorc <- func() error { w.actorc <- func() error {
off, err := hf.Seek(0, os.SEEK_CUR) off, err := hf.Seek(0, io.SeekCurrent)
if err != nil { if err != nil {
return errors.Wrapf(err, "finish old segment %s", hf.Name()) return errors.Wrapf(err, "finish old segment %s", hf.Name())
} }
@ -1024,7 +1024,7 @@ func (r *walReader) next() bool {
// Remember the offset after the last correctly read entry. If the next one // Remember the offset after the last correctly read entry. If the next one
// is corrupted, this is where we can safely truncate. // is corrupted, this is where we can safely truncate.
r.lastOffset, r.err = cf.Seek(0, os.SEEK_CUR) r.lastOffset, r.err = cf.Seek(0, io.SeekCurrent)
if r.err != nil { if r.err != nil {
return false return false
} }

View file

@ -15,6 +15,7 @@ package tsdb
import ( import (
"encoding/binary" "encoding/binary"
"io"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"os" "os"
@ -305,7 +306,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer f.Close()
off, err := f.Seek(0, os.SEEK_END) off, err := f.Seek(0, io.SeekEnd)
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Ok(t, f.Truncate(off-1)) testutil.Ok(t, f.Truncate(off-1))
@ -318,7 +319,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer f.Close()
off, err := f.Seek(0, os.SEEK_END) off, err := f.Seek(0, io.SeekEnd)
testutil.Ok(t, err) testutil.Ok(t, err)
testutil.Ok(t, f.Truncate(off-8)) testutil.Ok(t, f.Truncate(off-8))
@ -331,7 +332,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer f.Close()
off, err := f.Seek(0, os.SEEK_END) off, err := f.Seek(0, io.SeekEnd)
testutil.Ok(t, err) testutil.Ok(t, err)
// Write junk before checksum starts. // Write junk before checksum starts.
@ -346,7 +347,7 @@ func TestWALRestoreCorrupted(t *testing.T) {
testutil.Ok(t, err) testutil.Ok(t, err)
defer f.Close() defer f.Close()
off, err := f.Seek(0, os.SEEK_END) off, err := f.Seek(0, io.SeekEnd)
testutil.Ok(t, err) testutil.Ok(t, err)
// Write junk into checksum // Write junk into checksum