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

Function extract_and_install_binary

src/cli/cli.c:11814–11959  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11812}
11813
11814static int extract_and_install_binary(extract_install_args_t args) {
11815 const char *tmp_archive = args.tmp_archive;
11816 const char *ext = args.ext;
11817 const char *bin_dest = args.bin_dest;
11818 FILE *f = fopen(tmp_archive, "rb");
11819 if (!f) {
11820 (void)fprintf(stderr, "error: cannot open %s\n", tmp_archive);
11821 return CLI_TRUE;
11822 }
11823 if (fseek(f, 0, SEEK_END) != 0) {
11824 (void)fclose(f);
11825 cbm_unlink(tmp_archive);
11826 return CLI_TRUE;
11827 }
11828 long fsize = ftell(f);
11829 if (fsize <= 0 || fsize > INT_MAX || fseek(f, 0, SEEK_SET) != 0) {
11830 (void)fclose(f);
11831 cbm_unlink(tmp_archive);
11832 return CLI_TRUE;
11833 }
11834
11835 unsigned char *data = malloc((size_t)fsize);
11836 if (!data) {
11837 (void)fclose(f);
11838 cbm_unlink(tmp_archive);
11839 return CLI_TRUE;
11840 }
11841 size_t bytes_read = fread(data, CLI_ELEM_SIZE, (size_t)fsize, f);
11842 int close_status = fclose(f);
11843 if (bytes_read != (size_t)fsize || close_status != 0) {
11844 free(data);
11845 cbm_unlink(tmp_archive);
11846 return CLI_TRUE;
11847 }
11848
11849 int bin_len = 0;
11850 unsigned char *bin_data = NULL;
11851 if (strcmp(ext, "tar.gz") == 0) {
11852 bin_data = cbm_extract_binary_from_targz(data, (int)fsize, &bin_len);
11853 } else {
11854 bin_data = cbm_extract_binary_from_zip(data, (int)fsize, &bin_len);
11855 }
11856 free(data);
11857 cbm_unlink(tmp_archive);
11858
11859 if (!bin_data || bin_len <= 0) {
11860 (void)fprintf(stderr, "error: binary not found in archive\n");
11861 free(bin_data);
11862 return CLI_TRUE;
11863 }
11864
11865 cbm_activation_transaction_t *binary_transaction = NULL;
11866 cbm_activation_transaction_status_t stage_status;
11867 cli_binary_validator_t validator = {{0}};
11868#ifdef __APPLE__
11869 /* codesign replaces the signed file on current macOS releases. Publish and
11870 * sign a disposable private copy first, then stage the resulting immutable
11871 * bytes into the final transaction. */

Callers 1

download_verify_installFunction · 0.85

Tested by

no test coverage detected