Fix checks for local user config file paths#26269
Conversation
- Use the `DoNotVerify` option with `Environment.GetFolderPath`, ensuring the configured location will be returned regardless of if it has been created already - If we get an empty string, null or whitespace from `GetFolderPath`, consider that as disabled and skip loading or processing further for that location.
There was a problem hiding this comment.
Pull Request Overview
This PR fixes user config handling by ensuring PowerShell uses DoNotVerify option when retrieving special folder paths, preventing failures when directories don't exist yet. The main changes ensure that if a special folder path is empty or null, config loading is skipped for that location rather than failing.
Key Changes:
- Added
DoNotVerifyoption toEnvironment.GetFolderPathcalls to return configured paths regardless of directory existence - Added null/empty checks to skip processing when special folder paths are unavailable
- Introduced helper methods
SafeDeriveFromSpecialFolderandTryDeriveFromCacheto safely derive paths from special folders
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| CorePsPlatform.cs | Added helper methods for safe path derivation and updated cache/config directory initialization to use DoNotVerify |
| PSConfiguration.cs | Added null check before using per-user config file path |
| Telemetry.cs | Updated to use cached UUID path and skip telemetry if path unavailable; moved environment variable parsing to private method |
| AnalysisCache.cs | Updated to use TryDeriveFromCache and skip serialization if cache location unavailable |
| UpdatesNotification.cs | Updated to use TryDeriveFromCache and disable notifications if cache unavailable |
| ConsoleHost.cs | Added null check before using profile directory |
| CommandDiscovery.cs | Updated user profile path retrieval to use DoNotVerify option |
| MshHostUserInterface.cs | Added null/empty check for base directory in transcript path generation |
| HostUtilities.cs | Fixed brace placement in conditional logic |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
📣 Hey @@SeeminglyScience, how did we do? We would love to hear your feedback with the link below! 🗣️ 🔗 https://aka.ms/PSRepoFeedback |
PR Summary
With these changes,
SYSTEM's default config path isC:\Windows\system32\config\systemprofile\Documents\PowerShell\powershell.config.jsonregardless of if the directoryDocumentsexists.If the location for
Documentsis configured in the OS to be an empty string (if that's even possible), user based config loading will be skipped entirely.PR Context
DoNotVerifyoption withEnvironment.GetFolderPath, ensuring the configured location will be returned regardless of if it has been created alreadyGetFolderPath, consider that as disabled and skip loading or processing further for that location.PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright header