| 4113 | } |
| 4114 | |
| 4115 | static const char *coverage_path_freshness(cbm_store_t *store, const char *project, |
| 4116 | const char *root_path, const char *rel_path, |
| 4117 | bool *outside) { |
| 4118 | *outside = false; |
| 4119 | if (!root_path || !root_path[0]) { |
| 4120 | return "unavailable"; |
| 4121 | } |
| 4122 | char abs_path[CBM_SZ_4K]; |
| 4123 | int n = snprintf(abs_path, sizeof(abs_path), "%s%s%s", root_path, |
| 4124 | root_path[strlen(root_path) - 1U] == '/' ? "" : "/", rel_path); |
| 4125 | if (n < 0 || (size_t)n >= sizeof(abs_path)) { |
| 4126 | return "unavailable"; |
| 4127 | } |
| 4128 | struct stat st; |
| 4129 | if (stat(abs_path, &st) != 0) { |
| 4130 | return "missing"; |
| 4131 | } |
| 4132 | if (!cbm_path_within_root(root_path, abs_path)) { |
| 4133 | *outside = true; |
| 4134 | return "outside_project"; |
| 4135 | } |
| 4136 | |
| 4137 | cbm_file_hash_t hash = {0}; |
| 4138 | int rc = cbm_store_get_file_hash(store, project, rel_path, &hash); |
| 4139 | if (rc == CBM_STORE_NOT_FOUND) { |
| 4140 | return "not_tracked"; |
| 4141 | } |
| 4142 | if (rc != CBM_STORE_OK) { |
| 4143 | return "unavailable"; |
| 4144 | } |
| 4145 | bool matches = hash.mtime_ns == coverage_stat_mtime_ns(&st) && hash.size == st.st_size; |
| 4146 | cbm_store_clear_file_hash(&hash); |
| 4147 | return matches ? "metadata_match" : "metadata_changed"; |
| 4148 | } |
| 4149 | |
| 4150 | static void coverage_add_ranges(yyjson_mut_doc *doc, yyjson_mut_val *row, const char *detail) { |
| 4151 | if (!detail || !detail[0]) { |
no test coverage detected