diff --git a/pkg/dialer/dialer_unix.go b/pkg/dialer/dialer_unix.go index 3f8c50f7d8..1d98a0b444 100644 --- a/pkg/dialer/dialer_unix.go +++ b/pkg/dialer/dialer_unix.go @@ -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 } diff --git a/pkg/dialer/dialer_unix_test.go b/pkg/dialer/dialer_unix_test.go deleted file mode 100644 index bea86c4e1f..0000000000 --- a/pkg/dialer/dialer_unix_test.go +++ /dev/null @@ -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) - } - }) - } -} diff --git a/pkg/sys/socket_test.go b/pkg/sys/socket_test.go index 5b10012380..da069ee493 100644 --- a/pkg/sys/socket_test.go +++ b/pkg/sys/socket_test.go @@ -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") diff --git a/pkg/sys/socket_unix.go b/pkg/sys/socket_unix.go index b93554d664..91034e1718 100644 --- a/pkg/sys/socket_unix.go +++ b/pkg/sys/socket_unix.go @@ -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