| 4980 | } |
| 4981 | |
| 4982 | static bool arch_path_prepare(const char *path, char *norm_out, size_t norm_sz, char *like_out, |
| 4983 | size_t like_sz) { |
| 4984 | if (!arch_path_is_set(path)) { |
| 4985 | return false; |
| 4986 | } |
| 4987 | while (*path == ' ' || *path == '\t' || *path == '\n' || *path == '\r') { |
| 4988 | path++; |
| 4989 | } |
| 4990 | if (path[0] == '\0') { |
| 4991 | return false; |
| 4992 | } |
| 4993 | if (strncmp(path, "./", 2) == 0) { |
| 4994 | path += 2; |
| 4995 | } |
| 4996 | while (*path == '/') { |
| 4997 | path++; |
| 4998 | } |
| 4999 | if (path[0] == '\0') { |
| 5000 | return false; |
| 5001 | } |
| 5002 | strncpy(norm_out, path, norm_sz - 1); |
| 5003 | norm_out[norm_sz - 1] = '\0'; |
| 5004 | size_t len = strlen(norm_out); |
| 5005 | while (len > 0 && |
| 5006 | (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t' || norm_out[len - 1] == '/')) { |
| 5007 | norm_out[--len] = '\0'; |
| 5008 | } |
| 5009 | /* Collapse duplicate slashes */ |
| 5010 | size_t w = 0; |
| 5011 | for (size_t r = 0; norm_out[r] != '\0'; r++) { |
| 5012 | if (norm_out[r] == '/' && w > 0 && norm_out[w - 1] == '/') { |
| 5013 | continue; |
| 5014 | } |
| 5015 | norm_out[w++] = norm_out[r]; |
| 5016 | } |
| 5017 | norm_out[w] = '\0'; |
| 5018 | if (norm_out[0] == '\0') { |
| 5019 | return false; |
| 5020 | } |
| 5021 | snprintf(like_out, like_sz, "%s/%%", norm_out); |
| 5022 | return true; |
| 5023 | } |
| 5024 | |
| 5025 | static const char *arch_path_scope_sql(void) { |
| 5026 | return " AND (file_path = ? OR file_path LIKE ?)"; |
no test coverage detected