mirror of
https://github.com/containerd/containerd.git
synced 2026-11-06 05:17:02 +00:00
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:
4 files changed
+9
-50
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user