Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Sharp authored and Alexey Sharp committed Apr 25, 2022
1 parent 8130a4d commit 038e02b
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions cmd/downloader/downloader/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,26 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow
}
if _, ok := s.t.TorrentClient.Torrent(infoHashes[i]); !ok {
magnet := mi.Magnet(&infoHashes[i], nil)
if _, err := s.t.TorrentClient.AddMagnet(magnet.String()); err != nil {
t, err := s.t.TorrentClient.AddMagnet(magnet.String())
if err != nil {
return nil, err
}
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-t.GotInfo():
metaInfo := t.Metainfo()
if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), &metaInfo); err != nil {
return nil, err
}
}
}
}
if len(infoHashes) == 1 {
t, ok := s.t.TorrentClient.Torrent(infoHashes[0])
if !ok {
return nil, fmt.Errorf("torrent not found: [%x]", infoHashes[0])
}
select {
case <-ctx.Done():
return nil, ctx.Err()
case <-t.GotInfo():
metaInfo := t.Metainfo()
if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), &metaInfo); err != nil {
return nil, err
}
}
t.AllowDataUpload()
t.AllowDataDownload()
if !t.Complete.Bool() {
Expand Down

0 comments on commit 038e02b

Please sign in to comment.