diff --git a/src/js_realm.hpp b/src/js_realm.hpp index 27522d73..68652738 100644 --- a/src/js_realm.hpp +++ b/src/js_realm.hpp @@ -463,7 +463,6 @@ void RealmClass::clear_test_state(ContextType ctx, ObjectType this_object, si } SyncManager::shared().reset_for_testing(); SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); - s_sync_directory = ""; #endif } diff --git a/src/js_sync.hpp b/src/js_sync.hpp index e44929f8..af94ac39 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -35,25 +35,6 @@ namespace realm { namespace js { -static std::string s_sync_directory; - -static void set_sync_directory(std::string dir) { - if (s_sync_directory.length()) { - throw std::runtime_error("Sync directory can only be set once before using any Sync apis"); - } - s_sync_directory = dir; - - // setup synced realmFile paths - ensure_directory_exists_for_file(dir); - SyncManager::shared().configure_file_system(dir, SyncManager::MetadataMode::NoEncryption); -} - -static void ensure_sync_directory() { - if (s_sync_directory.length() == 0) { - set_sync_directory(default_realm_file_directory()); - } -} - using SharedUser = std::shared_ptr; template @@ -134,8 +115,6 @@ void UserClass::is_admin(ContextType ctx, ObjectType object, ReturnValue &ret template void UserClass::create_user(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 3, 4); - ensure_sync_directory(); - SharedUser *user = new SharedUser(SyncManager::shared().get_user( Value::validated_to_string(ctx, arguments[1]), Value::validated_to_string(ctx, arguments[2]), @@ -146,8 +125,6 @@ void UserClass::create_user(ContextType ctx, ObjectType this_object, size_t a template void UserClass::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) { - ensure_sync_directory(); - auto users = Object::create_empty(ctx); for (auto user : SyncManager::shared().all_logged_in_users()) { if (!user->is_admin()) { @@ -159,8 +136,6 @@ void UserClass::all_users(ContextType ctx, ObjectType object, ReturnValue &re template void UserClass::current_user(ContextType ctx, ObjectType object, ReturnValue &return_value) { - ensure_sync_directory(); - SharedUser *current = nullptr; for (auto user : SyncManager::shared().all_logged_in_users()) { if (!user->is_admin()) { @@ -204,8 +179,6 @@ public: static FunctionType create_constructor(ContextType); static void set_sync_log_level(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); - static void set_sync_directory(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); - static void ensure_sync_directory(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); static void set_verify_servers_ssl_certificate(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); // private @@ -218,8 +191,6 @@ public: MethodMap const static_methods = { {"refreshAccessToken", wrap}, {"setLogLevel", wrap}, - {"setSyncDirectory", wrap}, - {"ensureSyncDirectory", wrap}, {"setVerifyServersSslCertificate", wrap} }; }; @@ -231,6 +202,10 @@ inline typename T::Function SyncClass::create_constructor(ContextType ctx) { PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete; Object::set_property(ctx, sync_constructor, "User", ObjectWrap>::create_constructor(ctx), attributes); + // setup synced realmFile paths + ensure_directory_exists_for_file(default_realm_file_directory()); + SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); + realm::SyncManager::shared().set_error_handler([=](int error_code, std::string message) { std::cout << error_code << " " << message << std::endl; }); @@ -241,7 +216,6 @@ inline typename T::Function SyncClass::create_constructor(ContextType ctx) { template void SyncClass::set_sync_log_level(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1); - realm::js::ensure_sync_directory(); std::string log_level = Value::validated_to_string(ctx, arguments[0]); std::istringstream in(log_level); // Throws in.imbue(std::locale::classic()); // Throws @@ -253,23 +227,9 @@ void SyncClass::set_sync_log_level(ContextType ctx, ObjectType this_object, s realm::SyncManager::shared().set_log_level(log_level_2); } -template -void SyncClass::set_sync_directory(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { - validate_argument_count(argc, 1); - realm::js::set_sync_directory(Value::validated_to_string(ctx, arguments[0])); -} - -template -void SyncClass::ensure_sync_directory(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { - validate_argument_count(argc, 0); - realm::js::ensure_sync_directory(); -} - template void SyncClass::set_verify_servers_ssl_certificate(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { validate_argument_count(argc, 1); - realm::js::ensure_sync_directory(); - bool verify_servers_ssl_certificate = Value::validated_to_boolean(ctx, arguments[0]); realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate); } @@ -301,8 +261,6 @@ void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constr { ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); if (!Value::is_undefined(ctx, sync_config_value)) { - realm::js::ensure_sync_directory(); - auto sync_config_object = Value::validated_to_object(ctx, sync_config_value); ObjectType sync_constructor = Object::validated_get_object(ctx, realm_constructor, std::string("Sync"));