Skip to content

Commit 954142d

Browse files
authored
Fix home calculation Fixes #46821 (#46836)
Fixes #46821 #46349 was part of a set of changes to support containers that don't have HOME set to anything. Unfortunately, DOTNET_CLI_HOME (which is what we use instead) may not be set to things in other environments, notably with a zip install. Since Path.Combine is used, this led to a null pointer exception. This changes it to skip copying the nuget.config if DOTNET_CLI_HOME is not defined to avoid an error. It's fine to not error in that case since it's best effort anyway.
1 parent bd27620 commit 954142d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Cli/dotnet/SudoEnvironmentDirectoryOverride.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ public static void OverrideEnvironmentVariableToTmp(ParseResult parseResult)
3333
if (!OperatingSystem.IsWindows() && IsRunningUnderSudo() && IsRunningWorkloadCommand(parseResult))
3434
{
3535
string sudoHome = PathUtilities.CreateTempSubdirectory();
36-
var homeBeforeOverride = Path.Combine(Environment.GetEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName));
36+
var homeBeforeOverride = Environment.GetEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName);
3737
Environment.SetEnvironmentVariable(CliFolderPathCalculator.DotnetHomeVariableName, sudoHome);
3838

39-
CopyUserNuGetConfigToOverriddenHome(homeBeforeOverride);
39+
if (homeBeforeOverride is not null)
40+
{
41+
CopyUserNuGetConfigToOverriddenHome(homeBeforeOverride);
42+
}
4043
}
4144
}
4245

4346
/// <summary>
4447
/// To make NuGet honor the user's NuGet config file.
45-
/// Copying instead of using the file directoy to avoid existing file being set higher permission
48+
/// Copying instead of using the file directly to avoid existing file being set higher permission
4649
/// Try to delete the existing NuGet config file in "/tmp/dotnet_sudo_home/"
4750
/// to avoid different user's NuGet config getting mixed.
4851
/// </summary>

0 commit comments

Comments
 (0)