Read schema_version from artifact.json. Returns -1 if missing/invalid. */
| 271 | |
| 272 | /* Read schema_version from artifact.json. Returns -1 if missing/invalid. */ |
| 273 | static int read_metadata_version(const char *repo_path) { |
| 274 | char meta_path[CBM_SZ_4K]; |
| 275 | artifact_path(meta_path, sizeof(meta_path), repo_path, CBM_ARTIFACT_META); |
| 276 | |
| 277 | size_t len = 0; |
| 278 | char *json = read_file_alloc(meta_path, &len); |
| 279 | if (!json) { |
| 280 | return CBM_NOT_FOUND; |
| 281 | } |
| 282 | |
| 283 | yyjson_doc *doc = yyjson_read(json, len, 0); |
| 284 | free(json); |
| 285 | if (!doc) { |
| 286 | return CBM_NOT_FOUND; |
| 287 | } |
| 288 | |
| 289 | yyjson_val *root = yyjson_doc_get_root(doc); |
| 290 | yyjson_val *ver = yyjson_obj_get(root, "schema_version"); |
| 291 | int version = ver ? yyjson_get_int(ver) : CBM_NOT_FOUND; |
| 292 | yyjson_doc_free(doc); |
| 293 | return version; |
| 294 | } |
| 295 | |
| 296 | /* Read original_size from artifact.json. Returns 0 on error. */ |
| 297 | static size_t read_metadata_original_size(const char *repo_path) { |
no test coverage detected