Skip to content

Commit 97a5435

Browse files
authored
Merge pull request moby#47477 from robmry/resolvconf_gocompat
Remove slices.Clone() calls to avoid Go bug
2 parents 137a9d6 + 91d9307 commit 97a5435

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

libnetwork/internal/resolvconf/resolvconf.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,11 @@ import (
1818
"bufio"
1919
"bytes"
2020
"context"
21-
_ "embed"
2221
"fmt"
2322
"io"
2423
"io/fs"
2524
"net/netip"
2625
"os"
27-
"slices"
2826
"strconv"
2927
"strings"
3028
"text/template"
@@ -141,7 +139,7 @@ func (rc *ResolvConf) SetHeader(c string) {
141139

142140
// NameServers returns addresses used in nameserver directives.
143141
func (rc *ResolvConf) NameServers() []netip.Addr {
144-
return slices.Clone(rc.nameServers)
142+
return append([]netip.Addr(nil), rc.nameServers...)
145143
}
146144

147145
// OverrideNameServers replaces the current set of nameservers.
@@ -152,7 +150,7 @@ func (rc *ResolvConf) OverrideNameServers(nameServers []netip.Addr) {
152150

153151
// Search returns the current DNS search domains.
154152
func (rc *ResolvConf) Search() []string {
155-
return slices.Clone(rc.search)
153+
return append([]string(nil), rc.search...)
156154
}
157155

158156
// OverrideSearch replaces the current DNS search domains.
@@ -169,7 +167,7 @@ func (rc *ResolvConf) OverrideSearch(search []string) {
169167

170168
// Options returns the current options.
171169
func (rc *ResolvConf) Options() []string {
172-
return slices.Clone(rc.options)
170+
return append([]string(nil), rc.options...)
173171
}
174172

175173
// Option finds the last option named search, and returns (value, true) if
@@ -192,7 +190,7 @@ func (rc *ResolvConf) Option(search string) (string, bool) {
192190

193191
// OverrideOptions replaces the current DNS options.
194192
func (rc *ResolvConf) OverrideOptions(options []string) {
195-
rc.options = slices.Clone(options)
193+
rc.options = append([]string(nil), options...)
196194
rc.md.NDotsFrom = ""
197195
if _, exists := rc.Option("ndots"); exists {
198196
rc.md.NDotsFrom = "override"
@@ -314,7 +312,7 @@ func (rc *ResolvConf) TransformForIntNS(
314312
}
315313

316314
rc.md.Transform = "internal resolver"
317-
return slices.Clone(rc.md.ExtNameServers), nil
315+
return append([]ExtDNSEntry(nil), rc.md.ExtNameServers...), nil
318316
}
319317

320318
// Generate returns content suitable for writing to a resolv.conf file. If comments

libnetwork/internal/resolvconf/resolvconf_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,15 +221,15 @@ func TestRCModify(t *testing.T) {
221221
rc.OverrideSearch(tc.overrideSearch)
222222
rc.OverrideOptions(tc.overrideOptions)
223223

224-
assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateComparable(netip.Addr{})))
225-
assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch))
226-
assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions))
224+
assert.Check(t, is.DeepEqual(rc.NameServers(), overrideNS, cmpopts.EquateEmpty(), cmpopts.EquateComparable(netip.Addr{})))
225+
assert.Check(t, is.DeepEqual(rc.Search(), tc.overrideSearch, cmpopts.EquateEmpty()))
226+
assert.Check(t, is.DeepEqual(rc.Options(), tc.overrideOptions, cmpopts.EquateEmpty()))
227227
}
228228

229229
if tc.addOption != "" {
230230
options := rc.Options()
231231
rc.AddOption(tc.addOption)
232-
assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption)))
232+
assert.Check(t, is.DeepEqual(rc.Options(), append(options, tc.addOption), cmpopts.EquateEmpty()))
233233
}
234234

235235
d := t.TempDir()

0 commit comments

Comments
 (0)