only use custom dir for the notifier

This commit is contained in:
Ari Lazier 2016-12-09 17:15:46 +01:00
parent 64730e7e97
commit 43cb7bc463
2 changed files with 4 additions and 47 deletions

View File

@ -463,7 +463,6 @@ void RealmClass<T>::clear_test_state(ContextType ctx, ObjectType this_object, si
} }
SyncManager::shared().reset_for_testing(); SyncManager::shared().reset_for_testing();
SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption);
s_sync_directory = "";
#endif #endif
} }

View File

@ -35,25 +35,6 @@
namespace realm { namespace realm {
namespace js { 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<realm::SyncUser>; using SharedUser = std::shared_ptr<realm::SyncUser>;
template<typename T> template<typename T>
@ -134,8 +115,6 @@ void UserClass<T>::is_admin(ContextType ctx, ObjectType object, ReturnValue &ret
template<typename T> template<typename T>
void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 3, 4); validate_argument_count(argc, 3, 4);
ensure_sync_directory();
SharedUser *user = new SharedUser(SyncManager::shared().get_user( SharedUser *user = new SharedUser(SyncManager::shared().get_user(
Value::validated_to_string(ctx, arguments[1]), Value::validated_to_string(ctx, arguments[1]),
Value::validated_to_string(ctx, arguments[2]), Value::validated_to_string(ctx, arguments[2]),
@ -146,8 +125,6 @@ void UserClass<T>::create_user(ContextType ctx, ObjectType this_object, size_t a
template<typename T> template<typename T>
void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) { void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &return_value) {
ensure_sync_directory();
auto users = Object::create_empty(ctx); auto users = Object::create_empty(ctx);
for (auto user : SyncManager::shared().all_logged_in_users()) { for (auto user : SyncManager::shared().all_logged_in_users()) {
if (!user->is_admin()) { if (!user->is_admin()) {
@ -159,8 +136,6 @@ void UserClass<T>::all_users(ContextType ctx, ObjectType object, ReturnValue &re
template<typename T> template<typename T>
void UserClass<T>::current_user(ContextType ctx, ObjectType object, ReturnValue &return_value) { void UserClass<T>::current_user(ContextType ctx, ObjectType object, ReturnValue &return_value) {
ensure_sync_directory();
SharedUser *current = nullptr; SharedUser *current = nullptr;
for (auto user : SyncManager::shared().all_logged_in_users()) { for (auto user : SyncManager::shared().all_logged_in_users()) {
if (!user->is_admin()) { if (!user->is_admin()) {
@ -204,8 +179,6 @@ public:
static FunctionType create_constructor(ContextType); static FunctionType create_constructor(ContextType);
static void set_sync_log_level(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &); 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 &); static void set_verify_servers_ssl_certificate(ContextType, ObjectType, size_t, const ValueType[], ReturnValue &);
// private // private
@ -218,8 +191,6 @@ public:
MethodMap<T> const static_methods = { MethodMap<T> const static_methods = {
{"refreshAccessToken", wrap<refresh_access_token>}, {"refreshAccessToken", wrap<refresh_access_token>},
{"setLogLevel", wrap<set_sync_log_level>}, {"setLogLevel", wrap<set_sync_log_level>},
{"setSyncDirectory", wrap<set_sync_directory>},
{"ensureSyncDirectory", wrap<ensure_sync_directory>},
{"setVerifyServersSslCertificate", wrap<set_verify_servers_ssl_certificate>} {"setVerifyServersSslCertificate", wrap<set_verify_servers_ssl_certificate>}
}; };
}; };
@ -231,6 +202,10 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete; PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete;
Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::create_constructor(ctx), attributes); Object::set_property(ctx, sync_constructor, "User", ObjectWrap<T, UserClass<T>>::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) { realm::SyncManager::shared().set_error_handler([=](int error_code, std::string message) {
std::cout << error_code << " " << message << std::endl; std::cout << error_code << " " << message << std::endl;
}); });
@ -241,7 +216,6 @@ inline typename T::Function SyncClass<T>::create_constructor(ContextType ctx) {
template<typename T> template<typename T>
void SyncClass<T>::set_sync_log_level(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { void SyncClass<T>::set_sync_log_level(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 1); validate_argument_count(argc, 1);
realm::js::ensure_sync_directory();
std::string log_level = Value::validated_to_string(ctx, arguments[0]); std::string log_level = Value::validated_to_string(ctx, arguments[0]);
std::istringstream in(log_level); // Throws std::istringstream in(log_level); // Throws
in.imbue(std::locale::classic()); // Throws in.imbue(std::locale::classic()); // Throws
@ -253,23 +227,9 @@ void SyncClass<T>::set_sync_log_level(ContextType ctx, ObjectType this_object, s
realm::SyncManager::shared().set_log_level(log_level_2); realm::SyncManager::shared().set_log_level(log_level_2);
} }
template<typename T>
void SyncClass<T>::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<typename T>
void SyncClass<T>::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<typename T> template<typename T>
void SyncClass<T>::set_verify_servers_ssl_certificate(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { void SyncClass<T>::set_verify_servers_ssl_certificate(ContextType ctx, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) {
validate_argument_count(argc, 1); validate_argument_count(argc, 1);
realm::js::ensure_sync_directory();
bool verify_servers_ssl_certificate = Value::validated_to_boolean(ctx, arguments[0]); bool verify_servers_ssl_certificate = Value::validated_to_boolean(ctx, arguments[0]);
realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate); realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate);
} }
@ -301,8 +261,6 @@ void SyncClass<T>::populate_sync_config(ContextType ctx, ObjectType realm_constr
{ {
ValueType sync_config_value = Object::get_property(ctx, config_object, "sync"); ValueType sync_config_value = Object::get_property(ctx, config_object, "sync");
if (!Value::is_undefined(ctx, sync_config_value)) { 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); 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")); ObjectType sync_constructor = Object::validated_get_object(ctx, realm_constructor, std::string("Sync"));