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

Commit 36c0113

Browse files
author
William Li
committed
Separate tool package and shim file location
1 parent 839eccb commit 36c0113

File tree

6 files changed

+57
-11
lines changed

6 files changed

+57
-11
lines changed

src/Microsoft.DotNet.Configurer/CliFolderPathCalculator.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ namespace Microsoft.DotNet.Configurer
1212
{
1313
public class CliFolderPathCalculator
1414
{
15-
private const string ToolsFolderName = "tools";
15+
// ToolsShimFolderName ToolPackageFolderName cannot be the same
16+
// or if the PackageId is the same as CommandName, they will conflict on unix.
17+
private const string ToolsShimFolderName = "tools";
18+
private const string ToolPackageFolderName = "toolspkgs";
1619
private const string DotnetProfileDirectoryName = ".dotnet";
1720

1821
public string CliFallbackFolderPath => Environment.GetEnvironmentVariable("DOTNET_CLI_TEST_FALLBACKFOLDER") ??
1922
Path.Combine(new DirectoryInfo(AppContext.BaseDirectory).Parent.FullName, "NuGetFallbackFolder");
2023

21-
public string ExecutablePackagesPath => Path.Combine(DotnetUserProfileFolderPath, ToolsFolderName);
22-
23-
public BashPathUnderHomeDirectory ExecutablePackagesPathInUnix
24+
public string ToolsShimPath => Path.Combine(DotnetUserProfileFolderPath, ToolsShimFolderName);
25+
public string ToolsPackagePath => Path.Combine(DotnetUserProfileFolderPath, ToolPackageFolderName);
26+
public BashPathUnderHomeDirectory ToolsShimPathInUnix
2427
{
2528
get
2629
{
2730
return new BashPathUnderHomeDirectory(Environment.GetEnvironmentVariable("HOME"),
28-
Path.Combine(DotnetProfileDirectoryName, ToolsFolderName));
31+
Path.Combine(DotnetProfileDirectoryName, ToolsShimFolderName));
2932
}
3033
}
3134

src/dotnet/ShellShim/EnvironmentPathFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,20 @@ public static IEnvironmentPath CreateEnvironmentPath(
3232
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3333
{
3434
environmentPath = new WindowsEnvironmentPath(
35-
cliFolderPathCalculator.ExecutablePackagesPath,
35+
cliFolderPathCalculator.ToolsShimPath,
3636
Reporter.Output);
3737
}
3838
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && hasSuperUserAccess)
3939
{
4040
environmentPath = new LinuxEnvironmentPath(
41-
cliFolderPathCalculator.ExecutablePackagesPathInUnix,
41+
cliFolderPathCalculator.ToolsShimPathInUnix,
4242
Reporter.Output,
4343
environmentProvider, new FileWrapper());
4444
}
4545
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX) && hasSuperUserAccess)
4646
{
4747
environmentPath = new OSXEnvironmentPath(
48-
executablePath: cliFolderPathCalculator.ExecutablePackagesPathInUnix,
48+
executablePath: cliFolderPathCalculator.ToolsShimPathInUnix,
4949
reporter: Reporter.Output,
5050
environmentProvider: environmentProvider,
5151
fileSystem: new FileWrapper());

src/dotnet/ShellShim/ShellShimMaker.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public void CreateShim(string packageExecutablePath, string shellCommandName)
3030
{
3131
FilePath shimPath = GetShimPath(shellCommandName);
3232

33+
if (!Directory.Exists(shimPath.GetDirectoryPath().Value))
34+
{
35+
Directory.CreateDirectory(shimPath.GetDirectoryPath().Value);
36+
}
37+
3338
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
3439
{
3540
CreateConfigFile(shimPath.Value + ".config", entryPoint: packageExecutablePath, runner: "dotnet");

src/dotnet/commands/dotnet-install/dotnet-install-tool/InstallToolCommand.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ public override int Execute()
4949
}
5050

5151
var cliFolderPathCalculator = new CliFolderPathCalculator();
52-
var executablePackagePath = new DirectoryPath(cliFolderPathCalculator.ExecutablePackagesPath);
5352
var offlineFeedPath = new DirectoryPath(cliFolderPathCalculator.CliFallbackFolderPath);
5453

55-
var toolConfigurationAndExecutablePath = ObtainPackage(executablePackagePath, offlineFeedPath);
54+
var toolConfigurationAndExecutablePath = ObtainPackage(
55+
executablePackagePath: new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath),
56+
offlineFeedPath: offlineFeedPath);
5657

57-
var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
58+
var shellShimMaker = new ShellShimMaker(cliFolderPathCalculator.ToolsShimPath);
5859
var commandName = toolConfigurationAndExecutablePath.Configuration.CommandName;
5960
shellShimMaker.EnsureCommandNameUniqueness(commandName);
6061

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.DotNet.Cli.Utils;
7+
using Microsoft.DotNet.Tools.Test.Utilities;
8+
using FluentAssertions;
9+
10+
namespace Microsoft.DotNet.Configurer.UnitTests
11+
{
12+
public class GivenAPathCalculator
13+
{
14+
[NonWindowsOnlyFact]
15+
public void It_does_not_return_same_path_for_tools_package_and_tool_shim()
16+
{
17+
// shim name will conflict with the folder that is PackageId, if commandName and packageId are the same.
18+
var cliFolderPathCalculator = new CliFolderPathCalculator();
19+
cliFolderPathCalculator.ToolsPackagePath.Should().NotBe(cliFolderPathCalculator.ToolsShimPath);
20+
cliFolderPathCalculator.ToolsPackagePath.Should().NotBe(cliFolderPathCalculator.ToolsShimPathInUnix.Path);
21+
}
22+
}
23+
}

test/Microsoft.DotNet.ShellShim.Tests/ShellShimMakerTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ public void GivenAnExecutablePathItCanGenerateShimFile()
6868
stdOut.Should().Contain("Hello World");
6969
}
7070

71+
[Fact]
72+
public void GivenAnExecutablePathDirectoryThatDoesNotExistItCanGenerateShimFile()
73+
{
74+
var outputDll = MakeHelloWorldExecutableDll();
75+
var extraNonExistDirectory = Path.GetRandomFileName();
76+
var shellShimMaker = new ShellShimMaker(Path.Combine(TempRoot.Root, extraNonExistDirectory));
77+
var shellCommandName = nameof(ShellShimMakerTests) + Path.GetRandomFileName();
78+
79+
Action a = () => shellShimMaker.CreateShim(
80+
outputDll.FullName,
81+
shellCommandName);
82+
a.ShouldNotThrow<DirectoryNotFoundException>();
83+
}
84+
7185
[Theory]
7286
[InlineData("arg1 arg2", new[] { "arg1", "arg2" })]
7387
[InlineData(" \"arg1 with space\" arg2", new[] { "arg1 with space", "arg2" })]

0 commit comments

Comments
 (0)