1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:13:22 +08:00

Allow UpdateFile to be called when a previous file doesn't exist

This commit is contained in:
Dean Herbert 2020-09-01 15:50:08 +09:00
parent 218cc39a4c
commit e80ef341d2

View File

@ -397,15 +397,24 @@ namespace osu.Game.Database
}
}
/// <summary>
/// Update an existing file, or create a new entry if not already part of the <paramref name="model"/>'s files.
/// </summary>
/// <param name="model">The item to operate on.</param>
/// <param name="file">The file model to be updated or added.</param>
/// <param name="contents">The new file contents.</param>
public void UpdateFile(TModel model, TFileModel file, Stream contents)
{
using (var usage = ContextFactory.GetForWrite())
{
// Dereference the existing file info, since the file model will be removed.
Files.Dereference(file.FileInfo);
if (file.FileInfo != null)
{
Files.Dereference(file.FileInfo);
// Remove the file model.
usage.Context.Set<TFileModel>().Remove(file);
// Remove the file model.
usage.Context.Set<TFileModel>().Remove(file);
}
// Add the new file info and containing file model.
model.Files.Remove(file);