@@ -8717,6 +8717,54 @@ static cbm_graph_access_t cbm_tiered_profile_set_access(cbm_tiered_profile_set_t
87178717 : CBM_GRAPH_ACCESS_HANDOFF;
87188718}
87198719
8720+ /* Every earlier rendering of one tier's profile that install/uninstall must
8721+ * still recognise as ours: the other access mode, the v0.9.1-rc.1 Codex
8722+ * shape, the pre-tier Verify file, and the v0.10.8 OpenCode shape (#2264). */
8723+ typedef struct {
8724+ char *owned[4];
8725+ size_t owned_count;
8726+ const char *content[5];
8727+ size_t count;
8728+ } tiered_released_profiles_t;
8729+
8730+ static void tiered_released_profiles_keep(tiered_released_profiles_t *released, char *rendered) {
8731+ if (rendered) {
8732+ released->owned[released->owned_count++] = rendered;
8733+ released->content[released->count++] = rendered;
8734+ }
8735+ }
8736+
8737+ static void tiered_released_profiles_collect(cbm_tiered_profile_set_t profiles,
8738+ cbm_graph_tier_t tier, cbm_graph_access_t access,
8739+ tiered_released_profiles_t *released) {
8740+ memset(released, 0, sizeof(*released));
8741+ cbm_graph_access_t alternate_access =
8742+ access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8743+ tiered_released_profiles_keep(
8744+ released,
8745+ cbm_render_graph_profile(profiles.dialect, tier, alternate_access, profiles.binary_path));
8746+ if (profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT) {
8747+ tiered_released_profiles_keep(released, cbm_render_graph_profile_codex_rc1(tier));
8748+ }
8749+ if (profiles.dialect == CBM_GRAPH_DIALECT_OPENCODE) {
8750+ tiered_released_profiles_keep(released,
8751+ cbm_render_graph_profile_opencode_v0108(tier, access));
8752+ tiered_released_profiles_keep(
8753+ released, cbm_render_graph_profile_opencode_v0108(tier, alternate_access));
8754+ }
8755+ if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8756+ released->content[released->count++] = profiles.legacy_verify_content;
8757+ }
8758+ }
8759+
8760+ static void tiered_released_profiles_free(tiered_released_profiles_t *released) {
8761+ for (size_t i = 0U; i < released->owned_count; i++) {
8762+ free(released->owned[i]);
8763+ }
8764+ released->owned_count = 0U;
8765+ released->count = 0U;
8766+ }
8767+
87208768static void install_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, bool dry_run) {
87218769 cbm_graph_access_t access = cbm_tiered_profile_set_access(profiles);
87228770 for (int value = 0; value < (int)CBM_GRAPH_TIER_COUNT; value++) {
@@ -8740,30 +8788,13 @@ static void install_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, boo
87408788 record_agent_config_error(false, profiles.label, "agent_render", path);
87418789 continue;
87428790 }
8743- cbm_graph_access_t alternate_access =
8744- access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8745- char *alternate = cbm_render_graph_profile(profiles.dialect, tier, alternate_access,
8746- profiles.binary_path);
8747- char *codex_rc1 =
8748- profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT
8749- ? cbm_render_graph_profile_codex_rc1(tier)
8750- : NULL;
8751- const char *released[3];
8752- size_t released_count = 0U;
8753- if (alternate) {
8754- released[released_count++] = alternate;
8755- }
8756- if (codex_rc1) {
8757- released[released_count++] = codex_rc1;
8758- }
8759- if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8760- released[released_count++] = profiles.legacy_verify_content;
8761- }
8762- int result = prepare_config_parent(path)
8763- ? cbm_text_migrate_owned_document(path, current, released, released_count)
8764- : CLI_ERR;
8765- free(codex_rc1);
8766- free(alternate);
8791+ tiered_released_profiles_t released;
8792+ tiered_released_profiles_collect(profiles, tier, access, &released);
8793+ int result =
8794+ prepare_config_parent(path)
8795+ ? cbm_text_migrate_owned_document(path, current, released.content, released.count)
8796+ : CLI_ERR;
8797+ tiered_released_profiles_free(&released);
87678798 free(current);
87688799 if (result != CLI_OK) {
87698800 if (result > CLI_OK) {
@@ -8795,28 +8826,11 @@ static void uninstall_tiered_agent_profiles(cbm_tiered_profile_set_t profiles, b
87958826 record_agent_config_error(true, profiles.label, "agent_render", path);
87968827 continue;
87978828 }
8798- cbm_graph_access_t alternate_access =
8799- access == CBM_GRAPH_ACCESS_DIRECT ? CBM_GRAPH_ACCESS_HANDOFF : CBM_GRAPH_ACCESS_DIRECT;
8800- char *alternate = cbm_render_graph_profile(profiles.dialect, tier, alternate_access,
8801- profiles.binary_path);
8802- char *codex_rc1 =
8803- profiles.dialect == CBM_GRAPH_DIALECT_CODEX && access == CBM_GRAPH_ACCESS_DIRECT
8804- ? cbm_render_graph_profile_codex_rc1(tier)
8805- : NULL;
8806- const char *released[3];
8807- size_t released_count = 0U;
8808- if (alternate) {
8809- released[released_count++] = alternate;
8810- }
8811- if (codex_rc1) {
8812- released[released_count++] = codex_rc1;
8813- }
8814- if (tier == CBM_GRAPH_TIER_VERIFY && profiles.legacy_verify_content) {
8815- released[released_count++] = profiles.legacy_verify_content;
8816- }
8817- int result = cbm_text_remove_owned_document_any(path, current, released, released_count);
8818- free(codex_rc1);
8819- free(alternate);
8829+ tiered_released_profiles_t released;
8830+ tiered_released_profiles_collect(profiles, tier, access, &released);
8831+ int result =
8832+ cbm_text_remove_owned_document_any(path, current, released.content, released.count);
8833+ tiered_released_profiles_free(&released);
88208834 free(current);
88218835 if (result < CLI_OK) {
88228836 record_agent_config_error(true, profiles.label, "agent_uninstall", path);
0 commit comments