| 4085 | } |
| 4086 | |
| 4087 | static const char *coverage_path_freshness(cbm_store_t *store, const char *project, |
| 4088 | const char *root_path, const char *rel_path, |
| 4089 | bool *outside) { |
| 4090 | *outside = false; |
| 4091 | if (!root_path || !root_path[0]) { |
| 4092 | return "unavailable"; |
| 4093 | } |
| 4094 | char abs_path[CBM_SZ_4K]; |
| 4095 | int n = snprintf(abs_path, sizeof(abs_path), "%s%s%s", root_path, |
| 4096 | root_path[strlen(root_path) - 1U] == '/' ? "" : "/", rel_path); |
| 4097 | if (n < 0 || (size_t)n >= sizeof(abs_path)) { |
| 4098 | return "unavailable"; |
| 4099 | } |
| 4100 | struct stat st; |
| 4101 | if (stat(abs_path, &st) != 0) { |
| 4102 | return "missing"; |
| 4103 | } |
| 4104 | if (!cbm_path_within_root(root_path, abs_path)) { |
| 4105 | *outside = true; |
| 4106 | return "outside_project"; |
| 4107 | } |
| 4108 | |
| 4109 | cbm_file_hash_t hash = {0}; |
| 4110 | int rc = cbm_store_get_file_hash(store, project, rel_path, &hash); |
| 4111 | if (rc == CBM_STORE_NOT_FOUND) { |
| 4112 | return "not_tracked"; |
| 4113 | } |
| 4114 | if (rc != CBM_STORE_OK) { |
| 4115 | return "unavailable"; |
| 4116 | } |
| 4117 | bool matches = hash.mtime_ns == coverage_stat_mtime_ns(&st) && hash.size == st.st_size; |
| 4118 | cbm_store_clear_file_hash(&hash); |
| 4119 | return matches ? "metadata_match" : "metadata_changed"; |
| 4120 | } |
| 4121 | |
| 4122 | static void coverage_add_ranges(yyjson_mut_doc *doc, yyjson_mut_val *row, const char *detail) { |
| 4123 | if (!detail || !detail[0]) { |
no test coverage detected