Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't delete file in case of ResetFile schema mode #7331

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* Fixed invalid data in error reason string when registering a subscription change notification after the subscription has already failed. ([#6839](https://github.com/realm/realm-core/issues/6839), since v11.8.0)
* Fixed crash in fulltext index using prefix search with no matches ([#7309](https://github.com/realm/realm-core/issues/7309), since v13.18.0)
* Fix compilation and some warnings when building with Xcode 15.3 ([PR #7297](https://github.com/realm/realm-core/pull/7297)).
* Realm file would be deleted if SoftResetFile or HardResetFile was used and the file needed an upgrade. It will no longer be deleted in that case and just upgraded. ([#7140](https://github.com/realm/realm-core/issues/7140), since long time ago)

### Breaking changes
* None.
Expand Down
88 changes: 35 additions & 53 deletions src/realm/object-store/impl/realm_coordinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,72 +446,54 @@ bool RealmCoordinator::open_db()
#endif

bool server_synchronization_mode = m_config.sync_config || m_config.force_sync_history;
bool schema_mode_reset_file =
m_config.schema_mode == SchemaMode::SoftResetFile || m_config.schema_mode == SchemaMode::HardResetFile;
try {
if (m_config.immutable() && m_config.realm_data) {
m_db = DB::create(m_config.realm_data, false);
return true;
}
std::unique_ptr<Replication> history;
if (server_synchronization_mode) {
if (m_config.immutable() && m_config.realm_data) {
m_db = DB::create(m_config.realm_data, false);
return true;
}
std::unique_ptr<Replication> history;
if (server_synchronization_mode) {
#if REALM_ENABLE_SYNC
bool apply_server_changes = !m_config.sync_config || m_config.sync_config->apply_server_changes;
history = std::make_unique<sync::ClientReplication>(apply_server_changes);
bool apply_server_changes = !m_config.sync_config || m_config.sync_config->apply_server_changes;
history = std::make_unique<sync::ClientReplication>(apply_server_changes);
#else
REALM_TERMINATE("Realm was not built with sync enabled");
REALM_TERMINATE("Realm was not built with sync enabled");
#endif
}
else if (!m_config.immutable()) {
history = make_in_realm_history();
}
}
else if (!m_config.immutable()) {
history = make_in_realm_history();
}

DBOptions options;
DBOptions options;
#ifndef __EMSCRIPTEN__
options.enable_async_writes = true;
options.enable_async_writes = true;
#endif
options.durability = m_config.in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full;
options.is_immutable = m_config.immutable();
options.logger = util::Logger::get_default_logger();
options.durability = m_config.in_memory ? DBOptions::Durability::MemOnly : DBOptions::Durability::Full;
options.is_immutable = m_config.immutable();
options.logger = util::Logger::get_default_logger();

if (!m_config.fifo_files_fallback_path.empty()) {
options.temp_dir = util::normalize_dir(m_config.fifo_files_fallback_path);
}
options.encryption_key = m_config.encryption_key.data();
options.allow_file_format_upgrade = !m_config.disable_format_upgrade && !schema_mode_reset_file;
if (history) {
options.backup_at_file_format_change = m_config.backup_at_file_format_change;
if (!m_config.fifo_files_fallback_path.empty()) {
options.temp_dir = util::normalize_dir(m_config.fifo_files_fallback_path);
}
options.encryption_key = m_config.encryption_key.data();
options.allow_file_format_upgrade = !m_config.disable_format_upgrade;
if (history) {
options.backup_at_file_format_change = m_config.backup_at_file_format_change;
#ifdef __EMSCRIPTEN__
// Force the DB to be created in memory-only mode, ignoring the filesystem path supplied in the config.
// This is so we can run an SDK on top without having to solve the browser persistence problem yet,
// or teach RealmConfig and SDKs about pure in-memory realms.
m_db = DB::create_in_memory(std::move(history), m_config.path, options);
// Force the DB to be created in memory-only mode, ignoring the filesystem path supplied in the config.
// This is so we can run an SDK on top without having to solve the browser persistence problem yet,
// or teach RealmConfig and SDKs about pure in-memory realms.
m_db = DB::create_in_memory(std::move(history), m_config.path, options);
#else
if (m_config.path.size()) {
m_db = DB::create(std::move(history), m_config.path, options);
}
else {
m_db = DB::create(std::move(history), options);
}
#endif
if (m_config.path.size()) {
m_db = DB::create(std::move(history), m_config.path, options);
}
else {
m_db = DB::create(m_config.path, true, options);
}
}
catch (realm::FileFormatUpgradeRequired const&) {
if (!schema_mode_reset_file) {
throw;
m_db = DB::create(std::move(history), options);
}
util::File::remove(m_config.path);
return open_db();
#endif
}
catch (UnsupportedFileFormatVersion const&) {
if (!schema_mode_reset_file) {
throw;
}
util::File::remove(m_config.path);
return open_db();
else {
m_db = DB::create(m_config.path, true, options);
}

if (m_config.should_compact_on_launch_function) {
Expand Down
Loading