httpdl: unify completed counter and dedupe mirror loop; engine: harden untrack
From a Rob Pike pass over the tree: - singleOnce adds deltas to d.completed like pump does, instead of storing absolute offsets, so the counter has one write discipline. - one overMirrors helper replaces the three copy-pasted mirror-fallover loops in probeRetry, fetchSeg and single. - failedDownload becomes a pointer, the only value-type Download impl, so Engine.untrack's == is always pointer identity and can't compare the fields of a value (keying on Stat().ID is out — a torrent's ID changes from source to infohash once metadata loads).
This commit is contained in:
10
main.go
10
main.go
@@ -190,9 +190,9 @@ type failedDownload struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (f failedDownload) Name() string { return f.name }
|
||||
func (f failedDownload) Run(context.Context) error { return f.err }
|
||||
func (f failedDownload) Stat() download.Stat {
|
||||
func (f *failedDownload) Name() string { return f.name }
|
||||
func (f *failedDownload) Run(context.Context) error { return f.err }
|
||||
func (f *failedDownload) Stat() download.Stat {
|
||||
return download.Stat{Name: f.name, Status: download.Errored, Total: -1}
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ func build(opts *cli.Options, targets []target) ([]job, *torrent.Client, error)
|
||||
u := t.uris[0] // primary: classifies the target and names the session source
|
||||
src := strings.Join(t.uris, "\t")
|
||||
if first, isDup := dups[u]; isDup {
|
||||
out = append(out, job{source: src, dl: failedDownload{
|
||||
out = append(out, job{source: src, dl: &failedDownload{
|
||||
name: u,
|
||||
err: fmt.Errorf("%w: same torrent as %s", errDuplicate, first),
|
||||
}})
|
||||
@@ -397,7 +397,7 @@ func followUps(jobs []job, client *torrent.Client, bo bt.Options) []job {
|
||||
// from under the other, stranding it at 0%. build() dedupes pass-1 sources
|
||||
// but cannot reach a not-yet-fetched HTTP .torrent, so dedupe here too.
|
||||
if first, dup := markInfoHash(seen, path); dup {
|
||||
out = append(out, job{source: path, dl: failedDownload{
|
||||
out = append(out, job{source: path, dl: &failedDownload{
|
||||
name: path,
|
||||
err: fmt.Errorf("%w: same torrent as %s", errDuplicate, first),
|
||||
}})
|
||||
|
||||
Reference in New Issue
Block a user