Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/System.Management.Automation/CoreCLR/CorePsPlatform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public static class Platform
{
private static string _tempDirectory = null;

#if UNIX
// Cache the path so that GetTemporaryDirectory() does not create
// a temp directory for every new runspace if HOME environment variable is not present or empty.
private static string s_envHome =
System.Environment.GetEnvironmentVariable(CommonEnvVariableNames.Home) ?? GetTemporaryDirectory();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we cache HOME, then why not cache other values read from environment variables like XDG_CONFIG_HOME? Also we don't cache the "MyDocument" path on Windows. I think just caching a temp directory path on the first use would be sufficient.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it is not on hot path, I do not think we get a win.

Do we continue your PR or the PR? :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My PR already did that and it's only 2 lines change 😄 How about just close this PR?

#endif

/// <summary>
/// True if the current platform is Linux.
/// </summary>
Expand Down Expand Up @@ -249,16 +256,11 @@ public static string SelectProductNameForDirectory(Platform.XDG_Type dirpath)
string xdgconfighome = System.Environment.GetEnvironmentVariable("XDG_CONFIG_HOME");
string xdgdatahome = System.Environment.GetEnvironmentVariable("XDG_DATA_HOME");
string xdgcachehome = System.Environment.GetEnvironmentVariable("XDG_CACHE_HOME");
string envHome = System.Environment.GetEnvironmentVariable(CommonEnvVariableNames.Home);
if (envHome == null)
{
envHome = GetTemporaryDirectory();
}

string xdgConfigHomeDefault = Path.Combine(envHome, ".config", "powershell");
string xdgDataHomeDefault = Path.Combine(envHome, ".local", "share", "powershell");
string xdgConfigHomeDefault = Path.Combine(s_envHome, ".config", "powershell");
string xdgDataHomeDefault = Path.Combine(s_envHome, ".local", "share", "powershell");
string xdgModuleDefault = Path.Combine(xdgDataHomeDefault, "Modules");
string xdgCacheDefault = Path.Combine(envHome, ".cache", "powershell");
string xdgCacheDefault = Path.Combine(s_envHome, ".cache", "powershell");

switch (dirpath)
{
Expand Down Expand Up @@ -410,12 +412,6 @@ private static string InternalGetFolderPath(System.Environment.SpecialFolder fol
{
string folderPath = null;
#if UNIX
string envHome = System.Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home);
if (envHome == null)
{
envHome = Platform.GetTemporaryDirectory();
}

switch (folder)
{
case System.Environment.SpecialFolder.ProgramFiles:
Expand All @@ -435,10 +431,10 @@ private static string InternalGetFolderPath(System.Environment.SpecialFolder fol

break;
case System.Environment.SpecialFolder.Personal:
folderPath = envHome;
folderPath = s_envHome;
break;
case System.Environment.SpecialFolder.LocalApplicationData:
folderPath = System.IO.Path.Combine(envHome, ".config");
folderPath = System.IO.Path.Combine(s_envHome, ".config");
if (!System.IO.Directory.Exists(folderPath))
{
try
Expand Down