2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Fix some DeepSource lints

This commit is contained in:
Matt Joiner 2021-08-30 11:48:34 +10:00
parent a0ec0f2708
commit bf6e64a652
3 changed files with 7 additions and 7 deletions

View File

@ -86,7 +86,7 @@ func TestTorrentInitialState(t *testing.T) {
) )
tor.setChunkSize(2) tor.setChunkSize(2)
tor.cl.lock() tor.cl.lock()
err := tor.setInfoBytes(mi.InfoBytes) err := tor.setInfoBytesLocked(mi.InfoBytes)
tor.cl.unlock() tor.cl.unlock()
require.NoError(t, err) require.NoError(t, err)
require.Len(t, tor.pieces, 3) require.Len(t, tor.pieces, 3)

View File

@ -449,7 +449,7 @@ func (t *Torrent) onSetInfo() {
} }
// Called when metadata for a torrent becomes available. // 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 { if metainfo.HashBytes(b) != t.infoHash {
return errors.New("info bytes have wrong hash") return errors.New("info bytes have wrong hash")
} }
@ -1280,7 +1280,7 @@ func (t *Torrent) maybeCompleteMetadata() error {
// Don't have enough metadata pieces. // Don't have enough metadata pieces.
return nil return nil
} }
err := t.setInfoBytes(t.metadataBytes) err := t.setInfoBytesLocked(t.metadataBytes)
if err != nil { if err != nil {
t.invalidateMetadata() t.invalidateMetadata()
return fmt.Errorf("error setting info bytes: %s", err) 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) { func (t *Torrent) SetInfoBytes(b []byte) (err error) {
t.cl.lock() t.cl.lock()
defer t.cl.unlock() defer t.cl.unlock()
return t.setInfoBytes(b) return t.setInfoBytesLocked(b)
} }
// Returns true if connection is removed from torrent.Conns. // 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 return
} }
func (t *Torrent) announceToDht(s DhtServer) error { func (t *Torrent) timeboxedAnnounceToDht(s DhtServer) error {
_, stop, err := t.AnnounceToDht(s) _, stop, err := t.AnnounceToDht(s)
if err != nil { if err != nil {
return err return err
@ -1695,7 +1695,7 @@ func (t *Torrent) dhtAnnouncer(s DhtServer) {
t.numDHTAnnounces++ t.numDHTAnnounces++
cl.unlock() cl.unlock()
defer cl.lock() defer cl.lock()
err := t.announceToDht(s) err := t.timeboxedAnnounceToDht(s)
if err != nil { if err != nil {
t.logger.WithDefaultLevel(log.Warning).Printf("error announcing %q to DHT: %s", t, err) t.logger.WithDefaultLevel(log.Warning).Printf("error announcing %q to DHT: %s", t, err)
} }

View File

@ -147,7 +147,7 @@ func TestPieceHashFailed(t *testing.T) {
cl.initLogger() cl.initLogger()
tt := cl.newTorrent(mi.HashInfoBytes(), badStorage{}) tt := cl.newTorrent(mi.HashInfoBytes(), badStorage{})
tt.setChunkSize(2) tt.setChunkSize(2)
require.NoError(t, tt.setInfoBytes(mi.InfoBytes)) require.NoError(t, tt.setInfoBytesLocked(mi.InfoBytes))
tt.cl.lock() tt.cl.lock()
tt.pieces[1]._dirtyChunks.AddRange(0, 3) tt.pieces[1]._dirtyChunks.AddRange(0, 3)
require.True(t, tt.pieceAllDirty(1)) require.True(t, tt.pieceAllDirty(1))