@@ -216,6 +216,75 @@ bool write_default_xlings_json(const std::filesystem::path& path,
216216 return std::filesystem::exists (path);
217217}
218218
219+ bool replace_all (std::string& text, std::string_view from, std::string_view to) {
220+ bool changed = false ;
221+ for (std::size_t pos = 0 ;
222+ (pos = text.find (from, pos)) != std::string::npos;) {
223+ text.replace (pos, from.size (), to);
224+ pos += to.size ();
225+ changed = true ;
226+ }
227+ return changed;
228+ }
229+
230+ bool write_text_if_changed (const std::filesystem::path& path,
231+ const std::string& original,
232+ const std::string& updated) {
233+ if (updated == original) return false ;
234+ write_file (path, updated);
235+ return true ;
236+ }
237+
238+ bool migrate_legacy_config_toml_index_names (const std::filesystem::path& path) {
239+ std::ifstream is (path);
240+ if (!is) return false ;
241+ std::stringstream ss;
242+ ss << is.rdbuf ();
243+ auto original = ss.str ();
244+ auto updated = original;
245+
246+ replace_all (updated, " default = \" mcpp-index\" " , " default = \" mcpplibs\" " );
247+ replace_all (updated, " [index.repos.\" mcpp-index\" ]" , " [index.repos.\" mcpplibs\" ]" );
248+
249+ return write_text_if_changed (path, original, updated);
250+ }
251+
252+ bool migrate_legacy_xlings_json_index_names (const std::filesystem::path& path) {
253+ std::ifstream is (path);
254+ if (!is) return false ;
255+ std::stringstream ss;
256+ ss << is.rdbuf ();
257+ auto original = ss.str ();
258+ auto updated = original;
259+
260+ // Older mcpp sandboxes seeded the package index under the repository
261+ // name. Keep the URL and all xlings state intact; only rename the index
262+ // key so xlings config/list output matches mcpp's default namespace.
263+ replace_all (updated, " \" name\" : \" mcpp-index\" " , " \" name\" : \" mcpplibs\" " );
264+ replace_all (updated, " \" name\" :\" mcpp-index\" " , " \" name\" :\" mcpplibs\" " );
265+
266+ return write_text_if_changed (path, original, updated);
267+ }
268+
269+ void canonicalize_legacy_index_names (GlobalConfig& cfg) {
270+ if (cfg.defaultIndex == " mcpp-index" )
271+ cfg.defaultIndex = " mcpplibs" ;
272+
273+ std::vector<IndexRepo> normalized;
274+ for (auto r : cfg.indexRepos ) {
275+ if (r.name == " mcpp-index"
276+ && r.url == " https://github.com/mcpp-community/mcpp-index.git" ) {
277+ r.name = " mcpplibs" ;
278+ }
279+ bool duplicate = std::any_of (normalized.begin (), normalized.end (),
280+ [&](const IndexRepo& existing) {
281+ return existing.name == r.name && existing.url == r.url ;
282+ });
283+ if (!duplicate) normalized.push_back (std::move (r));
284+ }
285+ cfg.indexRepos = std::move (normalized);
286+ }
287+
219288// Try to acquire xlings binary. Returns the path if successful.
220289std::expected<std::filesystem::path, std::string>
221290acquire_xlings_binary (const std::filesystem::path& destBin, bool quiet)
@@ -345,6 +414,7 @@ std::expected<GlobalConfig, ConfigError> load_or_init(
345414 // 3. Seed config.toml if missing
346415 bool fresh_config = !std::filesystem::exists (cfg.configFile );
347416 if (fresh_config) write_default_config_toml (cfg.configFile );
417+ else migrate_legacy_config_toml_index_names (cfg.configFile );
348418
349419 // 4. Load config.toml
350420 auto doc = t::parse_file (cfg.configFile );
@@ -383,11 +453,16 @@ std::expected<GlobalConfig, ConfigError> load_or_init(
383453 cfg.indexRepos .push_back ({ std::string (name), std::string (url) });
384454 };
385455 add_default (" mcpplibs" , " https://github.com/mcpp-community/mcpp-index.git" );
456+ canonicalize_legacy_index_names (cfg);
386457
387- // 5. Seed registry/.xlings.json if missing
458+ // 5. Seed registry/.xlings.json if missing; migrate legacy cached
459+ // sandboxes in place so CI/user caches move from mcpp-index to mcpplibs
460+ // without losing xlings' active subos or version bindings.
388461 auto xjson = cfg.xlingsHome () / " .xlings.json" ;
389462 if (!std::filesystem::exists (xjson)) {
390463 write_default_xlings_json (xjson, cfg.indexRepos );
464+ } else {
465+ migrate_legacy_xlings_json_index_names (xjson);
391466 }
392467
393468 // 6. Acquire xlings binary if needed
0 commit comments