sys, dialer: leave non-Windows code unchanged

Only the Windows listener and dialer take the unix:// scheme.

Assisted-by: OpenCode (claude-sonnet-5-5)
Signed-off-by: Eric Curtin <eric.curtin@docker.com>
This commit is contained in:
Eric Curtin committed 2026-10-23 16:36:17 +01:00
1 parent 15849062c9
commit a2622c0a7a
4 files changed
+9 -50

No files matched your search

+1 -5
View File
@@ -27,12 +27,8 @@ import (
)
// DialAddress returns the address with unix:// prepended to the
// provided address. An address that already carries the scheme is
// returned unchanged.
// provided address
func DialAddress(address string) string {
if strings.HasPrefix(address, "unix://") {
return address
}
return "unix://" + address
}
-39
View File
@@ -1,39 +0,0 @@
//go:build !windows
/*
Copyright The containerd Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package dialer
import "testing"
func TestDialAddressScheme(t *testing.T) {
testcases := []struct {
name string
address string
want string
}{
{name: "bare path gets unix", address: "/run/containerd/containerd.sock", want: "unix:///run/containerd/containerd.sock"},
{name: "unix scheme idempotent", address: "unix:///run/containerd/containerd.sock", want: "unix:///run/containerd/containerd.sock"},
}
for _, tc := range testcases {
t.Run(tc.name, func(t *testing.T) {
if got := DialAddress(tc.address); got != tc.want {
t.Errorf("DialAddress(%q) = %q, want %q", tc.address, got, tc.want)
}
})
}
}
+7 -1
View File
@@ -20,6 +20,7 @@ import (
"net"
"os"
"path/filepath"
"runtime"
"testing"
"time"
@@ -73,7 +74,12 @@ func checkAccept(t *testing.T, l net.Listener, dial func() (net.Conn, error)) {
}
func TestGetLocalListenerUnixSocket(t *testing.T) {
for _, prefix := range []string{"", "unix://"} {
prefixes := []string{""}
if runtime.GOOS == "windows" {
// Only the Windows listener takes the scheme.
prefixes = append(prefixes, "unix://")
}
for _, prefix := range prefixes {
t.Run("prefix="+prefix, func(t *testing.T) {
sockPath := filepath.Join(shortTempDir(t), "test.sock")
+1 -5
View File
@@ -23,7 +23,6 @@ import (
"net"
"os"
"path/filepath"
"strings"
"golang.org/x/sys/unix"
)
@@ -43,11 +42,8 @@ func CreateUnixSocket(path string) (net.Listener, error) {
return net.Listen("unix", path)
}
// GetLocalListener returns a listener out of a unix socket. The path may
// carry a "unix://" prefix, as in dialer.DialAddress.
// GetLocalListener returns a listener out of a unix socket.
func GetLocalListener(path string, uid, gid int) (net.Listener, error) {
path = strings.TrimPrefix(path, "unix://")
// Ensure parent directory is created
if err := mkdirAs(filepath.Dir(path), uid, gid); err != nil {
return nil, err