1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 01:52:55 +08:00

Overwrite existing files if AddFile is called with an existing filename

This commit is contained in:
Dean Herbert 2021-12-02 17:17:12 +09:00
parent ec700e9142
commit ae3038ead4
2 changed files with 10 additions and 2 deletions

View File

@ -25,7 +25,7 @@ namespace osu.Game.Database
void DeleteFile(TModel model, TFileModel file); void DeleteFile(TModel model, TFileModel file);
/// <summary> /// <summary>
/// Add a new file. /// Add a new file. If the file already exists, it is overwritten.
/// </summary> /// </summary>
/// <param name="model">The item to operate on.</param> /// <param name="model">The item to operate on.</param>
/// <param name="contents">The new file contents.</param> /// <param name="contents">The new file contents.</param>

View File

@ -74,10 +74,18 @@ namespace osu.Game.Stores
} }
/// <summary> /// <summary>
/// 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.
/// </summary> /// </summary>
protected void AddFile(TModel item, Stream stream, string filename, Realm realm) 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 file = realmFileStore.Add(stream, realm);
var namedUsage = new RealmNamedFileUsage(file, filename); var namedUsage = new RealmNamedFileUsage(file, filename);