Skip to content

Commit f7646d7

Browse files
authored
Fix #696 (#698)
1 parent c6bc79f commit f7646d7

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

Lib/Collectors/WindowsFileSystemUtils.cs

+14-18
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,19 @@ public static List<DLLCHARACTERISTICS> GetDllCharacteristics(string Path)
8383
}
8484
// This can happen if the file is readable but not writable as MMFile tries to open the file with write privileges.
8585
// When we fail we can retry by reading the file to a Stream first, which cen be less performant but works with just Read access
86-
// See #684
87-
catch (UnauthorizedAccessException)
86+
// See #684 + #696
87+
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
8888
{
8989
try
9090
{
9191
using var stream = File.OpenRead(Path);
9292
return GetDllCharacteristics(Path, stream);
9393
}
94-
catch (Exception e)
94+
catch (Exception ex)
9595
{
96-
Log.Debug(e, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
96+
Log.Debug(ex, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, ex.GetType(), ex.Message);
9797
}
9898
}
99-
catch (Exception e) when (
100-
e is IndexOutOfRangeException
101-
|| e is ArgumentNullException
102-
|| e is System.IO.IOException
103-
|| e is ArgumentException
104-
|| e is NullReferenceException)
105-
{
106-
Log.Debug("Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
107-
}
10899
catch (Exception e)
109100
{
110101
Log.Debug(e, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
@@ -185,18 +176,18 @@ private static List<DLLCHARACTERISTICS> CharacteristicsTypeToListOfCharacteristi
185176
}
186177
}
187178
// This can happen if the file is readable but not writable as MMFile tries to open the file with write privileges.
188-
// When we fail we can retry by reading the file to a Stream first, which cen be less performant but works with just Read access
189-
// See #684
190-
catch (UnauthorizedAccessException)
179+
// When we fail we can retry by reading the file to a Stream first, which can be less performant but works with just Read access
180+
// See #684 + #696
181+
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
191182
{
192183
try
193184
{
194185
using var stream = File.OpenRead(Path);
195186
return GetSignatureStatus(Path, stream);
196187
}
197-
catch (Exception e)
188+
catch (Exception ex)
198189
{
199-
Log.Debug(e, "Failed to get signature for {0} ({1}:{2})", Path, e.GetType(), e.Message);
190+
Log.Debug(ex, "Failed to get signature for {0} ({1}:{2})", Path, ex.GetType(), ex.Message);
200191
}
201192
}
202193
catch (Exception e)
@@ -206,6 +197,11 @@ private static List<DLLCHARACTERISTICS> CharacteristicsTypeToListOfCharacteristi
206197
return null;
207198
}
208199

200+
/// <summary>
201+
/// Try to determine if the file is locally present to avoid triggering a downloading files that are cloud stubs
202+
/// </summary>
203+
/// <param name="path">Path to check</param>
204+
/// <returns>True when the file appears to be local based on its attributes</returns>
209205
public static bool IsLocal(string path)
210206
{
211207
NativeMethods.WIN32_FILE_ATTRIBUTE_DATA fileData;

0 commit comments

Comments
 (0)