Skip to content

[release/v7.4.16] Fix checks for local user config file paths#27454

Merged
adityapatwardhan merged 1 commit into
release/v7.4.16from
backport-26269
May 15, 2026
Merged

[release/v7.4.16] Fix checks for local user config file paths#27454
adityapatwardhan merged 1 commit into
release/v7.4.16from
backport-26269

Conversation

@adityapatwardhan
Copy link
Copy Markdown
Member

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

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

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.

  • Yes
  • No

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.

  • High
  • Medium
  • Low

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.

Copilot AI review requested due to automatic review settings May 15, 2026 17:40
@adityapatwardhan adityapatwardhan added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label May 15, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.DoNotVerify for 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;
}
@adityapatwardhan adityapatwardhan added CL-Engine Indicates that a PR should be marked as an engine change in the Change Log and removed CL-Engine Indicates that a PR should be marked as an engine change in the Change Log labels May 15, 2026
@adityapatwardhan adityapatwardhan merged commit c529770 into release/v7.4.16 May 15, 2026
41 of 44 checks passed
@adityapatwardhan adityapatwardhan deleted the backport-26269 branch May 15, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-Engine Indicates that a PR should be marked as an engine change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants