forked from dotnet/Nerdbank.GitVersioning
/
Utilities.cs
32 lines (29 loc) · 855 Bytes
/
Utilities.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Validation;
namespace Nerdbank.GitVersioning
{
internal static class Utilities
{
private const int ProcessCannotAccessFileHR = unchecked((int)0x80070020);
internal static void FileOperationWithRetry(Action operation)
{
Requires.NotNull(operation, nameof(operation));
for (int retriesLeft = 6; retriesLeft > 0; retriesLeft--)
{
try
{
operation();
break;
}
catch (IOException ex) when (ex.HResult == ProcessCannotAccessFileHR && retriesLeft > 0)
{
Task.Delay(100).Wait();
continue;
}
}
}
}
}