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

Function cli_update_activate_binary

src/cli/cli.c:11099–11145  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Tested by

no test coverage detected