MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / extract_and_install_binary

Function extract_and_install_binary

src/cli/cli.c:13265–13464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13263#endif
13264
13265static int extract_and_install_binary(extract_install_args_t args) {
13266 const char *tmp_archive = args.tmp_archive;
13267 const char *ext = args.ext;
13268 const char *bin_dest = args.bin_dest;
13269 FILE *f = fopen(tmp_archive, "rb");
13270 if (!f) {
13271 (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive);
13272 return CLI_TRUE;
13273 }
13274 if (fseek(f, 0, SEEK_END) != 0) {
13275 (void)fclose(f);
13276 cbm_unlink(tmp_archive);
13277 return CLI_TRUE;
13278 }
13279 long fsize = ftell(f);
13280 if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) {
13281 (void)fclose(f);
13282 cbm_unlink(tmp_archive);
13283 return CLI_TRUE;
13284 }
13285
13286 unsigned char *data = malloc((size_t)fsize);
13287 if (!data) {
13288 (void)fclose(f);
13289 cbm_unlink(tmp_archive);
13290 return CLI_TRUE;
13291 }
13292 size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f);
13293 int close_status = fclose(f);
13294 if (bytes_read != (size_t)fsize || close_status != 0) {
13295 free(data);
13296 cbm_unlink(tmp_archive);
13297 return CLI_TRUE;
13298 }
13299
13300 int bin_len = 0;
13301 unsigned char *bin_data = NULL;
13302 if (strcmp(ext, "tar.gz") == 0) {
13303 bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len);
13304 } else {
13305 bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len);
13306 }
13307 free(data);
13308 cbm_unlink(tmp_archive);
13309
13310 if (!bin_data || bin_len <= 0) {
13311 (void)fprintf(stderr, "error: binary not found in archive\n");
13312 free(bin_data);
13313 return CLI_TRUE;
13314 }
13315
13316 cbm_activation_transaction_t *binary_transaction = NULL;
13317 cbm_activation_transaction_status_t stage_status;
13318 cli_binary_validator_t validator = {{0}};
13319#ifdef __APPLE__
13320 /* codesign replaces the signed file on current macOS releases. Publish and
13321 * sign a disposable private copy first, then stage the resulting immutable
13322 * bytes into the final transaction. Every step records why it failed, so a

Callers 1

download_verify_installFunction · 0.85

Calls 15

fopenFunction · 0.85
cbm_unlinkFunction · 0.85
freadFunction · 0.85
cbm_tmpdirFunction · 0.85
cli_update_prep_stepFunction · 0.85
cbm_mkdtempFunction · 0.85

Tested by

no test coverage detected