Fix some DeepSource lints
This commit is contained in:
parent
a0ec0f2708
commit
bf6e64a652
@ -86,7 +86,7 @@ func TestTorrentInitialState(t *testing.T) {
|
||||
)
|
||||
tor.setChunkSize(2)
|
||||
tor.cl.lock()
|
||||
err := tor.setInfoBytes(mi.InfoBytes)
|
||||
err := tor.setInfoBytesLocked(mi.InfoBytes)
|
||||
tor.cl.unlock()
|
||||
require.NoError(t, err)
|
||||
require.Len(t, tor.pieces, 3)
|
||||
|
10
torrent.go
10
torrent.go
@ -449,7 +449,7 @@ func (t *Torrent) onSetInfo() {
|
||||
}
|
||||
|
||||
// Called when metadata for a torrent becomes available.
|
||||
func (t *Torrent) setInfoBytes(b []byte) error {
|
||||
func (t *Torrent) setInfoBytesLocked(b []byte) error {
|
||||
if metainfo.HashBytes(b) != t.infoHash {
|
||||
return errors.New("info bytes have wrong hash")
|
||||
}
|
||||
@ -1280,7 +1280,7 @@ func (t *Torrent) maybeCompleteMetadata() error {
|
||||
// Don't have enough metadata pieces.
|
||||
return nil
|
||||
}
|
||||
err := t.setInfoBytes(t.metadataBytes)
|
||||
err := t.setInfoBytesLocked(t.metadataBytes)
|
||||
if err != nil {
|
||||
t.invalidateMetadata()
|
||||
return fmt.Errorf("error setting info bytes: %s", err)
|
||||
@ -1355,7 +1355,7 @@ func (t *Torrent) bytesCompleted() int64 {
|
||||
func (t *Torrent) SetInfoBytes(b []byte) (err error) {
|
||||
t.cl.lock()
|
||||
defer t.cl.unlock()
|
||||
return t.setInfoBytes(b)
|
||||
return t.setInfoBytesLocked(b)
|
||||
}
|
||||
|
||||
// Returns true if connection is removed from torrent.Conns.
|
||||
@ -1658,7 +1658,7 @@ func (t *Torrent) AnnounceToDht(s DhtServer) (done <-chan struct{}, stop func(),
|
||||
return
|
||||
}
|
||||
|
||||
func (t *Torrent) announceToDht(s DhtServer) error {
|
||||
func (t *Torrent) timeboxedAnnounceToDht(s DhtServer) error {
|
||||
_, stop, err := t.AnnounceToDht(s)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -1695,7 +1695,7 @@ func (t *Torrent) dhtAnnouncer(s DhtServer) {
|
||||
t.numDHTAnnounces++
|
||||
cl.unlock()
|
||||
defer cl.lock()
|
||||
err := t.announceToDht(s)
|
||||
err := t.timeboxedAnnounceToDht(s)
|
||||
if err != nil {
|
||||
t.logger.WithDefaultLevel(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
|
||||
}
|
||||
|
@ -147,7 +147,7 @@ func TestPieceHashFailed(t *testing.T) {
|
||||
cl.initLogger()
|
||||
tt := cl.newTorrent(mi.HashInfoBytes(), badStorage{})
|
||||
tt.setChunkSize(2)
|
||||
require.NoError(t, tt.setInfoBytes(mi.InfoBytes))
|
||||
require.NoError(t, tt.setInfoBytesLocked(mi.InfoBytes))
|
||||
tt.cl.lock()
|
||||
tt.pieces[1]._dirtyChunks.AddRange(0, 3)
|
||||
require.True(t, tt.pieceAllDirty(1))
|
||||
|
Loading…
x
Reference in New Issue
Block a user