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:
@@ -122,7 +122,7 @@ var options = []Opt{
|
||||
{Long: "allow-overwrite", Kind: Bool, Default: "false", Help: "overwrite an existing file", Tag: Advanced},
|
||||
{Long: "auto-file-renaming", Kind: Bool, Default: "true", Help: "rename file (.1, .2, ...) if it already exists", Tag: Advanced},
|
||||
{Long: "human-readable", Kind: Bool, Default: "true", Help: "show sizes as Ki/Mi/Gi", Tag: Advanced},
|
||||
{Long: "file-allocation", Short: 'a', Kind: Enum, Default: "prealloc", Enum: []string{"none", "prealloc", "trunc", "falloc"}, Help: "how to allocate disk space", Tag: Advanced},
|
||||
{Long: "file-allocation", Short: 'a', Kind: Enum, Default: "prealloc", Enum: []string{"none", "prealloc", "trunc", "falloc"}, Help: "how to reserve disk space (prealloc and falloc are identical here)", Tag: Advanced},
|
||||
{Long: "dry-run", Kind: Bool, Default: "false", Help: "check that the file is available but do not download it", Tag: Advanced},
|
||||
{Long: "stop", Kind: Int, Default: "0", Min: 0, Help: "stop the program after N seconds (0 = off)", Tag: Advanced},
|
||||
{Long: "disable-ipv6", Kind: Bool, Default: "false", Help: "disable IPv6 (force IPv4-only connections)", Tag: Advanced},
|
||||
|
||||
@@ -27,13 +27,14 @@ func (o *Options) IsSet(name string) bool { return o.set[name] }
|
||||
// Str returns the raw string value (empty if unset and no default).
|
||||
func (o *Options) Str(name string) string { return o.vals[name] }
|
||||
|
||||
// boolWords is the single accepted vocabulary for boolean options, mapping each
|
||||
// recognised spelling to its truth value. The Bool reader, truthy, and
|
||||
// validate() all consult it, so exactly the words that validate are honoured
|
||||
// (no "accepted by the reader but rejected by validate" surprises like --x=on).
|
||||
// boolWords is the accepted vocabulary for boolean options. aria2 takes only
|
||||
// true/false (and rejects everything else), so we match it rather than inventing
|
||||
// extra spellings. boolWord is the single consult point — the Bool reader,
|
||||
// validate(), and the no-conf bootstrap all go through it — so exactly the words
|
||||
// that validate are honoured.
|
||||
var boolWords = map[string]bool{
|
||||
"true": true, "yes": true, "1": true, "on": true,
|
||||
"false": false, "no": false, "0": false, "off": false,
|
||||
"true": true,
|
||||
"false": false,
|
||||
}
|
||||
|
||||
// boolWord reports a value's truth and whether it is a recognised boolean word.
|
||||
|
||||
@@ -139,13 +139,17 @@ func TestValidateFloatNonNegative(t *testing.T) {
|
||||
|
||||
func TestValidateBool(t *testing.T) {
|
||||
b := byLong["enable-dht"]
|
||||
for _, ok := range []string{"true", "false", "yes", "no", "1", "0", "on", "off"} {
|
||||
// aria2 accepts only true/false; the invented yes/no/1/0/on/off spellings
|
||||
// were removed, so they must now fail validation.
|
||||
for _, ok := range []string{"true", "false"} {
|
||||
if err := validate(b, ok); err != nil {
|
||||
t.Errorf("validate bool %q: %v", ok, err)
|
||||
}
|
||||
}
|
||||
if err := validate(b, "flase"); err == nil {
|
||||
t.Errorf("validate bool flase: want error")
|
||||
for _, bad := range []string{"yes", "no", "1", "0", "on", "off", "flase"} {
|
||||
if err := validate(b, bad); err == nil {
|
||||
t.Errorf("validate bool %q: want error (only true/false accepted)", bad)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user