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)
| 1098 | // |
| 1099 | // It also validates the device mode. |
| 1100 | func validateLinuxPath(val string, validator func(string) bool) (string, error) { |
| 1101 | var containerPath string |
| 1102 | var mode string |
| 1103 | |
| 1104 | if strings.Count(val, ":") > 2 { |
| 1105 | return val, fmt.Errorf("bad format for path: %s", val) |
| 1106 | } |
| 1107 | |
| 1108 | split := strings.SplitN(val, ":", 3) |
| 1109 | if split[0] == "" { |
| 1110 | return val, fmt.Errorf("bad format for path: %s", val) |
| 1111 | } |
| 1112 | switch len(split) { |
| 1113 | case 1: |
| 1114 | containerPath = split[0] |
| 1115 | val = path.Clean(containerPath) |
| 1116 | case 2: |
| 1117 | if isValid := validator(split[1]); isValid { |
| 1118 | containerPath = split[0] |
| 1119 | mode = split[1] |
| 1120 | val = fmt.Sprintf("%s:%s", path.Clean(containerPath), mode) |
| 1121 | } else { |
| 1122 | containerPath = split[1] |
| 1123 | val = fmt.Sprintf("%s:%s", split[0], path.Clean(containerPath)) |
| 1124 | } |
| 1125 | case 3: |
| 1126 | containerPath = split[1] |
| 1127 | mode = split[2] |
| 1128 | if isValid := validator(split[2]); !isValid { |
| 1129 | return val, fmt.Errorf("bad mode specified: %s", mode) |
| 1130 | } |
| 1131 | val = fmt.Sprintf("%s:%s:%s", split[0], containerPath, mode) |
| 1132 | } |
| 1133 | |
| 1134 | if !path.IsAbs(containerPath) { |
| 1135 | return val, fmt.Errorf("%s is not an absolute path", containerPath) |
| 1136 | } |
| 1137 | return val, nil |
| 1138 | } |
| 1139 | |
| 1140 | // validateAttach validates that the specified string is a valid attach option. |
| 1141 | func validateAttach(val string) (string, error) { |
no outgoing calls
no test coverage detected
searching dependent graphs…