Skip to content

Commit 76b45ed

Browse files
Justin ChungCopilot
andcommitted
Scope PR to config merging: drop profile relocation; union WinCompat deny list
Per the MSIX machine-folder meeting decisions, narrow this PR to configuration-file merging. - Remove the AllUsers profile relocation to the packaged machine-folder data store. GetAllUsersFolderPath() again resolves to $PSHOME via Utils.GetApplicationBase(shellId) on every install type. Profile relocation is deferred to a dedicated follow-up tracked by PowerShell#27564. - Merge the Windows PowerShell compatibility module deny list as a policy: the effective list is the union of the CurrentUser, MachineFolder, and AllUsers ($PSHOME) scopes, so deny entries added by a product update in $PSHOME are still honored when a machine or user config also sets the key. The no-clobber list stays a preference (highest-precedence scope wins outright) and is documented as such. Co-authored-by: Copilot <[email protected]> Copilot-Session: ab738c1b-4d18-491b-a40f-0515b586857b
1 parent a6108cc commit 76b45ed

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

‎src/System.Management.Automation/engine/PSConfiguration.cs‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,13 +290,37 @@ internal bool IsImplicitWinCompatEnabled()
290290

291291
internal string[] GetWindowsPowerShellCompatibilityModuleDenyList()
292292
{
293-
return ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityModuleDenyListKey)
294-
?? ReadValueFromFile<string[]>(ConfigScope.MachineFolder, WindowsPowerShellCompatibilityModuleDenyListKey)
295-
?? ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityModuleDenyListKey);
293+
// The compatibility module deny list is a *policy*: the effective list is the union of the
294+
// entries from every scope (AllUsers/$PSHOME product defaults, the admin MachineFolder, and
295+
// CurrentUser). Unioning - rather than letting the highest-precedence scope that defines the
296+
// key win outright - ensures that new modules added to the deny list by a product update in
297+
// $PSHOME are still honored when a MachineFolder or user config also sets the key. Any scope
298+
// can only add to the deny list; a higher-precedence scope never removes a lower scope's deny.
299+
var denyList = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
300+
foreach (ConfigScope scope in new[] { ConfigScope.CurrentUser, ConfigScope.MachineFolder, ConfigScope.AllUsers })
301+
{
302+
string[] values = ReadValueFromFile<string[]>(scope, WindowsPowerShellCompatibilityModuleDenyListKey);
303+
if (values is not null)
304+
{
305+
denyList.UnionWith(values);
306+
}
307+
}
308+
309+
if (denyList.Count == 0)
310+
{
311+
return null;
312+
}
313+
314+
var result = new string[denyList.Count];
315+
denyList.CopyTo(result);
316+
return result;
296317
}
297318

298319
internal string[] GetWindowsPowerShellCompatibilityNoClobberModuleList()
299320
{
321+
// Unlike the deny list (a policy that unions every scope), the no-clobber list is treated as a
322+
// *preference*: the highest-precedence scope that defines it wins outright, following the
323+
// preference merge order CurrentUser > MachineFolder > AllUsers ($PSHOME).
300324
return ReadValueFromFile<string[]>(ConfigScope.CurrentUser, WindowsPowerShellCompatibilityNoClobberModuleListKey)
301325
?? ReadValueFromFile<string[]>(ConfigScope.MachineFolder, WindowsPowerShellCompatibilityNoClobberModuleListKey)
302326
?? ReadValueFromFile<string[]>(ConfigScope.AllUsers, WindowsPowerShellCompatibilityNoClobberModuleListKey);

‎src/System.Management.Automation/engine/hostifaces/HostUtilities.cs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,7 @@ private static string GetAllUsersFolderPath(string shellId)
177177
string folderPath = string.Empty;
178178
try
179179
{
180-
// When running as a packaged MSIX app with the per-machine data store provisioned, the
181-
// AllUsers profiles live in that writable store; otherwise they live under $PSHOME.
182-
folderPath = Utils.GetPackagedMachineDataStorePath() ?? Utils.GetApplicationBase(shellId);
180+
folderPath = Utils.GetApplicationBase(shellId);
183181
}
184182
catch (System.Security.SecurityException)
185183
{

0 commit comments

Comments
 (0)