mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 11:43:21 +08:00
Move collections db in-place
This commit is contained in:
parent
a1da9c5ee3
commit
c9a203cc11
@ -257,11 +257,14 @@ namespace osu.Game.Collections
|
||||
{
|
||||
Interlocked.Increment(ref lastSave);
|
||||
|
||||
// This is NOT thread-safe!!
|
||||
try
|
||||
{
|
||||
// This is NOT thread-safe!!
|
||||
var tempPath = Path.GetTempFileName();
|
||||
|
||||
using (var sw = new SerializationWriter(storage.GetStream(database_name, FileAccess.Write)))
|
||||
using (var ms = new MemoryStream())
|
||||
{
|
||||
using (var sw = new SerializationWriter(ms, true))
|
||||
{
|
||||
sw.Write(database_version);
|
||||
|
||||
@ -280,6 +283,18 @@ namespace osu.Game.Collections
|
||||
}
|
||||
}
|
||||
|
||||
using (var fs = File.OpenWrite(tempPath))
|
||||
ms.WriteTo(fs);
|
||||
|
||||
var storagePath = storage.GetFullPath(database_name);
|
||||
var storageBackupPath = storage.GetFullPath($"{database_name}.bak");
|
||||
if (File.Exists(storageBackupPath))
|
||||
File.Delete(storageBackupPath);
|
||||
if (File.Exists(storagePath))
|
||||
File.Move(storagePath, storageBackupPath);
|
||||
File.Move(tempPath, storagePath);
|
||||
}
|
||||
|
||||
if (saveFailures < 10)
|
||||
saveFailures = 0;
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user