all: cut bloat found in the pike audit
Dead, vestigial, and over-built code with no behavior change (except the
bool-vocabulary trim, a deliberate behavior tightening):
- httpdl: drop the vestigial sort+copy in validSegs (work-stealing was
removed in 270812d, so segments always tile [0,total) ascending now);
validate order in place, which also rejects a scrambled sidecar. Inline
the endOff() accessor to s.end.
- cli: shrink the boolean vocabulary to true/false, which is all that's
accepted. The invented yes/no/1/0/on/off spellings are gone, so e.g.
--enable-dht=yes (or yes in got.conf) is now a usage error.
- download: remove the dead, never-called Stat.Done() method.
- progress: drop speed(), a pure alias of humanSize; call humanSize directly.
- main: replace the jobsHolder mutex box with atomic.Pointer[[]job] for the
forced-exit session save; the capability stays, the lock and type go.
- bt: collapse isAddrInUse's X||X (missinggo.IsAddrInUse is that exact
string match); drop the now-unused missinggo import (tidy -> indirect).
- option: note that prealloc and falloc are identical here.
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
@@ -34,7 +33,7 @@ func controlPath(out string) string { return out + ".got" }
|
||||
func snapshot(url string, total int64, etag, lastmod string, segs []seg) control {
|
||||
c := control{URL: url, Total: total, ETag: etag, LastModified: lastmod, Segs: make([]segState, len(segs))}
|
||||
for i := range segs {
|
||||
c.Segs[i] = segState{segs[i].start, segs[i].endOff(), atomic.LoadInt64(&segs[i].written)}
|
||||
c.Segs[i] = segState{segs[i].start, segs[i].end, atomic.LoadInt64(&segs[i].written)}
|
||||
}
|
||||
return c
|
||||
}
|
||||
@@ -88,16 +87,15 @@ func loadControl(out, url string, total int64, etag, lastmod string) *control {
|
||||
}
|
||||
|
||||
// validSegs reports whether segs cover [0,total) with no gap or overlap and a
|
||||
// sane written count for each. The recorded order is not sorted (a steal appends
|
||||
// a tail), so we check coverage on a sorted copy.
|
||||
// sane written count for each. got always writes segments in ascending start
|
||||
// order, so coverage is checked in place; an out-of-order sidecar (only possible
|
||||
// from a hand-edited or corrupted file) is rejected, which restarts cleanly.
|
||||
func validSegs(segs []segState, total int64) bool {
|
||||
if total <= 0 || len(segs) == 0 {
|
||||
return false
|
||||
}
|
||||
sorted := append([]segState(nil), segs...)
|
||||
sort.Slice(sorted, func(i, j int) bool { return sorted[i].Start < sorted[j].Start })
|
||||
var next int64
|
||||
for _, s := range sorted {
|
||||
for _, s := range segs {
|
||||
length := s.End - s.Start + 1
|
||||
if s.Start != next || s.End < s.Start || s.Written < 0 || s.Written > length {
|
||||
return false
|
||||
|
||||
Reference in New Issue
Block a user