Skip to content

Commit

Permalink
Merge pull request #19478 from peppy/fix-collection-migration
Browse files Browse the repository at this point in the history
Fix collection migration potentially deleting the database before finishing migration
  • Loading branch information
frenzibyte authored Jul 30, 2022
2 parents 471a068 + 6ad86ce commit 498c796
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions osu.Game/Database/RealmAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -794,22 +794,23 @@ void convertOnlineIDs<T>() where T : RealmObject
break;

case 21:
try
{
// Migrate collections from external file to inside realm.
// We use the "legacy" importer because that is how things were actually being saved out until now.
var legacyCollectionImporter = new LegacyCollectionImporter(this);
// Migrate collections from external file to inside realm.
// We use the "legacy" importer because that is how things were actually being saved out until now.
var legacyCollectionImporter = new LegacyCollectionImporter(this);

if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0)
{
legacyCollectionImporter.ImportFromStorage(storage);
storage.Delete("collection.db");
}
}
catch (Exception e)
if (legacyCollectionImporter.GetAvailableCount(storage).GetResultSafely() > 0)
{
// can be removed 20221027 (just for initial safety).
Logger.Error(e, "Collections could not be migrated to realm. Please provide your \"collection.db\" to the dev team.");
legacyCollectionImporter.ImportFromStorage(storage).ContinueWith(task =>
{
if (task.Exception != null)
{
// can be removed 20221027 (just for initial safety).
Logger.Error(task.Exception.InnerException, "Collections could not be migrated to realm. Please provide your \"collection.db\" to the dev team.");
return;
}

storage.Move("collection.db", "collection.db.migrated");
});
}

break;
Expand Down

0 comments on commit 498c796

Please sign in to comment.