| 8233 | } |
| 8234 | |
| 8235 | static bool arch_path_prepare(const char *path, char *norm_out, size_t norm_sz, char *like_out, |
| 8236 | size_t like_sz) { |
| 8237 | if (!arch_path_is_set(path)) { |
| 8238 | return false; |
| 8239 | } |
| 8240 | while (*path == ' ' || *path == '\t' || *path == '\n' || *path == '\r') { |
| 8241 | path++; |
| 8242 | } |
| 8243 | if (path[0] == '\0') { |
| 8244 | return false; |
| 8245 | } |
| 8246 | if (strncmp(path, "./", 2) == 0) { |
| 8247 | path += 2; |
| 8248 | } |
| 8249 | while (*path == '/') { |
| 8250 | path++; |
| 8251 | } |
| 8252 | if (path[0] == '\0') { |
| 8253 | return false; |
| 8254 | } |
| 8255 | strncpy(norm_out, path, norm_sz - 1); |
| 8256 | norm_out[norm_sz - 1] = '\0'; |
| 8257 | size_t len = strlen(norm_out); |
| 8258 | while (len > 0 && |
| 8259 | (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t' || norm_out[len - 1] == '/')) { |
| 8260 | norm_out[--len] = '\0'; |
| 8261 | } |
| 8262 | /* Collapse duplicate slashes */ |
| 8263 | size_t w = 0; |
| 8264 | for (size_t r = 0; norm_out[r] != '\0'; r++) { |
| 8265 | if (norm_out[r] == '/' && w > 0 && norm_out[w - 1] == '/') { |
| 8266 | continue; |
| 8267 | } |
| 8268 | norm_out[w++] = norm_out[r]; |
| 8269 | } |
| 8270 | norm_out[w] = '\0'; |
| 8271 | if (norm_out[0] == '\0') { |
| 8272 | return false; |
| 8273 | } |
| 8274 | snprintf(like_out, like_sz, "%s/%%", norm_out); |
| 8275 | return true; |
| 8276 | } |
| 8277 | |
| 8278 | static const char *arch_path_scope_sql(void) { |
| 8279 | return " AND (file_path = ? OR file_path LIKE ?)"; |
no test coverage detected