Skip to content

Commit a7eeb54

Browse files
committed
handle UnauthorizedAccessException
fixes #302
1 parent c457442 commit a7eeb54

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/DiffEngine/OsSettingsResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static bool TryFindInEnvPath(string exeName, [NotNullWhen(true)] out stri
112112
// Return the first one that exists.
113113
exePath = envPaths
114114
.Select(_ => Path.Combine(_, exeName))
115-
.FirstOrDefault(_ => File.Exists(_));
115+
.FirstOrDefault(File.Exists);
116116

117117
return exePath != null;
118118
}

src/DiffEngineTray/FileEx.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
using IOException = System.IO.IOException;
2+
13
static class FileEx
24
{
35
public static bool IsEmptyDirectory(string directory) =>
@@ -58,6 +60,11 @@ public static bool SafeDeleteDirectory(string path)
5860

5961
public static bool SafeMove(string temp, string target)
6062
{
63+
//Swallow this since it is likely that a running test it reading or
64+
//writing to the files, and the result will re-add the tracked item
65+
void HandleAccessException(Exception exception) =>
66+
Log.Error(exception, $"Failed to move '{temp}' to '{target}'.");
67+
6168
if (!File.Exists(temp))
6269
{
6370
return false;
@@ -68,11 +75,13 @@ public static bool SafeMove(string temp, string target)
6875
File.Move(temp, target, true);
6976
return true;
7077
}
78+
catch (UnauthorizedAccessException exception)
79+
{
80+
HandleAccessException(exception);
81+
}
7182
catch (IOException exception)
7283
{
73-
Log.Error(exception, $"Failed to move '{temp}' to '{target}'.");
74-
//Swallow this since it is likely that a running test it reading or
75-
//writing to the files, and the result will re-add the tracked item
84+
HandleAccessException(exception);
7685
}
7786
catch (Exception exception)
7887
{

0 commit comments

Comments
 (0)