Replace uses of slices.Clone()
Avoid https://github.com/golang/go/issues/64759 Co-authored-by: Bjorn Neergaard <bjorn.neergaard@docker.com> Signed-off-by: Rob Murray <rob.murray@docker.com>
This commit is contained in:
parent
d19d98b136
commit
91d9307738
2 changed files with 9 additions and 11 deletions
|
@ -18,13 +18,11 @@ import (
|
|||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
_ "embed"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net/netip"
|
||||
"os"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
@ -141,7 +139,7 @@ func (rc *ResolvConf) SetHeader(c string) {
|
|||
|
||||
// NameServers returns addresses used in nameserver directives.
|
||||
func (rc *ResolvConf) NameServers() []netip.Addr {
|
||||
return slices.Clone(rc.nameServers)
|
||||
return append([]netip.Addr(nil), rc.nameServers...)
|
||||
}
|
||||
|
||||
// OverrideNameServers replaces the current set of nameservers.
|
||||
|
@ -152,7 +150,7 @@ func (rc *ResolvConf) OverrideNameServers(nameServers []netip.Addr) {
|
|||
|
||||
// Search returns the current DNS search domains.
|
||||
func (rc *ResolvConf) Search() []string {
|
||||
return slices.Clone(rc.search)
|
||||
return append([]string(nil), rc.search...)
|
||||
}
|
||||
|
||||
// OverrideSearch replaces the current DNS search domains.
|
||||
|
@ -169,7 +167,7 @@ func (rc *ResolvConf) OverrideSearch(search []string) {
|
|||
|
||||
// Options returns the current options.
|
||||
func (rc *ResolvConf) Options() []string {
|
||||
return slices.Clone(rc.options)
|
||||
return append([]string(nil), rc.options...)
|
||||
}
|
||||
|
||||
// Option finds the last option named search, and returns (value, true) if
|
||||
|
@ -192,7 +190,7 @@ func (rc *ResolvConf) Option(search string) (string, bool) {
|
|||
|
||||
// OverrideOptions replaces the current DNS options.
|
||||
func (rc *ResolvConf) OverrideOptions(options []string) {
|
||||
rc.options = slices.Clone(options)
|
||||
rc.options = append([]string(nil), options...)
|
||||
rc.md.NDotsFrom = ""
|
||||
if _, exists := rc.Option("ndots"); exists {
|
||||
rc.md.NDotsFrom = "override"
|
||||
|
@ -314,7 +312,7 @@ func (rc *ResolvConf) TransformForIntNS(
|
|||
}
|
||||
|
||||
rc.md.Transform = "internal resolver"
|
||||
return slices.Clone(rc.md.ExtNameServers), nil
|
||||
return append([]ExtDNSEntry(nil), rc.md.ExtNameServers...), nil
|
||||
}
|
||||
|
||||
// Generate returns content suitable for writing to a resolv.conf file. If comments
|
||||
|
|
|
@ -221,15 +221,15 @@ func TestRCModify(t *testing.T) {
|
|||
rc.OverrideSearch(tc.overrideSearch)
|
||||
rc.OverrideOptions(tc.overrideOptions)
|
||||
|
||||
assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateComparable(netip.Addr{})))
|
||||
assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch))
|
||||
assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions))
|
||||
assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateEmpty(), cmpopts.EquateComparable(netip.Addr{})))
|
||||
assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch, cmpopts.EquateEmpty()))
|
||||
assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions, cmpopts.EquateEmpty()))
|
||||
}
|
||||
|
||||
if tc.addOption != "" {
|
||||
options := rc.Options()
|
||||
rc.AddOption(tc.addOption)
|
||||
assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption)))
|
||||
assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption), cmpopts.EquateEmpty()))
|
||||
}
|
||||
|
||||
d := t.TempDir()
|
||||
|
|
Loading…
Reference in a new issue