Skip to content

Commit 4eda384

Browse files
author
NullpointerW
committed
u
1 parent 877046b commit 4eda384

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

downloader/builtin/monitor.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (l *TorrentProgressList) Put(dirty []TorrentProgress) {
2323
}
2424
for _, t := range dirty {
2525
if idx, ex := l.list[t.Name]; !ex {
26-
l.list[t.Name] = len(l.clean)
26+
l.list[t.Name] = len(l.clean)
2727
l.clean = append(l.clean, t)
2828
} else {
2929
l.clean[idx] = t
@@ -53,10 +53,6 @@ type TorrentProgress struct {
5353
Percentage int `json:"percentage"`
5454
Name string `json:"name"`
5555
}
56-
// type TorrentProgressElem struct {
57-
// idx int
58-
// TorrentProgress
59-
// }
6056

6157
type TorrentProgressMonitor struct {
6258
mu sync.Mutex
@@ -120,7 +116,7 @@ type MonitoredTorrent struct {
120116
Url string
121117
}
122118
type torrentState struct {
123-
m MonitoredTorrent
119+
MonitoredTorrent
124120
gotInfo bool
125121
}
126122

@@ -149,12 +145,12 @@ func MonitorBuiltin(recv, send chan MonitoredTorrent, ctx context.Context, monit
149145
close(recv)
150146
close(send)
151147
for _, t := range torrents {
152-
t.m.Torrent.Drop()
148+
t.Torrent.Drop()
153149
}
154150
return
155151
} else if c == 1 { // recv
156152
mt := v.Interface().(MonitoredTorrent)
157-
ts := torrentState{m: mt, gotInfo: false}
153+
ts := torrentState{MonitoredTorrent: mt, gotInfo: false}
158154
gch := mt.Torrent.GotInfo()
159155
torrents[reflect.ValueOf(gch).Pointer()] = ts
160156
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(gch)})
@@ -167,20 +163,21 @@ func MonitorBuiltin(recv, send chan MonitoredTorrent, ctx context.Context, monit
167163
}
168164
delete(torrents, ptr)
169165
if ts.gotInfo { // push
170-
ts.m.Size = ts.m.Torrent.Length()
171-
fmt.Printf("bultin-detector: download complete :%+v \n", ts.m)
172-
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectSend, Chan: reflect.ValueOf(send), Send: reflect.ValueOf(ts.m)})
166+
ts.Size = ts.Torrent.Length()
167+
fmt.Printf("bultin-detector: download complete :%+v \n", ts.MonitoredTorrent)
168+
ts.Torrent.Drop()
169+
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectSend, Chan: reflect.ValueOf(send), Send: reflect.ValueOf(ts.MonitoredTorrent)})
173170
} else { // download
174171
ts.gotInfo = true
175-
ts.m.Torrent.DownloadAll()
176-
dch := ts.m.Torrent.Complete.On()
177-
if ts.m.Rename == "" {
178-
ts.m.Rename = ts.m.Torrent.Name()
172+
ts.Torrent.DownloadAll()
173+
dch := ts.Torrent.Complete.On()
174+
if ts.Rename == "" {
175+
ts.Rename = ts.Torrent.Name()
179176
}
180177
torrents[reflect.ValueOf(dch).Pointer()] = ts
181178
cases = append(cases, reflect.SelectCase{Dir: reflect.SelectRecv, Chan: reflect.ValueOf(dch)})
182-
monitor.AddTorrent(ts.m.TorrentInfo)
183-
fmt.Printf("bultin-detector: got torrent info ok,downloading :%+v \n", ts.m)
179+
monitor.AddTorrent(ts.TorrentInfo)
180+
fmt.Printf("bultin-detector: got torrent info ok,downloading :%+v \n", ts.MonitoredTorrent)
184181
}
185182
cleancases:
186183
cases = util.SliceDelete(cases, c)

0 commit comments

Comments
 (0)