-
Notifications
You must be signed in to change notification settings - Fork 8.3k
PowerShell doesn't start if env var HOME is not defined #3437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -604,6 +604,30 @@ internal static bool IsRunningOnProcessorArchitectureARM() | |
| #endif | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Get a temporary directory to use, needs to be unique to avoid collision | ||
| /// </summary> | ||
| internal static string GetTemporaryDirectory() | ||
| { | ||
| string tempDir = String.Empty; | ||
| string tempPath = Path.GetTempPath(); | ||
| do | ||
| { | ||
| tempDir = Path.Combine(tempPath,System.Guid.NewGuid().ToString()); | ||
| } | ||
| while (Directory.Exists(tempDir)); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe remove the cycle? If we believe that it cannot be infinite that means we believe that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the risk of an infinite loop is slightly lower than the risk of NewGuid() not being unique although realistically, I expect both to be practically not a real issue but having the loop seems very slightly safer.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Closed. |
||
|
|
||
| try | ||
| { | ||
| Directory.CreateDirectory(tempDir); | ||
| } | ||
| catch (UnauthorizedAccessException) | ||
| { | ||
| tempDir = String.Empty; // will become current working directory | ||
| } | ||
| return tempDir; | ||
| } | ||
|
|
||
| internal static string GetHostName() | ||
| { | ||
| // Note: non-windows CoreCLR does not support System.Net yet | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming this scenario is common (no HOME), we'll eventually create a ton of these directories.
I think we should either:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know how common this will be, but cleaning up makes sense. Putting it in ConsoleHost.Dispose()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is a common scenario, then perhaps we should require to specify a temporary directory using one of the possible ways?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iSazonov although not discoverable, for advanced uses you can define XDG_CONFIG_HOME, XDG_CACHE_HOME, and XDG_DATA_HOME env vars which PowerShell will use (on non-Windows). This was really only to support simple cases (like Puppet) to not put a barrier for adoption of PowerShell
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that maybe we need to specify in the documentation that for proper PowerShell operation, users need to define (enumeration here) variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created doc bug MicrosoftDocs/PowerShell-Docs#1126
I don't think users should be required to create those env vars, we should just work in most cases