From d78ee47154eee7d5c6d72ca9f7fb232a1720a2d8 Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 8 Jul 2020 15:20:04 -0400 Subject: [PATCH] Allow libcontainer/configs to be imported on Windows Signed-off-by: Daniel J Walsh --- libcontainer/configs/device.go | 12 ------------ libcontainer/configs/device_unix.go | 16 ++++++++++++++++ libcontainer/configs/device_windows.go | 5 +++++ 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 libcontainer/configs/device_unix.go create mode 100644 libcontainer/configs/device_windows.go diff --git a/libcontainer/configs/device.go b/libcontainer/configs/device.go index 24c5bbfa..632bf6ac 100644 --- a/libcontainer/configs/device.go +++ b/libcontainer/configs/device.go @@ -1,20 +1,15 @@ package configs import ( - "errors" "fmt" "os" "strconv" - - "golang.org/x/sys/unix" ) const ( Wildcard = -1 ) -// TODO Windows: This can be factored out in the future - type Device struct { DeviceRule @@ -173,10 +168,3 @@ func (d *DeviceRule) CgroupString() string { } return fmt.Sprintf("%c %s:%s %s", d.Type, major, minor, d.Permissions) } - -func (d *DeviceRule) Mkdev() (uint64, error) { - if d.Major == Wildcard || d.Minor == Wildcard { - return 0, errors.New("cannot mkdev() device with wildcards") - } - return unix.Mkdev(uint32(d.Major), uint32(d.Minor)), nil -} diff --git a/libcontainer/configs/device_unix.go b/libcontainer/configs/device_unix.go new file mode 100644 index 00000000..650c4684 --- /dev/null +++ b/libcontainer/configs/device_unix.go @@ -0,0 +1,16 @@ +// +build !windows + +package configs + +import ( + "errors" + + "golang.org/x/sys/unix" +) + +func (d *DeviceRule) Mkdev() (uint64, error) { + if d.Major == Wildcard || d.Minor == Wildcard { + return 0, errors.New("cannot mkdev() device with wildcards") + } + return unix.Mkdev(uint32(d.Major), uint32(d.Minor)), nil +} diff --git a/libcontainer/configs/device_windows.go b/libcontainer/configs/device_windows.go new file mode 100644 index 00000000..72928939 --- /dev/null +++ b/libcontainer/configs/device_windows.go @@ -0,0 +1,5 @@ +package configs + +func (d *DeviceRule) Mkdev() (uint64, error) { + return 0, nil +}