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

Function extract_and_install_binary

src/cli/cli.c:11556–11701  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11554}
11555
11556static int extract_and_install_binary(extract_install_args_t args) {
11557 const char *tmp_archive = args.tmp_archive;
11558 const char *ext = args.ext;
11559 const char *bin_dest = args.bin_dest;
11560 FILE *f = fopen(tmp_archive, "rb");
11561 if (!f) {
11562 (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive);
11563 return CLI_TRUE;
11564 }
11565 if (fseek(f, 0, SEEK_END) != 0) {
11566 (void)fclose(f);
11567 cbm_unlink(tmp_archive);
11568 return CLI_TRUE;
11569 }
11570 long fsize = ftell(f);
11571 if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) {
11572 (void)fclose(f);
11573 cbm_unlink(tmp_archive);
11574 return CLI_TRUE;
11575 }
11576
11577 unsigned char *data = malloc((size_t)fsize);
11578 if (!data) {
11579 (void)fclose(f);
11580 cbm_unlink(tmp_archive);
11581 return CLI_TRUE;
11582 }
11583 size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f);
11584 int close_status = fclose(f);
11585 if (bytes_read != (size_t)fsize || close_status != 0) {
11586 free(data);
11587 cbm_unlink(tmp_archive);
11588 return CLI_TRUE;
11589 }
11590
11591 int bin_len = 0;
11592 unsigned char *bin_data = NULL;
11593 if (strcmp(ext, "tar.gz") == 0) {
11594 bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len);
11595 } else {
11596 bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len);
11597 }
11598 free(data);
11599 cbm_unlink(tmp_archive);
11600
11601 if (!bin_data || bin_len <= 0) {
11602 (void)fprintf(stderr, "error: binary not found in archive\n");
11603 free(bin_data);
11604 return CLI_TRUE;
11605 }
11606
11607 cbm_activation_transaction_t *binary_transaction = NULL;
11608 cbm_activation_transaction_status_t stage_status;
11609 cli_binary_validator_t validator = {{0}};
11610#ifdef __APPLE__
11611 /* codesign replaces the signed file on current macOS releases. Publish and
11612 * sign a disposable private copy first, then stage the resulting immutable
11613 * bytes into the final transaction. */

Callers 1

download_verify_installFunction · 0.85

Tested by

no test coverage detected