Skip to content

Commit 8a13ba6

Browse files
committed
drop torrent when download completes
1 parent a689bd5 commit 8a13ba6

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

engine/kedgeClient.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@ type TorrentProps struct {
101101
Meta *metainfo.MetaInfo
102102
}
103103

104-
func NewKedgeDownloadListener(client kedge.ClientI, props *TorrentProps, listener *MirrorListener, statusGetter func(string) (*TorrentStatus, error), isSeed bool) *KedgeDownloadListener {
104+
func NewKedgeDownloadListener(client kedge.ClientI, props *TorrentProps, listener *MirrorListener, statusGetter func(string) (*TorrentStatus, error), stopTorrent func(string) error, isSeed bool) *KedgeDownloadListener {
105105
return &KedgeDownloadListener{
106106
client: client,
107107
props: props,
108108
listener: listener,
109109
statusGetter: statusGetter,
110+
stopTorrent: stopTorrent,
110111
isSeed: isSeed,
111112
}
112113
}
@@ -117,6 +118,7 @@ type KedgeDownloadListener struct {
117118
listener *MirrorListener
118119
IsListenerRunning bool
119120
statusGetter func(string) (*TorrentStatus, error)
121+
stopTorrent func(string) error
120122
IsQueued bool
121123
haveInfo bool
122124
isSeed bool
@@ -147,6 +149,11 @@ func (k *KedgeDownloadListener) OnDownloadComplete() {
147149
if k.isSeed {
148150
k.IsSeeding = true
149151
k.OnSeedingStart()
152+
} else {
153+
err := k.stopTorrent(k.props.Spec.InfoHash.HexString())
154+
if err != nil {
155+
L().Errorf("kedge error while stopping torrent in download complete: %v", err)
156+
}
150157
}
151158
k.listener.OnDownloadComplete()
152159
}
@@ -368,7 +375,7 @@ func (k *KedgeDownloader) PrepDownload(gid string, link string, dir string, list
368375
}
369376
listener.isTorrent = true
370377
listener.isSeed = isSeed
371-
kedgeListener := NewKedgeDownloadListener(k.client, props, listener, k.GetTorrentStatus, isSeed)
378+
kedgeListener := NewKedgeDownloadListener(k.client, props, listener, k.GetTorrentStatus, k.client.Drop, isSeed)
372379
kedgeListener.StartListener()
373380
status := NewKedgeDownloadStatus(gid, listener, kedgeListener, k.GetTorrentStatus, k.client.Drop, props)
374381
status.Index_ = index

0 commit comments

Comments
 (0)