MCPcopy
hub / github.com/nektos/act / parseLinuxDevice

Function parseLinuxDevice

pkg/container/docker_cli.go:1016–1047  ·  view source on GitHub ↗

parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct knowing that the target is a Linux daemon

(device string)

Source from the content-addressed store, hash-verified

1014// parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
1015// knowing that the target is a Linux daemon
1016func parseLinuxDevice(device string) (container.DeviceMapping, error) {
1017 var src, dst string
1018 permissions := "rwm"
1019 // We expect 3 parts at maximum; limit to 4 parts to detect invalid options.
1020 arr := strings.SplitN(device, ":", 4)
1021 switch len(arr) {
1022 case 3:
1023 permissions = arr[2]
1024 fallthrough
1025 case 2:
1026 if validDeviceMode(arr[1]) {
1027 permissions = arr[1]
1028 } else {
1029 dst = arr[1]
1030 }
1031 fallthrough
1032 case 1:
1033 src = arr[0]
1034 default:
1035 return container.DeviceMapping{}, fmt.Errorf("invalid device specification: %s", device)
1036 }
1037
1038 if dst == "" {
1039 dst = src
1040 }
1041
1042 return container.DeviceMapping{
1043 PathOnHost: src,
1044 PathInContainer: dst,
1045 CgroupPermissions: permissions,
1046 }, nil
1047}
1048
1049// validateDeviceCgroupRule validates a device cgroup rule string format
1050// It will make sure 'val' is in the form:

Callers 1

parseDeviceFunction · 0.85

Calls 1

validDeviceModeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…