Use the same temp personal module path when env 'HOME' not defined#13239
Conversation
I wonder if it's possible to test this by unsetting |
PaulHigin
left a comment
There was a problem hiding this comment.
Thanks for fixing this! I don't think we need tests for this change, and as long as current tests pass I feel we are good.
|
@PoshChan please remind me in 23 hours |
| string envHome = System.Environment.GetEnvironmentVariable(CommonEnvVariableNames.Home); | ||
| if (envHome == null) | ||
| { | ||
| envHome = GetTemporaryDirectory(); | ||
| s_tempHomeDir ??= GetTemporaryDirectory(); | ||
| envHome = s_tempHomeDir; |
There was a problem hiding this comment.
You assume that HOME could be defined on the fly (and preserve current behavior) but we could already put some files in previous folder :-(
There was a problem hiding this comment.
Sorry that I missed this comment. I think it would be very unlikely that the HOME env var changes it value after it's declared, so I'm not too worry about this.
|
@rjmholt, this is the reminder you requested 23 hours ago |
|
Will be this backported to 7.0? |
|
|
Good question. Maybe it's worth backporting, given the fix is so simple. |
|
🎉 Handy links: |
|
🎉 Handy links: |
PR Summary
Fix #13189
When the env variable
HOMEis not defined, every Runspace startup on Unix platforms will try creating a folder in the form of/tmp/<new-guid>/.local/share/powershell/Modulesas the personal user module path. That means LOTs of such folders get created whenForeach-Object -Parallelis dealing with a lot of inputs. In that situation, it may not be surprising to see strange failures like theDirectoryNotFoundExceptionreported in the issue.This PR adds a static field to cache the temporary personal user module path, so all Runspace's will use the same temp directory path in case
HOMEenv variable is not defined.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.