in Code_Sweep/C#/Scanner/Scanner.cs [130:184]
private static IScanResult ScanFile(string filePath, MatchFinder finder, FileContentGetter contentGetter, ScanStopper stopper)
{
if (filePath == null)
{
throw new ArgumentNullException("filePath");
}
// See if the content getter can give us the file contents. If so, we'll scan that
// string rather than loading the file from disk.
if (contentGetter != null)
{
string content = contentGetter(filePath);
if (content != null)
{
return ScanResult.ScanOccurred(filePath, GetScanHits(filePath, content, finder, stopper));
}
}
StreamReader reader = null;
try
{
try
{
reader = File.OpenText(filePath);
}
catch (Exception ex)
{
if (ex is UnauthorizedAccessException ||
ex is ArgumentException ||
ex is ArgumentNullException ||
ex is PathTooLongException ||
ex is DirectoryNotFoundException ||
ex is FileNotFoundException ||
ex is NotSupportedException ||
ex is IOException)
{
return ScanResult.ScanNotPossible(filePath);
}
else
{
throw;
}
}
return ScanResult.ScanOccurred(filePath, GetScanHits(filePath, reader, finder, stopper));
}
finally
{
if (reader != null)
{
reader.Close();
}
}
}