mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 04:53:21 +08:00
Overwrite existing files if AddFile
is called with an existing filename
This commit is contained in:
parent
ec700e9142
commit
ae3038ead4
@ -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>
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user