Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit d3244e8

Browse files
author
Peter Huene
committed
Ensure tool package store root is a full path.
This commit fixes the tool package store such that it stores a full path instead of, potentially, a relative path. This prevents a relative path from inadvertently being passed to NuGet during the restore and causing it to restore relative to the temp project directory. Fixes #8829.
1 parent 04ba0c9 commit d3244e8

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

src/dotnet/ToolPackage/ToolPackageStore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal class ToolPackageStore : IToolPackageStore
1414

1515
public ToolPackageStore(DirectoryPath root)
1616
{
17-
Root = root;
17+
Root = new DirectoryPath(Path.GetFullPath(root.Value));
1818
}
1919

2020
public DirectoryPath Root { get; private set; }

test/Microsoft.DotNet.ToolPackage.Tests/ToolPackageInstallerTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ private static (IToolPackageStore, IToolPackageInstaller, BufferedReporter, IFil
637637
FilePath? tempProject = null,
638638
DirectoryPath? offlineFeed = null)
639639
{
640-
var root = new DirectoryPath(Path.Combine(Path.GetFullPath(TempRoot.Root), Path.GetRandomFileName()));
640+
var root = new DirectoryPath(Path.Combine(TempRoot.Root, Path.GetRandomFileName()));
641641
var reporter = new BufferedReporter();
642642

643643
IFileSystem fileSystem;
@@ -666,6 +666,8 @@ private static (IToolPackageStore, IToolPackageInstaller, BufferedReporter, IFil
666666
offlineFeed: offlineFeed ?? new DirectoryPath("does not exist"));
667667
}
668668

669+
store.Root.Value.Should().Be(Path.GetFullPath(root.Value));
670+
669671
return (store, installer, reporter, fileSystem);
670672
}
671673

test/Microsoft.DotNet.Tools.Tests.ComponentMocks/ToolPackageStoreMock.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public ToolPackageStoreMock(
2222
IFileSystem fileSystem,
2323
Action uninstallCallback = null)
2424
{
25-
Root = root;
25+
Root = new DirectoryPath(Path.GetFullPath(root.Value));
2626
_fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
2727
_uninstallCallback = uninstallCallback;
2828
}

test/dotnet.Tests/CommandTests/UninstallToolCommandTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ public void GivenAPackageItUninstalls()
7373
PackageId,
7474
PackageVersion));
7575

76-
var packageDirectory = new DirectoryPath(ToolsDirectory).WithSubDirectories(PackageId, PackageVersion);
76+
var packageDirectory = new DirectoryPath(Path.GetFullPath(ToolsDirectory))
77+
.WithSubDirectories(PackageId, PackageVersion);
7778
var shimPath = Path.Combine(
7879
ShimsDirectory,
7980
ProjectRestorerMock.FakeCommandName +
@@ -114,7 +115,8 @@ public void GivenAFailureToUninstallItLeavesItInstalled()
114115
PackageId,
115116
PackageVersion));
116117

117-
var packageDirectory = new DirectoryPath(ToolsDirectory).WithSubDirectories(PackageId, PackageVersion);
118+
var packageDirectory = new DirectoryPath(Path.GetFullPath(ToolsDirectory))
119+
.WithSubDirectories(PackageId, PackageVersion);
118120
var shimPath = Path.Combine(
119121
ShimsDirectory,
120122
ProjectRestorerMock.FakeCommandName +

0 commit comments

Comments
 (0)