Skip to content

Commit

Permalink
SlnHierarchy: Properly handle directory separator. (#65)
Browse files Browse the repository at this point in the history
Each iteration over a path segment added path separator before and after,
yielding doubled path separator and tricking the hierarchy resolution into
believing that all folders up to the drive letter are part of the solution.

The logic in GetRootFolder is fixed, and the test updated so that this case is
properly detected.
  • Loading branch information
afabre authored and jeffkl committed Jul 7, 2019
1 parent a0638c9 commit a99e0f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions src/SlnGen.Build.Tasks.UnitTests/SlnHierarchyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ public void HierarchyIsCorrectlyFormed()

List<SlnProject> projects = new List<SlnProject>
{
new SlnProject(@"D:\foo\bar\baz\baz.csproj", "baz", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\foo\bar\baz1\baz1.csproj", "baz1", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\foo\bar\baz2\baz2.csproj", "baz2", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\foo\bar1\bar1.csproj", "bar1", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\zoo\foo\bar\baz\baz.csproj", "baz", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\zoo\foo\bar\baz1\baz1.csproj", "baz1", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\zoo\foo\bar\baz2\baz2.csproj", "baz2", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
new SlnProject(@"D:\zoo\foo\bar1\bar1.csproj", "bar1", Guid.NewGuid(), SlnProject.DefaultLegacyProjectTypeGuid, configurations, platforms, false, isDeployable: false),
};

SlnHierarchy hierarchy = new SlnHierarchy(projects);

hierarchy.Folders.Select(i => i.FullPath)
.ShouldBe(new[]
{
@"D:\foo\bar\baz",
@"D:\foo\bar\baz1",
@"D:\foo\bar\baz2",
@"D:\foo\bar",
@"D:\foo\bar1",
@"D:\foo",
@"D:\zoo\foo\bar\baz",
@"D:\zoo\foo\bar\baz1",
@"D:\zoo\foo\bar\baz2",
@"D:\zoo\foo\bar",
@"D:\zoo\foo\bar1",
@"D:\zoo\foo",
});

foreach (SlnProject project in projects)
Expand Down
4 changes: 2 additions & 2 deletions src/SlnGen.Build.Tasks/Internal/SlnHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ private static SlnFolder GetRootFolder(IEnumerable<SlnProject> projects)
{
if (commonPath.Length == 0 && paths.All(str => str.StartsWith(pathSegment)))
{
commonPath = pathSegment;
commonPath = pathSegment + Path.DirectorySeparatorChar;
}
else if (paths.All(str => str.StartsWith(nextPath = $"{commonPath}{Path.DirectorySeparatorChar}{pathSegment}{Path.DirectorySeparatorChar}")))
else if (paths.All(str => str.StartsWith(nextPath = $"{commonPath}{pathSegment}{Path.DirectorySeparatorChar}")))
{
commonPath = nextPath;
}
Expand Down

0 comments on commit a99e0f5

Please sign in to comment.