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:
2026-06-21 15:45:56 +09:00
parent 3eb2d5ffcb
commit 10672f3816
14 changed files with 47 additions and 75 deletions

View File

@@ -41,12 +41,6 @@ func humanSize(n int64, human bool) string {
return fmt.Sprintf("%.0f%ciB", val, suffix)
}
// speed formats a bytes-per-second rate. The DL:/UL: fields show the bare
// abbreviated size with no "/s" suffix.
func speed(bytesPerSec int64, human bool) string {
return humanSize(bytesPerSec, human)
}
// secfmt renders a duration as "1h2m3s", appending each unit only when it is
// nonzero (but still showing seconds when the whole input is 0):
// 3600s->"1h", 120s->"2m", 3720s->"1h2m". A non-positive or absurd

View File

@@ -53,16 +53,6 @@ func TestSecfmt(t *testing.T) {
}
}
func TestSpeedNoSuffix(t *testing.T) {
// The DL:/UL: fields show the bare abbreviated size with no "/s".
if got := speed(1536, true); got != "1.5KiB" {
t.Errorf("speed(1536,true) = %q, want %q", got, "1.5KiB")
}
if got := speed(2048, false); got != "2048B" {
t.Errorf("speed(2048,false) = %q, want %q", got, "2048B")
}
}
func TestPercent(t *testing.T) {
if got := percent(50, 100); got != 50 {
t.Errorf("percent(50,100) = %d, want 50", got)

View File

@@ -147,10 +147,10 @@ func (r *Reporter) lineOne(s download.Stat) string {
fmt.Fprintf(&b, " SD:%d", s.Seeders)
}
if !seeding {
fmt.Fprintf(&b, " DL:%s", speed(dl, r.human))
fmt.Fprintf(&b, " DL:%s", humanSize(dl, r.human))
}
if seeding || ul > 0 {
fmt.Fprintf(&b, " UL:%s", speed(ul, r.human))
fmt.Fprintf(&b, " UL:%s", humanSize(ul, r.human))
}
if !seeding && s.Total > 0 && dl > 0 {
fmt.Fprintf(&b, " ETA:%s", secfmt(etaDuration(s.Total-s.Completed, dl)))
@@ -227,7 +227,7 @@ func (r *Reporter) summary(stats []download.Stat) string {
stalled++
}
}
line := fmt.Sprintf("%d active DL:%s UL:%s", len(stats)-waiting, speed(totDL, r.human), speed(totUL, r.human))
line := fmt.Sprintf("%d active DL:%s UL:%s", len(stats)-waiting, humanSize(totDL, r.human), humanSize(totUL, r.human))
if waiting > 0 {
line += fmt.Sprintf(" (%d waiting)", waiting)
}
@@ -254,13 +254,13 @@ func (r *Reporter) rowMetric(s download.Stat, dl, ul int64) (metric, tail string
case download.Waiting:
return "queued", ""
case download.Seeding:
return "seeding", "UL:" + speed(ul, r.human)
return "seeding", "UL:" + humanSize(ul, r.human)
case download.Complete:
return "done", ""
case download.Errored:
return "failed", ""
default:
metric = "DL:" + speed(dl, r.human)
metric = "DL:" + humanSize(dl, r.human)
switch {
case dl > 0 && s.Total > 0:
tail = secfmt(etaDuration(s.Total-s.Completed, dl))