in src/Sarif.Viewer.VisualStudio.Core/CodeAnalysisResultManager.cs [198:283]
public bool TryResolveFilePath(int resultId, int runIndex, string uriBaseId, string relativePath, out string resolvedPath)
{
resolvedPath = null;
if (!SarifViewerPackage.IsUnitTesting)
{
#pragma warning disable VSTHRD108 // Assert thread affinity unconditionally
ThreadHelper.ThrowIfNotOnUIThread();
#pragma warning restore VSTHRD108
}
if (!this.RunIndexToRunDataCache.TryGetValue(runIndex, out RunDataCache dataCache))
{
return false;
}
SarifErrorListItem sarifErrorListItem = dataCache.SarifErrors.FirstOrDefault(sarifResult => sarifResult.ResultId == resultId);
if (sarifErrorListItem == null)
{
return false;
}
string solutionPath = GetSolutionPath(
(DTE2)Package.GetGlobalService(typeof(DTE)),
((IComponentModel)Package.GetGlobalService(typeof(SComponentModel))).GetService<IVsFolderWorkspaceService>());
// File contents embedded in SARIF.
bool hasHash = dataCache.FileDetails.TryGetValue(relativePath, out ArtifactDetailsModel model) && !string.IsNullOrEmpty(model?.Sha256Hash);
string embeddedTempFilePath = this.CreateFileFromContents(dataCache.FileDetails, relativePath);
try
{
resolvedPath = this.GetFilePathFromHttp(sarifErrorListItem, uriBaseId, dataCache, relativePath);
}
catch (WebException)
{
// failed to download the file
return false;
}
if (string.IsNullOrEmpty(resolvedPath))
{
// resolve path, existing file in local disk
resolvedPath = this.GetRebaselinedFileName(
uriBaseId: uriBaseId,
pathFromLogFile: relativePath,
dataCache: dataCache,
workingDirectory: sarifErrorListItem.WorkingDirectory,
solutionFullPath: solutionPath);
}
// verify resolved file with artifact's Hash
if (hasHash)
{
string currentResolvedPath = resolvedPath;
if (!this.VerifyFileWithArtifactHash(sarifErrorListItem, relativePath, dataCache, currentResolvedPath, embeddedTempFilePath, out resolvedPath))
{
return false;
}
}
if (string.IsNullOrEmpty(resolvedPath))
{
// User needs to locate file.
resolvedPath = this._promptForResolvedPathDelegate(sarifErrorListItem, relativePath);
}
if (!string.IsNullOrEmpty(resolvedPath))
{
// save resolved path to mapping
if (!this.SaveResolvedPathToUriBaseMapping(uriBaseId, relativePath, relativePath, resolvedPath, dataCache))
{
resolvedPath = relativePath;
}
}
if (string.IsNullOrEmpty(resolvedPath) || relativePath.Equals(resolvedPath, StringComparison.OrdinalIgnoreCase))
{
resolvedPath = relativePath;
return false;
}
// Update all the paths in this run.
this.RemapFilePaths(dataCache.SarifErrors, relativePath, resolvedPath);
return true;
}