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

Commit 0f0f70c

Browse files
author
Peter Huene
committed
Fix adding tools directory to PATH for native installers.
This commit fixes adding the tools directory to the user's PATH for the native installers. The issue was a regression caused by #8886. The change used a "no-op" sentinel file that reported it existed. This "no-op" sentinel was used for the native installers. Unlike the other "no-op" sentinels used by the native installer, we do want PATH to be modified by the native installer. The fix is to change the "no-op" sentinel to report the file doesn't exist, but also to not to attempt to create the file. This fixes #9208.
1 parent e7ebf48 commit 0f0f70c

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,16 @@ namespace Microsoft.DotNet.Configurer
77
{
88
public class NoOpFileSentinel : IFileSentinel
99
{
10+
private bool _exists;
11+
12+
public NoOpFileSentinel(bool exists)
13+
{
14+
_exists = exists;
15+
}
16+
1017
public bool Exists()
1118
{
12-
return true;
19+
return _exists;
1320
}
1421

1522
public void Create()

src/dotnet/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null
147147
{
148148
aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel();
149149
firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel();
150-
toolPathSentinel = new NoOpFileSentinel();
150+
toolPathSentinel = new NoOpFileSentinel(exists: false);
151151
hasSuperUserAccess = true;
152152
}
153153

test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Collections.Generic;
77
using Microsoft.DotNet.Cli.Utils;
88
using Microsoft.DotNet.Cli;
9+
using Microsoft.DotNet.Configurer;
910
using Microsoft.DotNet.TestFramework;
1011
using Microsoft.DotNet.Tools.Test.Utilities;
1112
using Xunit;
@@ -193,6 +194,49 @@ public void ItShowsTheAspNetCertificateGenerationMessageWhenInvokingACommandAfte
193194
.ContainVisuallySameFragment(Configurer.LocalizableStrings.AspNetCertificateInstalled);
194195
}
195196

197+
[LinuxOnlyFact]
198+
public void ItCreatesTheProfileFileOnLinuxWhenInvokedFromNativeInstaller()
199+
{
200+
var emptyHome = Path.Combine(_testDirectory, "empty_home");
201+
var profiled = Path.Combine(_testDirectory, "profile.d");
202+
203+
var command = new DotnetCommand().WithWorkingDirectory(_testDirectory);
204+
command.Environment["HOME"] = emptyHome;
205+
command.Environment["USERPROFILE"] = emptyHome;
206+
command.Environment["APPDATA"] = emptyHome;
207+
command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName;
208+
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
209+
command.Environment["DOTNET_CLI_TEST_LINUX_PROFILED_PATH"] = profiled;
210+
command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true";
211+
command.Environment["SkipInvalidConfigurations"] = "true";
212+
command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass();
213+
214+
File.Exists(profiled).Should().BeTrue();
215+
File.ReadAllText(profiled).Should().Be(
216+
$"export PATH=\"$PATH:{new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithDollar}\"");
217+
}
218+
219+
[MacOsOnlyFact]
220+
public void ItCreatesThePathDFileOnMacOSWhenInvokedFromNativeInstaller()
221+
{
222+
var emptyHome = Path.Combine(_testDirectory, "empty_home");
223+
var pathsd = Path.Combine(_testDirectory, "paths.d");
224+
225+
var command = new DotnetCommand().WithWorkingDirectory(_testDirectory);
226+
command.Environment["HOME"] = emptyHome;
227+
command.Environment["USERPROFILE"] = emptyHome;
228+
command.Environment["APPDATA"] = emptyHome;
229+
command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName;
230+
command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = "";
231+
command.Environment["DOTNET_CLI_TEST_OSX_PATHSD_PATH"] = pathsd;
232+
command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true";
233+
command.Environment["SkipInvalidConfigurations"] = "true";
234+
command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass();
235+
236+
File.Exists(pathsd).Should().BeTrue();
237+
File.ReadAllText(pathsd).Should().Be(new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithTilde);
238+
}
239+
196240
[Fact]
197241
public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder()
198242
{

0 commit comments

Comments
 (0)