Skip to content

Commit

Permalink
fix lint errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Aug 16, 2020
1 parent 1eed341 commit 0e1b59f
Show file tree
Hide file tree
Showing 25 changed files with 102 additions and 89 deletions.
4 changes: 2 additions & 2 deletions storage/sector/faults.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import (
"github.com/filecoin-project/specs-actors/actors/abi"
)

// TODO: Track things more actively
// FaultTracker TODO: Track things more actively
type FaultTracker interface {
CheckProvable(ctx context.Context, spt abi.RegisteredSealProof, sectors []abi.SectorID) ([]abi.SectorID, error)
}

// Returns unprovable sectors
// CheckProvable returns unprovable sectors
func (m *Manager) CheckProvable(ctx context.Context, spt abi.RegisteredSealProof, sectors []abi.SectorID) ([]abi.SectorID, error) {
var bad []abi.SectorID

Expand Down
8 changes: 4 additions & 4 deletions storage/sector/ffiwrapper/basicfs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ type Provider struct {
}

func (b *Provider) AcquireSector(ctx context.Context, id abi.SectorID, existing stores.SectorFileType, allocate stores.SectorFileType, ptype stores.PathType) (stores.SectorPaths, func(), error) {
if err := os.Mkdir(filepath.Join(b.Root, stores.FTUnsealed.String()), 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(filepath.Join(b.Root, stores.FTUnsealed.String()), 0755); err != nil && !os.IsExist(err) { // nolint
return stores.SectorPaths{}, nil, err
}
if err := os.Mkdir(filepath.Join(b.Root, stores.FTSealed.String()), 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(filepath.Join(b.Root, stores.FTSealed.String()), 0755); err != nil && !os.IsExist(err) { // nolint
return stores.SectorPaths{}, nil, err
}
if err := os.Mkdir(filepath.Join(b.Root, stores.FTCache.String()), 0755); err != nil && !os.IsExist(err) {
if err := os.Mkdir(filepath.Join(b.Root, stores.FTCache.String()), 0755); err != nil && !os.IsExist(err) { // nolint
return stores.SectorPaths{}, nil, err
}

done := func() {}

out := stores.SectorPaths{
Id: id,
ID: id,
}

for _, fileType := range stores.PathTypes {
Expand Down
8 changes: 4 additions & 4 deletions storage/sector/ffiwrapper/partialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func writeTrailer(maxPieceSize int64, w *os.File, r rlepluslazy.RunIterator) err
}

func createPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFile, error) {
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644)
f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE, 0644) // nolint
if err != nil {
return nil, xerrors.Errorf("openning partial file '%s': %w", path, err)
}
Expand All @@ -82,7 +82,7 @@ func createPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialF
return nil
}()
if err != nil {
f.Close()
_ = f.Close()
return nil, err
}
if err := f.Close(); err != nil {
Expand All @@ -93,7 +93,7 @@ func createPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialF
}

func openPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFile, error) {
f, err := os.OpenFile(path, os.O_RDWR, 0644)
f, err := os.OpenFile(path, os.O_RDWR, 0644) // nolint
if err != nil {
return nil, xerrors.Errorf("openning partial file '%s': %w", path, err)
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func openPartialFile(maxPieceSize abi.PaddedPieceSize, path string) (*partialFil
return nil
}()
if err != nil {
f.Close()
_ = f.Close()
return nil, err
}

Expand Down
24 changes: 12 additions & 12 deletions storage/sector/ffiwrapper/sealer_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (sb *Sealer) pieceCid(in []byte) (cid.Cid, error) {
return cid.Undef, xerrors.Errorf("generating piece commitment: %w", err)
}

prf.Close()
_ = prf.Close()

return pieceCID, werr()
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector abi.SectorID, offset s
default:
return xerrors.Errorf("acquire unsealed sector path (existing): %w", err)
}
defer pf.Close()
defer pf.Close() // nolint

allocated, err := pf.Allocated()
if err != nil {
Expand All @@ -247,11 +247,11 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector abi.SectorID, offset s
}
defer srcDone()

sealed, err := os.OpenFile(srcPaths.Sealed, os.O_RDONLY, 0644)
sealed, err := os.OpenFile(srcPaths.Sealed, os.O_RDONLY, 0644) // nolint:gosec
if err != nil {
return xerrors.Errorf("opening sealed file: %w", err)
}
defer sealed.Close()
defer sealed.Close() // nolint

var at, nextat abi.PaddedPieceSize
first := true
Expand Down Expand Up @@ -287,7 +287,7 @@ func (sb *Sealer) UnsealPiece(ctx context.Context, sector abi.SectorID, offset s
{
go func() {
defer close(outWait)
defer opr.Close()
defer opr.Close() // nolint:errcheck

padwriter := fr32.NewPadWriter(out)
if err != nil {
Expand Down Expand Up @@ -377,18 +377,18 @@ func (sb *Sealer) ReadPiece(ctx context.Context, writer io.Writer, sector abi.Se

ok, err := pf.HasAllocated(offset, size)
if err != nil {
pf.Close()
_ = pf.Close()
return false, err
}

if !ok {
pf.Close()
_ = pf.Close()
return false, nil
}

f, err := pf.Reader(offset.Padded(), size.Padded())
if err != nil {
pf.Close()
_ = pf.Close()
return false, xerrors.Errorf("getting partial file reader: %w", err)
}

Expand All @@ -398,7 +398,7 @@ func (sb *Sealer) ReadPiece(ctx context.Context, writer io.Writer, sector abi.Se
}

if _, err := io.CopyN(writer, upr, int64(size)); err != nil {
pf.Close()
_ = pf.Close()
return false, xerrors.Errorf("reading unsealed file: %w", err)
}

Expand All @@ -416,23 +416,23 @@ func (sb *Sealer) SealPreCommit1(ctx context.Context, sector abi.SectorID, ticke
}
defer done()

e, err := os.OpenFile(paths.Sealed, os.O_RDWR|os.O_CREATE, 0644)
e, err := os.OpenFile(paths.Sealed, os.O_RDWR|os.O_CREATE, 0644) // nolint:gosec
if err != nil {
return nil, xerrors.Errorf("ensuring sealed file exists: %w", err)
}
if err := e.Close(); err != nil {
return nil, err
}

if err := os.Mkdir(paths.Cache, 0755); err != nil {
if err := os.Mkdir(paths.Cache, 0755); err != nil { // nolint
if os.IsExist(err) {
log.Warnf("existing cache in %s; removing", paths.Cache)

if err := os.RemoveAll(paths.Cache); err != nil {
return nil, xerrors.Errorf("remove existing sector cache from %s (sector %d): %w", paths.Cache, sector, err)
}

if err := os.Mkdir(paths.Cache, 0755); err != nil {
if err := os.Mkdir(paths.Cache, 0755); err != nil { // nolint:gosec
return nil, xerrors.Errorf("mkdir cache path after cleanup: %w", err)
}
} else {
Expand Down
10 changes: 6 additions & 4 deletions storage/sector/ffiwrapper/sealer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"context"
"fmt"
"github.com/ipfs/go-cid"
"io"
"io/ioutil"
"math/rand"
Expand All @@ -16,15 +15,18 @@ import (
"testing"
"time"

"github.com/ipfs/go-cid"

logging "github.com/ipfs/go-log"
"github.com/stretchr/testify/require"
"golang.org/x/xerrors"

ffi "github.com/filecoin-project/filecoin-ffi"
paramfetch "github.com/filecoin-project/go-paramfetch"
"github.com/filecoin-project/specs-actors/actors/abi"
"github.com/filecoin-project/specs-storage/storage"

ffi "github.com/filecoin-project/filecoin-ffi"

"github.com/filecoin-project/lotus/storage/sector/ffiwrapper/basicfs"
"github.com/filecoin-project/lotus/storage/sector/stores"
)
Expand Down Expand Up @@ -443,8 +445,8 @@ func BenchmarkWriteWithAlignment(b *testing.B) {
tf, _ := ioutil.TempFile("/tmp/", "scrb-")
b.StartTimer()

ffi.WriteWithAlignment(abi.RegisteredSealProof_StackedDrg2KiBV1, rf, bt, tf, nil)
w()
ffi.WriteWithAlignment(abi.RegisteredSealProof_StackedDrg2KiBV1, rf, bt, tf, nil) // nolint:errcheck
_ = w()
}
}

Expand Down
3 changes: 2 additions & 1 deletion storage/sector/ffiwrapper/unseal_ranges.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package ffiwrapper
import (
"golang.org/x/xerrors"

"github.com/filecoin-project/go-bitfield/rle"
rlepluslazy "github.com/filecoin-project/go-bitfield/rle"

"github.com/filecoin-project/specs-actors/actors/abi"

"github.com/filecoin-project/lotus/storage/sector/storiface"
Expand Down
6 changes: 4 additions & 2 deletions storage/sector/ffiwrapper/verifier_cgo.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ package ffiwrapper

import (
"context"

"golang.org/x/xerrors"

"go.opencensus.io/trace"
"github.com/filecoin-project/specs-actors/actors/abi"

ffi "github.com/filecoin-project/filecoin-ffi"
"github.com/filecoin-project/specs-actors/actors/abi"

"github.com/filecoin-project/lotus/storage/sector/stores"

"go.opencensus.io/trace"
)

func (sb *Sealer) GenerateWinningPoSt(ctx context.Context, minerID abi.ActorID, sectorInfo []abi.SectorInfo, randomness abi.PoStRandomness) ([]abi.PoStProof, error) {
Expand Down
4 changes: 2 additions & 2 deletions storage/sector/fr32/fr32.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ func mt(in, out []byte, padLen int, op func(unpadded, padded []byte)) {
wg.Wait()
}

// Assumes len(in)%127==0 and len(out)%128==0
func Pad(in, out []byte) {
// Assumes len(in)%127==0 and len(out)%128==0
if len(out) > int(MTTresh) {
mt(in, out, len(out), pad)
return
Expand Down Expand Up @@ -94,8 +94,8 @@ func pad(in, out []byte) {
}
}

// Assumes len(in)%128==0 and len(out)%127==0
func Unpad(in []byte, out []byte) {
// Assumes len(in)%128==0 and len(out)%127==0
if len(in) > int(MTTresh) {
mt(out, in, len(in), unpad)
return
Expand Down
9 changes: 5 additions & 4 deletions storage/sector/fr32/fr32_ffi_cmp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package fr32_test

import (
"bytes"
"github.com/filecoin-project/lotus/storage/sector/fr32"
"io"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
"github.com/filecoin-project/lotus/storage/sector/ffiwrapper"
"github.com/filecoin-project/lotus/storage/sector/fr32"

ffi "github.com/filecoin-project/filecoin-ffi"

"github.com/filecoin-project/specs-actors/actors/abi"

"github.com/filecoin-project/lotus/storage/sector/ffiwrapper"
"github.com/stretchr/testify/require"
)

func TestWriteTwoPcs(t *testing.T) {
Expand All @@ -39,7 +40,7 @@ func TestWriteTwoPcs(t *testing.T) {
}
}

if _, err := tf.Seek(io.SeekStart, 0); err != nil {
if _, err := tf.Seek(io.SeekStart, 0); err != nil { // nolint:staticcheck
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion storage/sector/fr32/fr32_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func padFFI(buf []byte) []byte {
panic(err)
}

if _, err := tf.Seek(io.SeekStart, 0); err != nil {
if _, err := tf.Seek(io.SeekStart, 0); err != nil { // nolint:staticcheck
panic(err)
}

Expand Down
2 changes: 1 addition & 1 deletion storage/sector/fsutil/filesize_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ func FileSize(path string) (SizeInfo, error) {
// NOTE: stat.Blocks is in 512B blocks, NOT in stat.Blksize
// See https://www.gnu.org/software/libc/manual/html_node/Attribute-Meanings.html
return SizeInfo{
int64(stat.Blocks) * 512, // NOTE: int64 cast is needed on osx
stat.Blocks * 512, // NOTE: int64 cast is needed on osx
}, nil
}
3 changes: 2 additions & 1 deletion storage/sector/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package sector
import (
"context"
"errors"
"github.com/filecoin-project/lotus/storage/sector/fsutil"
"io"
"net/http"

"github.com/filecoin-project/lotus/storage/sector/fsutil"

"github.com/ipfs/go-cid"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
Expand Down
14 changes: 7 additions & 7 deletions storage/sector/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/filecoin-project/lotus/storage/sector/fsutil"
"github.com/filecoin-project/lotus/storage/sector/sealtasks"
logging "github.com/ipfs/go-log"
"io/ioutil"
"os"
"path/filepath"
"strings"
"testing"

"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/filecoin-project/lotus/storage/sector/ffiwrapper"
"github.com/filecoin-project/lotus/storage/sector/fsutil"
"github.com/filecoin-project/lotus/storage/sector/sealtasks"
"github.com/filecoin-project/lotus/storage/sector/stores"

"github.com/filecoin-project/specs-actors/actors/abi"

"github.com/filecoin-project/lotus/storage/sector/ffiwrapper"
"github.com/filecoin-project/lotus/storage/sector/stores"
"github.com/google/uuid"
logging "github.com/ipfs/go-log"
"github.com/stretchr/testify/require"
)

func init() {
Expand Down
12 changes: 6 additions & 6 deletions storage/sector/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ func (mgr *SectorMgr) NewSector(ctx context.Context, sector abi.SectorID) error
return nil
}

func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorId abi.SectorID, existingPieces []abi.UnpaddedPieceSize, size abi.UnpaddedPieceSize, r io.Reader) (abi.PieceInfo, error) {
log.Warn("Add piece: ", sectorId, size, mgr.proofType)
func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorID abi.SectorID, existingPieces []abi.UnpaddedPieceSize, size abi.UnpaddedPieceSize, r io.Reader) (abi.PieceInfo, error) {
log.Warn("Add piece: ", sectorID, size, mgr.proofType)

var b bytes.Buffer
tr := io.TeeReader(r, &b)
Expand All @@ -92,12 +92,12 @@ func (mgr *SectorMgr) AddPiece(ctx context.Context, sectorId abi.SectorID, exist
mgr.lk.Lock()
mgr.pieces[c] = b.Bytes()

ss, ok := mgr.sectors[sectorId]
ss, ok := mgr.sectors[sectorID]
if !ok {
ss = &sectorState{
state: statePacking,
}
mgr.sectors[sectorId] = ss
mgr.sectors[sectorID] = ss
}
mgr.lk.Unlock()

Expand Down Expand Up @@ -260,7 +260,7 @@ func opFinishWait(ctx context.Context) {
func AddOpFinish(ctx context.Context) (context.Context, func()) {
done := make(chan struct{})

return context.WithValue(ctx, "opfinish", done), func() {
return context.WithValue(ctx, "opfinish", done), func() { // nolint
close(done)
}
}
Expand Down Expand Up @@ -338,7 +338,7 @@ func (mgr *SectorMgr) StageFakeData(mid abi.ActorID) (abi.SectorID, []abi.PieceI
}

buf := make([]byte, usize)
rand.Read(buf)
_, _ = rand.Read(buf) // nolint:gosec

id := abi.SectorID{
Miner: mid,
Expand Down
Loading

0 comments on commit 0e1b59f

Please sign in to comment.