validateMountStringFormat parses a mount string and validates its basic format. Expected format: "source:destination:mode" where mode is "ro" or "rw". Returns (source, dest, mode, nil) on success, or ("", "", "", error) on failure. The error message describes which aspect of the format is invalid. C
(mount string)
| 82 | // The error message describes which aspect of the format is invalid. |
| 83 | // Callers are responsible for wrapping the error with context-appropriate error types. |
| 84 | func validateMountStringFormat(mount string) (source, dest, mode string, err error) { |
| 85 | parts := strings.Split(mount, ":") |
| 86 | if len(parts) != 3 { |
| 87 | validationHelpersLog.Printf("Invalid mount format: %q (expected 3 colon-separated parts, got %d)", mount, len(parts)) |
| 88 | return "", "", "", errors.New("must follow 'source:destination:mode' format with exactly 3 colon-separated parts") |
| 89 | } |
| 90 | mode = parts[2] |
| 91 | if mode != "ro" && mode != "rw" { |
| 92 | validationHelpersLog.Printf("Invalid mount mode: %q in %q (must be 'ro' or 'rw')", mode, mount) |
| 93 | return parts[0], parts[1], parts[2], fmt.Errorf("mode must be 'ro' or 'rw', got %q", mode) |
| 94 | } |
| 95 | validationHelpersLog.Printf("Valid mount: source=%s, dest=%s, mode=%s", parts[0], parts[1], mode) |
| 96 | return parts[0], parts[1], parts[2], nil |
| 97 | } |
| 98 | |
| 99 | // mountValidationKind classifies the result of parsing and validating a mount entry. |
| 100 | // Callers use it to translate shared parsing results into context-specific errors |