From 0f0f70ce48939945baec78cba0bbcff848b4a188 Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Mon, 7 May 2018 16:35:29 -0700 Subject: [PATCH] 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. --- .../NoOpFileSentinel.cs | 9 +++- src/dotnet/Program.cs | 2 +- ...atTheUserIsRunningDotNetForTheFirstTime.cs | 44 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs b/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs index e77097011..80e3d0831 100644 --- a/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs +++ b/src/Microsoft.DotNet.Configurer/NoOpFileSentinel.cs @@ -7,9 +7,16 @@ namespace Microsoft.DotNet.Configurer { public class NoOpFileSentinel : IFileSentinel { + private bool _exists; + + public NoOpFileSentinel(bool exists) + { + _exists = exists; + } + public bool Exists() { - return true; + return _exists; } public void Create() diff --git a/src/dotnet/Program.cs b/src/dotnet/Program.cs index 6ae1409ce..ce08bcb56 100644 --- a/src/dotnet/Program.cs +++ b/src/dotnet/Program.cs @@ -147,7 +147,7 @@ namespace Microsoft.DotNet.Cli { aspNetCertificateSentinel = new NoOpAspNetCertificateSentinel(); firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel(); - toolPathSentinel = new NoOpFileSentinel(); + toolPathSentinel = new NoOpFileSentinel(exists: false); hasSuperUserAccess = true; } diff --git a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index bccc3c053..b554d528e 100644 --- a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs +++ b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -6,6 +6,7 @@ using System.IO; using System.Collections.Generic; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli; +using Microsoft.DotNet.Configurer; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; @@ -193,6 +194,49 @@ namespace Microsoft.DotNet.Tests .ContainVisuallySameFragment(Configurer.LocalizableStrings.AspNetCertificateInstalled); } + [LinuxOnlyFact] + public void ItCreatesTheProfileFileOnLinuxWhenInvokedFromNativeInstaller() + { + var emptyHome = Path.Combine(_testDirectory, "empty_home"); + var profiled = Path.Combine(_testDirectory, "profile.d"); + + var command = new DotnetCommand().WithWorkingDirectory(_testDirectory); + command.Environment["HOME"] = emptyHome; + command.Environment["USERPROFILE"] = emptyHome; + command.Environment["APPDATA"] = emptyHome; + command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName; + command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; + command.Environment["DOTNET_CLI_TEST_LINUX_PROFILED_PATH"] = profiled; + command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true"; + command.Environment["SkipInvalidConfigurations"] = "true"; + command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass(); + + File.Exists(profiled).Should().BeTrue(); + File.ReadAllText(profiled).Should().Be( + $"export PATH=\"$PATH:{new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithDollar}\""); + } + + [MacOsOnlyFact] + public void ItCreatesThePathDFileOnMacOSWhenInvokedFromNativeInstaller() + { + var emptyHome = Path.Combine(_testDirectory, "empty_home"); + var pathsd = Path.Combine(_testDirectory, "paths.d"); + + var command = new DotnetCommand().WithWorkingDirectory(_testDirectory); + command.Environment["HOME"] = emptyHome; + command.Environment["USERPROFILE"] = emptyHome; + command.Environment["APPDATA"] = emptyHome; + command.Environment["DOTNET_CLI_TEST_FALLBACKFOLDER"] = _nugetFallbackFolder.FullName; + command.Environment["DOTNET_SKIP_FIRST_TIME_EXPERIENCE"] = ""; + command.Environment["DOTNET_CLI_TEST_OSX_PATHSD_PATH"] = pathsd; + command.Environment["DOTNET_DISABLE_MULTICOREJIT"] = "true"; + command.Environment["SkipInvalidConfigurations"] = "true"; + command.ExecuteWithCapturedOutput("internal-reportinstallsuccess test").Should().Pass(); + + File.Exists(pathsd).Should().BeTrue(); + File.ReadAllText(pathsd).Should().Be(new CliFolderPathCalculator().ToolsShimPathInUnix.PathWithTilde); + } + [Fact] public void ItRestoresTheNuGetPackagesToTheNuGetCacheFolder() {