[release/v7.5.7] Fix checks for local user config file paths#27479
Merged
adityapatwardhan merged 2 commits intoMay 19, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Backport to release/v7.5.7 of logic that makes user/config/cache path derivation more robust on Windows by using Environment.SpecialFolderOption.DoNotVerify and treating empty/whitespace folder paths as “disabled” to avoid accidental relative-path I/O.
Changes:
- Add safe Windows derivation for
Platform.CacheDirectory/ConfigDirectory, and introducePlatform.TryDeriveFromCache(...)helpers. - Update several features (telemetry UUID, module analysis cache, update notifications, profiles/transcripts) to avoid using empty cache/config/document paths.
- Adjust path resolution for
~in PATH discovery to useDoNotVerify.
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/utils/Telemetry.cs | Derive telemetry.uuid path via TryDeriveFromCache and gate telemetry init on having a valid cache path. |
| src/System.Management.Automation/engine/PSConfiguration.cs | Avoid building per-user config file path when config directory is empty; skip reads when config path is empty. |
| src/System.Management.Automation/engine/Modules/AnalysisCache.cs | Derive cache file location via TryDeriveFromCache and skip serialization when no cache location is available. |
| src/System.Management.Automation/engine/hostifaces/MshHostUserInterface.cs | Return empty transcript path when base documents directory resolves to empty. |
| src/System.Management.Automation/engine/hostifaces/HostUtilities.cs | Normalize empty-base-path handling for profile file path generation. |
| src/System.Management.Automation/engine/CommandDiscovery.cs | Use DoNotVerify when expanding ~ to the user profile path. |
| src/System.Management.Automation/CoreCLR/CorePsPlatform.cs | Implement SafeDeriveFromSpecialFolder, switch Windows folder lookups to DoNotVerify, and add TryDeriveFromCache helpers. |
| src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs | Gate update notifications on successful cache path derivation. |
| src/Microsoft.PowerShell.ConsoleHost/host/msh/ConsoleHost.cs | Avoid calling profile optimization APIs when cache directory is empty. |
Comment on lines
89
to
96
| // Note: This directory may or may not exist depending upon the execution scenario. | ||
| // Writes will attempt to create the directory if it does not already exist. | ||
| perUserConfigDirectory = Platform.ConfigDirectory; | ||
| perUserConfigFile = Path.Combine(perUserConfigDirectory, ConfigFileName); | ||
| if (!string.IsNullOrEmpty(perUserConfigDirectory)) | ||
| { | ||
| perUserConfigFile = Path.Combine(perUserConfigDirectory, ConfigFileName); | ||
| } | ||
|
|
Comment on lines
+1159
to
+1162
| if (string.IsNullOrEmpty(baseDirectory)) | ||
| { | ||
| return string.Empty; | ||
| } |
d648dd1
into
PowerShell:release/v7.5.7
50 of 54 checks passed
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.5.7
Triggered by @adityapatwardhan on behalf of @SeeminglyScience
Original CL Label: CL-Engine
/cc @PowerShell/powershell-maintainers
Manual merge as co-pilot merge was incorrect.
Impact
REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.
Tooling Impact
Customer Impact
Fixes user configuration path handling so SYSTEM uses the expected default config location and skips user config loading when the configured Documents folder resolves to an empty/whitespace path.
Regression
REQUIRED: Check exactly one box.
This is not a regression.
Testing
Cherry-pick completed onto release/v7.5.7 and conflict resolution preserved release-specific telemetry module lists while applying the config-path fix logic. The changed files match the original PR scope and the backport commit applied cleanly after resolving one conflict in Telemetry.cs.
Risk
REQUIRED: Check exactly one box.
Change is scoped to path derivation and guard logic for user config locations. The backport keeps existing release branch behavior outside this targeted fix, minimizing regression surface.
Merge Conflicts
Resolved one conflict in src/System.Management.Automation/utils/Telemetry.cs by preserving release/v7.5.7 content and applying the intended CanSendTelemetry/telemetry.uuid path derivation update from PR #26269.