From ae3038ead4afb1329f765eca71dbdfa3dcfc78d0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 2 Dec 2021 17:17:12 +0900 Subject: [PATCH] Overwrite existing files if `AddFile` is called with an existing filename --- osu.Game/Database/IModelFileManager.cs | 2 +- osu.Game/Stores/RealmArchiveModelManager.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/osu.Game/Database/IModelFileManager.cs b/osu.Game/Database/IModelFileManager.cs index 4bc1e2d29b..390be4a69d 100644 --- a/osu.Game/Database/IModelFileManager.cs +++ b/osu.Game/Database/IModelFileManager.cs @@ -25,7 +25,7 @@ namespace osu.Game.Database void DeleteFile(TModel model, TFileModel file); /// - /// Add a new file. + /// Add a new file. If the file already exists, it is overwritten. /// /// The item to operate on. /// The new file contents. diff --git a/osu.Game/Stores/RealmArchiveModelManager.cs b/osu.Game/Stores/RealmArchiveModelManager.cs index a916e2b53a..4efcdd096c 100644 --- a/osu.Game/Stores/RealmArchiveModelManager.cs +++ b/osu.Game/Stores/RealmArchiveModelManager.cs @@ -74,10 +74,18 @@ namespace osu.Game.Stores } /// - /// Add a file from within an ongoing realm transaction. + /// Add a file from within an ongoing realm transaction. If the file already exists, it is overwritten. /// protected void AddFile(TModel item, Stream stream, string filename, Realm realm) { + var existing = item.Files.FirstOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase)); + + if (existing != null) + { + ReplaceFile(item, existing, stream, realm); + return; + } + var file = realmFileStore.Add(stream, realm); var namedUsage = new RealmNamedFileUsage(file, filename);