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

Function cli_update_activate_binary

src/cli/cli.c:11155–11201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11153} cli_update_activation_t;
11154
11155static int cli_update_activate_binary(void *opaque) {
11156 cli_update_activation_t *activation = opaque;
11157 if (!activation || !activation->bin_dest || !activation->binary_transaction) {
11158 return CLI_TRUE;
11159 }
11160 char previous_managed_binary[CLI_BUF_1K] = {0};
11161 bool previous_managed_binary_exact = cbm_detect_self_path(
11162 previous_managed_binary, sizeof(previous_managed_binary), activation->home);
11163 if (cli_activation_transaction_commit_validated(activation->binary_transaction,
11164 &activation->binary_validator,
11165 CLI_OCTAL_PERM) != CLI_OK) {
11166 cli_activation_transaction_abort_or_fail_stop(&activation->binary_transaction,
11167 "update_transaction_publish_recovery");
11168 (void)fprintf(stderr, "error: cannot publish staged update to %s\n", activation->bin_dest);
11169 return CLI_TRUE;
11170 }
11171 /* Agent configs must never observe a replacement binary outside the same
11172 * exact-build activation window. Otherwise another CBM process can start
11173 * after the binary swap but before its MCP/hook entries are refreshed. */
11174 printf("Refreshing agent configurations...\n");
11175 if (cbm_install_agent_configs_with_previous(
11176 activation->home, activation->bin_dest,
11177 previous_managed_binary_exact ? previous_managed_binary : NULL, true,
11178 false) != CLI_OK) {
11179 cli_activation_transaction_finalize_committed_or_fail_stop(
11180 &activation->binary_transaction, "update_transaction_config_failure_finalize");
11181 (void)fprintf(stderr, "error: one or more agent configurations failed; the "
11182 "published update was kept. Review the errors above and "
11183 "rerun update\n");
11184 return CLI_ACTIVATION_PARTIAL;
11185 }
11186 if (activation->delete_indexes) {
11187 int expected = count_db_indexes(activation->home);
11188 int removed = cbm_remove_indexes(activation->home);
11189 printf("Removed %d index(es).\n\n", removed);
11190 if (removed != expected) {
11191 cli_activation_transaction_finalize_committed_or_fail_stop(
11192 &activation->binary_transaction, "update_transaction_index_failure_finalize");
11193 (void)fprintf(stderr, "error: only %d of %d indexes could be removed\n", removed,
11194 expected);
11195 return CLI_ACTIVATION_PARTIAL;
11196 }
11197 }
11198 cli_activation_transaction_finalize_committed_or_fail_stop(&activation->binary_transaction,
11199 "update_transaction_finalize");
11200 return CLI_OK;
11201}
11202
11203static int extract_and_install_binary(extract_install_args_t args) {
11204 const char *tmp_archive = args.tmp_archive;

Callers

nothing calls this directly

Tested by

no test coverage detected