| 4879 | } |
| 4880 | |
| 4881 | static bool arch_path_prepare(const char *path, char *norm_out, size_t norm_sz, char *like_out, |
| 4882 | size_t like_sz) { |
| 4883 | if (!arch_path_is_set(path)) { |
| 4884 | return false; |
| 4885 | } |
| 4886 | while (*path == ' ' || *path == '\t' || *path == '\n' || *path == '\r') { |
| 4887 | path++; |
| 4888 | } |
| 4889 | if (path[0] == '\0') { |
| 4890 | return false; |
| 4891 | } |
| 4892 | if (strncmp(path, "./", 2) == 0) { |
| 4893 | path += 2; |
| 4894 | } |
| 4895 | while (*path == '/') { |
| 4896 | path++; |
| 4897 | } |
| 4898 | if (path[0] == '\0') { |
| 4899 | return false; |
| 4900 | } |
| 4901 | strncpy(norm_out, path, norm_sz - 1); |
| 4902 | norm_out[norm_sz - 1] = '\0'; |
| 4903 | size_t len = strlen(norm_out); |
| 4904 | while (len > 0 && |
| 4905 | (norm_out[len - 1] == ' ' || norm_out[len - 1] == '\t' || norm_out[len - 1] == '/')) { |
| 4906 | norm_out[--len] = '\0'; |
| 4907 | } |
| 4908 | /* Collapse duplicate slashes */ |
| 4909 | size_t w = 0; |
| 4910 | for (size_t r = 0; norm_out[r] != '\0'; r++) { |
| 4911 | if (norm_out[r] == '/' && w > 0 && norm_out[w - 1] == '/') { |
| 4912 | continue; |
| 4913 | } |
| 4914 | norm_out[w++] = norm_out[r]; |
| 4915 | } |
| 4916 | norm_out[w] = '\0'; |
| 4917 | if (norm_out[0] == '\0') { |
| 4918 | return false; |
| 4919 | } |
| 4920 | snprintf(like_out, like_sz, "%s/%%", norm_out); |
| 4921 | return true; |
| 4922 | } |
| 4923 | |
| 4924 | static const char *arch_path_scope_sql(void) { |
| 4925 | return " AND (file_path = ? OR file_path LIKE ?)"; |
no test coverage detected