MCPcopy Index your code
hub / github.com/docker/cli / validateLinuxPath

Function validateLinuxPath

cli/command/container/opts.go:1093–1131  ·  view source on GitHub ↗

validateLinuxPath is the implementation of validateDevice knowing that the target server operating system is a Linux daemon. It will make sure 'val' is in the form: [host-dir:]container-path[:mode] It also validates the device mode.

(val string, validator func(string) bool)

Source from the content-addressed store, hash-verified

1091//
1092// It also validates the device mode.
1093func validateLinuxPath(val string, validator func(string) bool) (string, error) {
1094 var containerPath string
1095 var mode string
1096
1097 if strings.Count(val, ":") > 2 {
1098 return val, fmt.Errorf("bad format for path: %s", val)
1099 }
1100
1101 split := strings.SplitN(val, ":", 3)
1102 if split[0] == "" {
1103 return val, fmt.Errorf("bad format for path: %s", val)
1104 }
1105 switch len(split) {
1106 case 1:
1107 containerPath = split[0]
1108 val = path.Clean(containerPath)
1109 case 2:
1110 if isValid := validator(split[1]); isValid {
1111 containerPath = split[0]
1112 mode = split[1]
1113 val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode)
1114 } else {
1115 containerPath = split[1]
1116 val = fmt.Sprintf("%s:%s", split[0], path.Clean(containerPath))
1117 }
1118 case 3:
1119 containerPath = split[1]
1120 mode = split[2]
1121 if isValid := validator(split[2]); !isValid {
1122 return val, fmt.Errorf("bad mode specified: %s", mode)
1123 }
1124 val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode)
1125 }
1126
1127 if !path.IsAbs(containerPath) {
1128 return val, fmt.Errorf("%s is not an absolute path", containerPath)
1129 }
1130 return val, nil
1131}
1132
1133// validateAttach validates that the specified string is a valid attach option.
1134func validateAttach(val string) (string, error) {

Callers 1

validateDeviceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…