Skip to content

Does not re-evaluate home dir path#13218

Closed
iSazonov wants to merge 2 commits into
PowerShell:masterfrom
iSazonov:fix-homedir-temp
Closed

Does not re-evaluate home dir path#13218
iSazonov wants to merge 2 commits into
PowerShell:masterfrom
iSazonov:fix-homedir-temp

Conversation

@iSazonov
Copy link
Copy Markdown
Collaborator

@iSazonov iSazonov commented Jul 20, 2020

PR Summary

Fix #13189.

Internally cache a home directory path on Unix so that does not re-valuate the value and does not re-create temporary home directory every time if HOME environment variable is empty or absent.

(No tests was added because it is an edge case and we need a test hook for reliable test.)

PR Context

PR Checklist

@iSazonov iSazonov added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 20, 2020
@daxian-dbw
Copy link
Copy Markdown
Member

Sorry that I didn't notice this PR before submitting #13239 😦

// 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?

@iSazonov iSazonov closed this Jul 23, 2020
@iSazonov iSazonov deleted the fix-homedir-temp branch July 23, 2020 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.IO.DirectoryNotFoundException using -Parallel feature and Microsoft.PowerShell.SDK

2 participants