mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 09:42:57 +08:00
Attempt delete operations more than once
This commit is contained in:
parent
9ed0e8891b
commit
6ca102bc3f
@ -84,7 +84,7 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
fi.Delete();
|
attemptOperation(() => fi.Delete());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DirectoryInfo dir in target.GetDirectories())
|
foreach (DirectoryInfo dir in target.GetDirectories())
|
||||||
@ -92,11 +92,11 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_DIRECTORIES.Contains(dir.Name))
|
if (topLevelExcludes && IGNORE_DIRECTORIES.Contains(dir.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
dir.Delete(true);
|
attemptOperation(() => dir.Delete(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0)
|
if (target.GetFiles().Length == 0 && target.GetDirectories().Length == 0)
|
||||||
target.Delete();
|
attemptOperation(target.Delete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true)
|
private static void copyRecursive(DirectoryInfo source, DirectoryInfo destination, bool topLevelExcludes = true)
|
||||||
@ -109,7 +109,7 @@ namespace osu.Game.IO
|
|||||||
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
if (topLevelExcludes && IGNORE_FILES.Contains(fi.Name))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
attemptCopy(fi, Path.Combine(destination.FullName, fi.Name));
|
attemptOperation(() => fi.CopyTo(Path.Combine(destination.FullName, fi.Name), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (DirectoryInfo dir in source.GetDirectories())
|
foreach (DirectoryInfo dir in source.GetDirectories())
|
||||||
@ -121,24 +121,27 @@ namespace osu.Game.IO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void attemptCopy(System.IO.FileInfo fileInfo, string destination)
|
/// <summary>
|
||||||
|
/// Attempt an IO operation multiple times and only throw if none of the attempts succeed.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="action">The action to perform.</param>
|
||||||
|
/// <param name="attempts">The number of attempts (250ms wait between each).</param>
|
||||||
|
private static void attemptOperation(Action action, int attempts = 10)
|
||||||
{
|
{
|
||||||
int tries = 5;
|
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
fileInfo.CopyTo(destination, true);
|
action();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
if (tries-- == 0)
|
if (attempts-- == 0)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.Sleep(50);
|
Thread.Sleep(250);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user