1818
1919#include < realm/object-store/sync/impl/app_metadata.hpp>
2020
21- #include < realm/object-store/sync/ impl/sync_file .hpp>
21+ #include < realm/object-store/impl/realm_coordinator .hpp>
2222#include < realm/object-store/object_schema.hpp>
2323#include < realm/object-store/object_store.hpp>
2424#include < realm/object-store/property.hpp>
2525#include < realm/object-store/results.hpp>
2626#include < realm/object-store/schema.hpp>
27+ #include < realm/object-store/sync/impl/sync_file.hpp>
2728#include < realm/object-store/util/scheduler.hpp>
29+
2830#if REALM_PLATFORM_APPLE
2931#include < realm/object-store/impl/apple/keychain_helper.hpp>
3032#endif
@@ -336,13 +338,13 @@ std::shared_ptr<Realm> open_realm(RealmConfig& config, const app::AppConfig& app
336338}
337339
338340struct PersistedSyncMetadataManager : public app ::MetadataStore {
339- RealmConfig m_config ;
341+ std::shared_ptr<_impl::RealmCoordinator> m_coordinator ;
340342 SyncUserSchema m_user_schema;
341343 FileActionSchema m_file_action_schema;
342344 UserIdentitySchema m_user_identity_schema;
343345 CurrentUserSchema m_current_user_schema;
344346
345- PersistedSyncMetadataManager (std::string path, const app::AppConfig& app_config, SyncFileManager& file_manager)
347+ PersistedSyncMetadataManager (const app::AppConfig& app_config, SyncFileManager& file_manager)
346348 {
347349 // Note that there are several deferred schema changes which don't
348350 // justify bumping the schema version by themself, but should be done
@@ -353,26 +355,27 @@ struct PersistedSyncMetadataManager : public app::MetadataStore {
353355 // - change most of the nullable columns to non-nullable
354356 constexpr uint64_t SCHEMA_VERSION = 7 ;
355357
356- m_config.automatic_change_notifications = false ;
357- m_config.path = std::move (path);
358- m_config.schema = Schema{
358+ RealmConfig config;
359+ config.automatic_change_notifications = false ;
360+ config.path = file_manager.metadata_path ();
361+ config.schema = Schema{
359362 UserIdentitySchema::object_schema (),
360363 SyncUserSchema::object_schema (),
361364 FileActionSchema::object_schema (),
362365 CurrentUserSchema::object_schema (),
363366 };
364367
365- m_config .schema_version = SCHEMA_VERSION;
366- m_config .schema_mode = SchemaMode::Automatic;
367- m_config .scheduler = util::Scheduler::make_dummy ();
368- m_config .automatically_handle_backlinks_in_migrations = true ;
369- m_config .migration_function = [](std::shared_ptr<Realm> old_realm, std::shared_ptr<Realm> realm, Schema&) {
368+ config .schema_version = SCHEMA_VERSION;
369+ config .schema_mode = SchemaMode::Automatic;
370+ config .scheduler = util::Scheduler::make_dummy ();
371+ config .automatically_handle_backlinks_in_migrations = true ;
372+ config .migration_function = [](std::shared_ptr<Realm> old_realm, std::shared_ptr<Realm> realm, Schema&) {
370373 if (old_realm->schema_version () < 7 ) {
371374 migrate_to_v7 (old_realm, realm);
372375 }
373376 };
374377
375- auto realm = open_realm (m_config , app_config);
378+ auto realm = open_realm (config , app_config);
376379 m_user_schema.read (*realm);
377380 m_file_action_schema.read (*realm);
378381 m_user_identity_schema.read (*realm);
@@ -382,11 +385,13 @@ struct PersistedSyncMetadataManager : public app::MetadataStore {
382385 perform_file_actions (*realm, file_manager);
383386 remove_dead_users (*realm, file_manager);
384387 realm->commit_transaction ();
388+
389+ m_coordinator = _impl::RealmCoordinator::get_existing_coordinator (config.path );
385390 }
386391
387392 std::shared_ptr<Realm> get_realm () const
388393 {
389- return Realm::get_shared_realm (m_config );
394+ return m_coordinator-> get_realm ( util::Scheduler::make_dummy () );
390395 }
391396
392397 void remove_dead_users (Realm& realm, SyncFileManager& file_manager)
@@ -933,5 +938,5 @@ std::unique_ptr<app::MetadataStore> app::create_metadata_store(const AppConfig&
933938 if (config.metadata_mode == AppConfig::MetadataMode::InMemory) {
934939 return std::make_unique<InMemoryMetadataStorage>();
935940 }
936- return std::make_unique<PersistedSyncMetadataManager>(file_manager. metadata_path (), config, file_manager);
941+ return std::make_unique<PersistedSyncMetadataManager>(config, file_manager);
937942}
0 commit comments