| 74 | } |
| 75 | |
| 76 | int cbm_workspace_path_depth(const char *canonical_path) { |
| 77 | size_t prefix = ws_volume_prefix_len(canonical_path); |
| 78 | if (prefix == 0) { |
| 79 | return 0; |
| 80 | } |
| 81 | int depth = 0; |
| 82 | const char *p = canonical_path + prefix; |
| 83 | /* macOS firmlinks /etc, /tmp and /var under /private, so canonicalizing any |
| 84 | * of them adds a component: "/etc" resolves to "/private/etc" and would count |
| 85 | * as two deep, sailing past a minimum of two — exactly the path the reports |
| 86 | * demonstrate. Treat a leading "private" as transparent so depth reflects the |
| 87 | * tree the user named. "/private/tmp/proj" still counts two and is allowed. */ |
| 88 | if (strncmp(p, "private", 7) == 0 && (ws_is_sep(p[7]) || p[7] == '\0')) { |
| 89 | p += 7; |
| 90 | } |
| 91 | while (*p) { |
| 92 | while (ws_is_sep(*p)) { |
| 93 | p++; |
| 94 | } |
| 95 | if (!*p) { |
| 96 | break; |
| 97 | } |
| 98 | depth++; |
| 99 | while (*p && !ws_is_sep(*p)) { |
| 100 | p++; |
| 101 | } |
| 102 | } |
| 103 | return depth; |
| 104 | } |
| 105 | |
| 106 | /* Case-insensitive on Windows-style paths, exact elsewhere: NTFS is |
| 107 | * case-insensitive, so ".SSH" must not slip past a case-sensitive compare. */ |
no test coverage detected