diff --git a/osu.Game.Tests/Database/BeatmapImporterTests.cs b/osu.Game.Tests/Database/BeatmapImporterTests.cs index 9d67381b5a..9abd78039a 100644 --- a/osu.Game.Tests/Database/BeatmapImporterTests.cs +++ b/osu.Game.Tests/Database/BeatmapImporterTests.cs @@ -590,6 +590,8 @@ namespace osu.Game.Tests.Database Assert.IsTrue(imported.DeletePending); + var originalAddedDate = imported.DateAdded; + var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm); // check the newly "imported" beatmap is actually just the restored previous import. since it matches hash. @@ -597,6 +599,7 @@ namespace osu.Game.Tests.Database Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID); Assert.IsFalse(imported.DeletePending); Assert.IsFalse(importedSecondTime.DeletePending); + Assert.That(importedSecondTime.DateAdded, Is.GreaterThan(originalAddedDate)); }); } @@ -646,6 +649,8 @@ namespace osu.Game.Tests.Database Assert.IsTrue(imported.DeletePending); + var originalAddedDate = imported.DateAdded; + var importedSecondTime = await LoadOszIntoStore(importer, realm.Realm); // check the newly "imported" beatmap is actually just the restored previous import. since it matches hash. @@ -653,6 +658,7 @@ namespace osu.Game.Tests.Database Assert.IsTrue(imported.Beatmaps.First().ID == importedSecondTime.Beatmaps.First().ID); Assert.IsFalse(imported.DeletePending); Assert.IsFalse(importedSecondTime.DeletePending); + Assert.That(importedSecondTime.DateAdded, Is.GreaterThan(originalAddedDate)); }); } diff --git a/osu.Game/Stores/BeatmapImporter.cs b/osu.Game/Stores/BeatmapImporter.cs index e6b655589c..f04a0210ef 100644 --- a/osu.Game/Stores/BeatmapImporter.cs +++ b/osu.Game/Stores/BeatmapImporter.cs @@ -163,6 +163,12 @@ namespace osu.Game.Stores return existing.OnlineID == import.OnlineID && existingIds.SequenceEqual(importIds); } + protected override void UndeleteForReuse(BeatmapSetInfo existing) + { + base.UndeleteForReuse(existing); + existing.DateAdded = DateTimeOffset.UtcNow; + } + public override bool IsAvailableLocally(BeatmapSetInfo model) { return Realm.Run(realm => realm.All().Any(s => s.OnlineID == model.OnlineID)); diff --git a/osu.Game/Stores/RealmArchiveModelImporter.cs b/osu.Game/Stores/RealmArchiveModelImporter.cs index 3011bc0320..1d0e16d549 100644 --- a/osu.Game/Stores/RealmArchiveModelImporter.cs +++ b/osu.Game/Stores/RealmArchiveModelImporter.cs @@ -351,7 +351,8 @@ namespace osu.Game.Stores using (var transaction = realm.BeginWrite()) { - existing.DeletePending = false; + if (existing.DeletePending) + UndeleteForReuse(existing); transaction.Commit(); } @@ -387,7 +388,9 @@ namespace osu.Game.Stores { LogForModel(item, @$"Found existing {HumanisedModelName} for {item} (ID {existing.ID}) – skipping import."); - existing.DeletePending = false; + if (existing.DeletePending) + UndeleteForReuse(existing); + transaction.Commit(); return existing.ToLive(Realm); @@ -527,6 +530,15 @@ namespace osu.Game.Stores private bool checkAllFilesExist(TModel model) => model.Files.All(f => Files.Storage.Exists(f.File.GetStoragePath())); + /// + /// Called when an existing model is in a soft deleted state but being recovered. + /// + /// The existing model. + protected virtual void UndeleteForReuse(TModel existing) + { + existing.DeletePending = false; + } + /// /// Whether this specified path should be removed after successful import. ///