1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Fix model file infos not being removed

This commit is contained in:
smoogipoo 2020-01-14 18:43:06 +09:00
parent a255832195
commit 1b3bff6fa5
2 changed files with 10 additions and 5 deletions

View File

@ -34,7 +34,7 @@ namespace osu.Game.Database
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
public abstract class ArchiveModelManager<TModel, TFileModel> : ICanAcceptFiles, IModelManager<TModel>
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete
where TFileModel : INamedFileInfo, new()
where TFileModel : class, INamedFileInfo, new()
{
private const int import_queue_request_concurrency = 1;
@ -366,8 +366,15 @@ namespace osu.Game.Database
public void UpdateFile(TModel model, TFileModel file, Stream contents)
{
using (ContextFactory.GetForWrite())
using (var usage = ContextFactory.GetForWrite())
{
// Dereference the existing file info, since the file model will be removed.
Files.Dereference(file.FileInfo);
// Remove the file model.
usage.Context.Set<TFileModel>().Remove(file);
// Add the new file info and containing file model.
model.Files.Remove(file);
model.Files.Add(new TFileModel
{
@ -375,8 +382,6 @@ namespace osu.Game.Database
FileInfo = Files.Add(contents)
});
Files.Dereference(file.FileInfo);
Update(model);
}
}

View File

@ -21,7 +21,7 @@ namespace osu.Game.Database
/// <typeparam name="TFileModel">The associated file join type.</typeparam>
public abstract class DownloadableArchiveModelManager<TModel, TFileModel> : ArchiveModelManager<TModel, TFileModel>, IModelDownloader<TModel>
where TModel : class, IHasFiles<TFileModel>, IHasPrimaryKey, ISoftDelete, IEquatable<TModel>
where TFileModel : INamedFileInfo, new()
where TFileModel : class, INamedFileInfo, new()
{
public event Action<ArchiveDownloadRequest<TModel>> DownloadBegan;