| 6894 | } |
| 6895 | |
| 6896 | static const char *coverage_path_freshness(cbm_store_t *store, const char *project, |
| 6897 | const char *root_path, const char *rel_path, |
| 6898 | bool *outside) { |
| 6899 | *outside = false; |
| 6900 | if (!root_path || !root_path[0]) { |
| 6901 | return "unavailable"; |
| 6902 | } |
| 6903 | char abs_path[CBM_SZ_4K]; |
| 6904 | int n = snprintf(abs_path, sizeof(abs_path), "%s%s%s", root_path, |
| 6905 | root_path[strlen(root_path) - 1U] == '/' ? "" : "/", rel_path); |
| 6906 | if (n < 0 || (size_t)n >= sizeof(abs_path)) { |
| 6907 | return "unavailable"; |
| 6908 | } |
| 6909 | /* #1714: mtime_ns must come from the SAME source the indexer recorded it |
| 6910 | * with — cbm_path_info_utf8. Recomputing from struct stat truncates to |
| 6911 | * seconds on Windows (st_mtime), while the file_hashes record carries |
| 6912 | * FILETIME-resolution nanoseconds, so a byte-identical file never matched |
| 6913 | * and every path was reported metadata_changed. */ |
| 6914 | cbm_path_info_t info; |
| 6915 | if (cbm_path_info_utf8(abs_path, &info) != 0) { |
| 6916 | return "missing"; |
| 6917 | } |
| 6918 | if (!cbm_path_within_root(root_path, abs_path)) { |
| 6919 | *outside = true; |
| 6920 | return "outside_project"; |
| 6921 | } |
| 6922 | |
| 6923 | cbm_file_hash_t hash = {0}; |
| 6924 | int rc = cbm_store_get_file_hash(store, project, rel_path, &hash); |
| 6925 | if (rc == CBM_STORE_NOT_FOUND) { |
| 6926 | return "not_tracked"; |
| 6927 | } |
| 6928 | if (rc != CBM_STORE_OK) { |
| 6929 | return "unavailable"; |
| 6930 | } |
| 6931 | bool matches = hash.mtime_ns == info.mtime_ns && hash.size == info.size; |
| 6932 | cbm_store_clear_file_hash(&hash); |
| 6933 | return matches ? "metadata_match" : "metadata_changed"; |
| 6934 | } |
| 6935 | |
| 6936 | /* Read an "start-end,start-end,...[,+<N>]" string into a JSON ranges array. |
| 6937 | * |
no test coverage detected