Skip to content

Commit

Permalink
[CI Visibility] Fix MakeRelativePathFromSourceRoot method when the pa…
Browse files Browse the repository at this point in the history
…th is invalid. (#5189)
  • Loading branch information
tonyredondo authored Feb 14, 2024
1 parent 9e31875 commit c1279de
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions tracer/src/Datadog.Trace/Ci/CIEnvironmentValues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,22 +288,31 @@ public string MakeRelativePathFromSourceRoot(string absolutePath, bool useOSSepa
return pivotFolder;
}

var folderSeparator = Path.DirectorySeparatorChar;
if (pivotFolder[pivotFolder.Length - 1] != folderSeparator)
try
{
pivotFolder += folderSeparator;
}
var folderSeparator = Path.DirectorySeparatorChar;
if (pivotFolder[pivotFolder.Length - 1] != folderSeparator)
{
pivotFolder += folderSeparator;
}

var pivotFolderUri = new Uri(pivotFolder);
var absolutePathUri = new Uri(absolutePath);
var relativeUri = pivotFolderUri.MakeRelativeUri(absolutePathUri);
if (useOSSeparator)
var pivotFolderUri = new Uri(pivotFolder);
var absolutePathUri = new Uri(absolutePath);
var relativeUri = pivotFolderUri.MakeRelativeUri(absolutePathUri);
if (useOSSeparator)
{
return Uri.UnescapeDataString(
relativeUri.ToString().Replace('/', folderSeparator));
}

return Uri.UnescapeDataString(relativeUri.ToString());
}
catch (Exception ex)
{
return Uri.UnescapeDataString(
relativeUri.ToString().Replace('/', folderSeparator));
Log.Warning(ex, "Error creating a relative path for '{AbsolutePath}' from '{BasePath}'", absolutePath, pivotFolder);
}

return Uri.UnescapeDataString(relativeUri.ToString());
return absolutePath;
}

internal void ReloadEnvironmentData()
Expand Down

0 comments on commit c1279de

Please sign in to comment.