File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,7 +7,8 @@ namespace Nerdbank.GitVersioning;
77
88internal static class Utilities
99{
10- private const int ProcessCannotAccessFileHR = unchecked ( ( int ) 0x80070020 ) ;
10+ private const int SharingViolation = unchecked ( ( int ) 0x80070020 ) ; // ERROR_SHARING_VIOLATION
11+ private const int AccessDenied = unchecked ( ( int ) 0x80070005 ) ; // ERROR_ACCESS_DENIED
1112
1213 internal static void FileOperationWithRetry ( Action operation )
1314 {
@@ -20,11 +21,15 @@ internal static void FileOperationWithRetry(Action operation)
2021 operation ( ) ;
2122 break ;
2223 }
23- catch ( IOException ex ) when ( ex . HResult == ProcessCannotAccessFileHR && retriesLeft > 0 )
24+ catch ( Exception ex ) when ( IsTransientFileAccessError ( ex ) && retriesLeft > 1 )
2425 {
25- Task . Delay ( 100 ) . Wait ( ) ;
26+ Thread . Sleep ( 100 ) ;
2627 continue ;
2728 }
2829 }
2930 }
31+
32+ private static bool IsTransientFileAccessError ( Exception ex ) => ex is
33+ IOException { HResult : SharingViolation } or
34+ UnauthorizedAccessException { HResult : AccessDenied } ;
3035}
You can’t perform that action at this time.
0 commit comments