mirror of https://github.com/ppy/osu
Overwrite existing files if `AddFile` is called with an existing filename
This commit is contained in:
parent
ec700e9142
commit
ae3038ead4
|
@ -25,7 +25,7 @@ public interface IModelFileManager<in TModel, in TFileModel>
|
|||
void DeleteFile(TModel model, TFileModel file);
|
||||
|
||||
/// <summary>
|
||||
/// Add a new file.
|
||||
/// Add a new file. If the file already exists, it is overwritten.
|
||||
/// </summary>
|
||||
/// <param name="model">The item to operate on.</param>
|
||||
/// <param name="contents">The new file contents.</param>
|
||||
|
|
|
@ -74,10 +74,18 @@ protected void ReplaceFile(TModel model, RealmNamedFileUsage file, Stream conten
|
|||
}
|
||||
|
||||
/// <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>
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue