[release/v7.4.16] Fix checks for local user config file paths#27454
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This backport updates PowerShell’s handling of user-local folder paths so configuration and cache-related features can tolerate special folders that are configured but not yet created, or unavailable.
Changes:
- Uses
Environment.SpecialFolderOption.DoNotVerifyfor Windows special-folder resolution. - Adds empty-path handling for config, cache, profile, transcript, telemetry, update notification, and analysis cache paths.
- Avoids some filesystem operations when derived user-local paths are unavailable.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/System.Management.Automation/CoreCLR/CorePsPlatform.cs |
Adds safer special-folder path derivation and cache path helpers. |
src/System.Management.Automation/engine/PSConfiguration.cs |
Skips per-user config reads when no config path is available. |
src/System.Management.Automation/engine/Modules/AnalysisCache.cs |
Avoids module analysis cache serialization when no cache path is available. |
src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs |
Handles unavailable transcript base paths. |
src/System.Management.Automation/engine/hostifaces/HostUtilities.cs |
Handles unavailable profile base paths for current/all users. |
src/System.Management.Automation/engine/CommandDiscovery.cs |
Resolves ~ paths using non-verifying special-folder lookup. |
src/System.Management.Automation/utils/Telemetry.cs |
Uses derived cache path for telemetry UUID storage and gates telemetry when unavailable. |
src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs |
Gates update notifications on derived cache path availability. |
src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs |
Skips profile optimization setup when the cache directory is unavailable. |
Comment on lines
+92
to
+95
| if (!string.IsNullOrEmpty(perUserConfigDirectory)) | ||
| { | ||
| perUserConfigFile = Path.Combine(perUserConfigDirectory, ConfigFileName); | ||
| } |
Comment on lines
+1159
to
+1162
| if (string.IsNullOrEmpty(baseDirectory)) | ||
| { | ||
| return string.Empty; | ||
| } |
SeeminglyScience
approved these changes
May 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #26269 to release/v7.4.16
Triggered by @adityapatwardhan on behalf of @SeeminglyScience
Original CL Label: CL-Engine
/cc @PowerShell/powershell-maintainers
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Customer Impact
Fixes an issue where configuration file loading could fail when the Documents directory location was not yet created. The fix ensures PowerShell can locate user config files even when their parent directories don't exist yet.
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Original PR testing included verification that SYSTEM's default config path is properly resolved regardless of whether the Documents directory exists. Uses DoNotVerify option with Environment.GetFolderPath to ensure configured location is returned.
Risk
REQUIRED: Check exactly one box.
This is a targeted fix for config path resolution that improves robustness by ensuring paths are returned regardless of directory existence. The changes are localized to config file path validation logic with no impact to core functionality.