Skip to content

Fix #696 #698

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions Lib/Collectors/WindowsFileSystemUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,19 @@ public static List<DLLCHARACTERISTICS> GetDllCharacteristics(string Path)
}
// This can happen if the file is readable but not writable as MMFile tries to open the file with write privileges.
// 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
// See #684
catch (UnauthorizedAccessException)
// See #684 + #696
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
{
try
{
using var stream = File.OpenRead(Path);
return GetDllCharacteristics(Path, stream);
}
catch (Exception e)
catch (Exception ex)
{
Log.Debug(e, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
Log.Debug(ex, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, ex.GetType(), ex.Message);
}
}
catch (Exception e) when (
e is IndexOutOfRangeException
|| e is ArgumentNullException
|| e is System.IO.IOException
|| e is ArgumentException
|| e is NullReferenceException)
{
Log.Debug("Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
}
catch (Exception e)
{
Log.Debug(e, "Failed to get DLL Characteristics for {0} ({1}:{2})", Path, e.GetType(), e.Message);
Expand Down Expand Up @@ -185,18 +176,18 @@ private static List<DLLCHARACTERISTICS> CharacteristicsTypeToListOfCharacteristi
}
}
// This can happen if the file is readable but not writable as MMFile tries to open the file with write privileges.
// 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
// See #684
catch (UnauthorizedAccessException)
// 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
// See #684 + #696
catch (Exception e) when (e is UnauthorizedAccessException or IOException)
{
try
{
using var stream = File.OpenRead(Path);
return GetSignatureStatus(Path, stream);
}
catch (Exception e)
catch (Exception ex)
{
Log.Debug(e, "Failed to get signature for {0} ({1}:{2})", Path, e.GetType(), e.Message);
Log.Debug(ex, "Failed to get signature for {0} ({1}:{2})", Path, ex.GetType(), ex.Message);
}
}
catch (Exception e)
Expand All @@ -206,6 +197,11 @@ private static List<DLLCHARACTERISTICS> CharacteristicsTypeToListOfCharacteristi
return null;
}

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