Skip to content

Use the same temp personal module path when env 'HOME' not defined - #13239

Merged
Rob Holt (rjmholt) merged 1 commit into
PowerShell:masterfrom
daxian-dbw:tempPath
Jul 23, 2020
Merged

Rob Holt (rjmholt) merged 1 commit into
PowerShell:masterfrom
daxian-dbw:tempPath

Conversation

@daxian-dbw

Copy link
Copy Markdown
Member

PR Summary

Fix #13189

When the env variable HOME is not defined, every Runspace startup on Unix platforms will try creating a folder in the form of /tmp/<new-guid>/.local/share/powershell/Modules as the personal user module path. That means LOTs of such folders get created when Foreach-Object -Parallel is dealing with a lot of inputs. In that situation, it may not be surprising to see strange failures like the DirectoryNotFoundException reported 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 HOME env variable is not defined.

PR Checklist

@rjmholt

Copy link
Copy Markdown
Collaborator

N/A or can only be tested interactively

I wonder if it's possible to test this by unsetting $env:HOME

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@rjmholt

Copy link
Copy Markdown
Collaborator

PoshChan-Bot (@PoshChan) please remind me in 23 hours

@rjmholt
Rob Holt (rjmholt) merged commit cfb1952 into PowerShell:master Jul 23, 2020
Comment on lines 254 to +258
string envHome = System.Environment.GetEnvironmentVariable(CommonEnvVariableNames.Home);
if (envHome == null)
{
envHome = GetTemporaryDirectory();
s_tempHomeDir ??= GetTemporaryDirectory();
envHome = s_tempHomeDir;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You assume that HOME could be defined on the fly (and preserve current behavior) but we could already put some files in previous folder :-(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the tempPath branch July 23, 2020 18:29
@PoshChan

Copy link
Copy Markdown
Collaborator

Rob Holt (@rjmholt), this is the reminder you requested 23 hours ago

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Jul 24, 2020
@iSazonov Ilya (iSazonov) added this to the 7.1.0-preview.7 milestone Jul 24, 2020
@iSazonov

Copy link
Copy Markdown
Collaborator

Will be this backported to 7.0?

@rjmholt

Copy link
Copy Markdown
Collaborator

Will be this backported to 7.0?

Paul Higinbotham (@PaulHigin) Dongbo Wang (@daxian-dbw)

@daxian-dbw Dongbo Wang (daxian-dbw) added the Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers label Jul 24, 2020
@daxian-dbw

Copy link
Copy Markdown
Member Author

Good question. Maybe it's worth backporting, given the fix is so simple.
Marked this PR maintainer - review

@TravisEz13 Travis Plunk (TravisEz13) added BackPort-7.0.x and removed Review - Maintainer The PR/issue needs a review from the PowerShell repo Maintainers BackPort-7.0.x labels Aug 4, 2020
@TravisEz13 Travis Plunk (TravisEz13) modified the milestones: 7.1.0-preview.7, 7.1.0-preview.6 Aug 5, 2020
@ghost

Copy link
Copy Markdown

🎉v7.1.0-preview.6 has been released which incorporates this pull request.:tada:

Handy links:

@ghost

Copy link
Copy Markdown

🎉v7.0.4 has been released which incorporates this pull request.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-7.0.x-Done 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

6 participants