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

Function cli_update_activate_binary

src/cli/cli.c:11093–11139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11091} cli_update_activation_t;
11092
11093static int cli_update_activate_binary(void *opaque) {
11094 cli_update_activation_t *activation = opaque;
11095 if (!activation || !activation->bin_dest || !activation->binary_transaction) {
11096 return CLI_TRUE;
11097 }
11098 char previous_managed_binary[CLI_BUF_1K] = {0};
11099 bool previous_managed_binary_exact = cbm_detect_self_path(
11100 previous_managed_binary, sizeof(previous_managed_binary), activation->home);
11101 if (cli_activation_transaction_commit_validated(activation->binary_transaction,
11102 &activation->binary_validator,
11103 CLI_OCTAL_PERM) != CLI_OK) {
11104 cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction,
11105 "update_transaction_publish_recovery");
11106 (void)fprintf(stderr, "error: cannot publish staged update to %s\n", activation->bin_dest);
11107 return CLI_TRUE;
11108 }
11109 /* Agent configs must never observe a replacement binary outside the same
11110 * exact-build activation window. Otherwise another CBM process can start
11111 * after the binary swap but before its MCP/hook entries are refreshed. */
11112 printf("Refreshing agent configurations...\n");
11113 if (cbm_install_agent_configs_with_previous(
11114 activation->home, activation->bin_dest,
11115 previous_managed_binary_exact ? previous_managed_binary : NULL, true,
11116 false) != CLI_OK) {
11117 cli_activation_transaction_finalize_committed_or_fail_stop(
11118 &activation->binary_transaction, "update_transaction_config_failure_finalize");
11119 (void)fprintf(stderr, "error: one or more agent configurations failed; the "
11120 "published update was kept. Review the errors above and "
11121 "rerun update\n");
11122 return CLI_ACTIVATION_PARTIAL;
11123 }
11124 if (activation->delete_indexes) {
11125 int expected = count_db_indexes(activation->home);
11126 int removed = cbm_remove_indexes(activation->home);
11127 printf("Removed %d index(es).\n\n", removed);
11128 if (removed != expected) {
11129 cli_activation_transaction_finalize_committed_or_fail_stop(
11130 &activation->binary_transaction, "update_transaction_index_failure_finalize");
11131 (void)fprintf(stderr, "error: only %d of %d indexes could be removed\n", removed,
11132 expected);
11133 return CLI_ACTIVATION_PARTIAL;
11134 }
11135 }
11136 cli_activation_transaction_finalize_committed_or_fail_stop(&activation->binary_transaction,
11137 "update_transaction_finalize");
11138 return CLI_OK;
11139}
11140
11141static int extract_and_install_binary(extract_install_args_t args) {
11142 const char *tmp_archive = args.tmp_archive;

Callers

nothing calls this directly

Tested by

no test coverage detected