Skip to content

[release/v7.5.7] Fix checks for local user config file paths#27479

Merged
adityapatwardhan merged 2 commits into
PowerShell:release/v7.5.7from
adityapatwardhan:backport-localuserconfig-757
May 19, 2026
Merged

[release/v7.5.7] Fix checks for local user config file paths#27479
adityapatwardhan merged 2 commits into
PowerShell:release/v7.5.7from
adityapatwardhan:backport-localuserconfig-757

Conversation

@adityapatwardhan
Copy link
Copy Markdown
Member

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

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

Customer Impact

  • Customer reported
  • Found internally

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.

  • Yes
  • No

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.

  • High
  • Medium
  • Low

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.

Copilot AI review requested due to automatic review settings May 19, 2026 15:13
@adityapatwardhan adityapatwardhan added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label May 19, 2026
Comment thread src/System.Management.Automation/utils/Telemetry.cs Outdated
Copy link
Copy Markdown
Contributor

@SeeminglyScience SeeminglyScience left a comment

Choose a reason for hiding this comment

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

LGTM!

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

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 introduce Platform.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 use DoNotVerify.

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;
}
@adityapatwardhan adityapatwardhan enabled auto-merge (squash) May 19, 2026 17:23
@adityapatwardhan adityapatwardhan merged commit d648dd1 into PowerShell:release/v7.5.7 May 19, 2026
50 of 54 checks passed
@adityapatwardhan adityapatwardhan deleted the backport-localuserconfig-757 branch May 19, 2026 17:25
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