mirror of
https://github.com/ppy/osu.git
synced 2024-12-16 00:02:54 +08:00
Use helper method for backup retry attempts
This commit is contained in:
parent
b262497083
commit
a4bc5a8fc9
@ -35,6 +35,7 @@ using osu.Game.Rulesets.Mods;
|
|||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
using osu.Game.Scoring.Legacy;
|
using osu.Game.Scoring.Legacy;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
using osu.Game.Utils;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
using Realms;
|
using Realms;
|
||||||
using Realms.Exceptions;
|
using Realms.Exceptions;
|
||||||
@ -1157,11 +1158,7 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
||||||
|
|
||||||
int attempts = 10;
|
FileUtils.AttemptOperation(() =>
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
using (var source = storage.GetStream(Filename, mode: FileMode.Open))
|
using (var source = storage.GetStream(Filename, mode: FileMode.Open))
|
||||||
{
|
{
|
||||||
@ -1172,18 +1169,7 @@ namespace osu.Game.Database
|
|||||||
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
||||||
source.CopyTo(destination);
|
source.CopyTo(destination);
|
||||||
}
|
}
|
||||||
|
}, 20);
|
||||||
return;
|
|
||||||
}
|
|
||||||
catch (IOException)
|
|
||||||
{
|
|
||||||
if (attempts-- <= 0)
|
|
||||||
throw;
|
|
||||||
|
|
||||||
// file may be locked during use.
|
|
||||||
Thread.Sleep(500);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user