| 5090 | } |
| 5091 | |
| 5092 | static bool arch_path_prepare(const char *path, char *norm_out, size_t norm_sz, char *like_out, |
| 5093 | size_t like_sz) { |
| 5094 | if (!arch_path_is_set(path)) { |
| 5095 | return false; |
| 5096 | } |
| 5097 | while (*path == ' ' || *path == '\t' || *path == '\n' || *path == '\r') { |
| 5098 | path++; |
| 5099 | } |
| 5100 | if (path[0] == '\0') { |
| 5101 | return false; |
| 5102 | } |
| 5103 | if (strncmp(path, "./", 2) == 0) { |
| 5104 | path += 2; |
| 5105 | } |
| 5106 | while (*path == '/') { |
| 5107 | path++; |
| 5108 | } |
| 5109 | if (path[0] == '\0') { |
| 5110 | return false; |
| 5111 | } |
| 5112 | strncpy(norm_out, path, norm_sz - 1); |
| 5113 | norm_out[norm_sz - 1] = '\0'; |
| 5114 | size_t len = strlen(norm_out); |
| 5115 | while (len > 0 && |
| 5116 | (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t' || norm_out[len - 1] == '/')) { |
| 5117 | norm_out[--len] = '\0'; |
| 5118 | } |
| 5119 | /* Collapse duplicate slashes */ |
| 5120 | size_t w = 0; |
| 5121 | for (size_t r = 0; norm_out[r] != '\0'; r++) { |
| 5122 | if (norm_out[r] == '/' && w > 0 && norm_out[w - 1] == '/') { |
| 5123 | continue; |
| 5124 | } |
| 5125 | norm_out[w++] = norm_out[r]; |
| 5126 | } |
| 5127 | norm_out[w] = '\0'; |
| 5128 | if (norm_out[0] == '\0') { |
| 5129 | return false; |
| 5130 | } |
| 5131 | snprintf(like_out, like_sz, "%s/%%", norm_out); |
| 5132 | return true; |
| 5133 | } |
| 5134 | |
| 5135 | static const char *arch_path_scope_sql(void) { |
| 5136 | return " AND (file_path = ? OR file_path LIKE ?)"; |
no test coverage detected