Skip to content

WIP: Enable usage in AppContainers#27266

Open
SeeminglyScience wants to merge 1 commit intoPowerShell:masterfrom
SeeminglyScience:fix-app-container-issue
Open

WIP: Enable usage in AppContainers#27266
SeeminglyScience wants to merge 1 commit intoPowerShell:masterfrom
SeeminglyScience:fix-app-container-issue

Conversation

@SeeminglyScience
Copy link
Copy Markdown
Contributor

PR Summary

PR Context

PR Checklist

@SeeminglyScience SeeminglyScience requested a review from a team as a code owner April 14, 2026 22:49
Copilot AI review requested due to automatic review settings April 14, 2026 22:49
@SeeminglyScience SeeminglyScience added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Apr 14, 2026
@SeeminglyScience SeeminglyScience changed the title WIP: Stop catastrophic drive errors in AppContainers WIP: Enable usage in AppContainers Apr 14, 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

Note

Copilot was unable to run its full agentic suite in this review.

This PR aims to prevent failures when validating or discovering fixed drives and user module paths in restricted environments (e.g., AppContainers), where direct access to certain roots/special folders may be denied.

Changes:

  • Replace direct fixed-drive existence checks with a helper that tolerates access-denied scenarios.
  • Update default drive initialization to use the new fixed-drive validator.
  • Avoid verification when retrieving the “My Documents” special folder path on Windows.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/System.Management.Automation/namespaces/FileSystemProvider.cs Introduces IsValidFixedDrive and routes fixed-drive validation through it to avoid access-related failures.
src/System.Management.Automation/engine/Modules/ModuleIntrinsics.cs Uses Environment.SpecialFolderOption.DoNotVerify when reading MyDocuments to avoid verification failures.

Comment on lines +1247 to +1250
catch
{
return false;
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The bare catch will also swallow unexpected/fatal exceptions (e.g., OutOfMemoryException, StackOverflowException can’t be caught, but others like ThreadAbortException in legacy scenarios) and makes failures harder to diagnose. Prefer catching only the expected exception types from File.GetAttributes (e.g., IOException, ArgumentException, NotSupportedException, PathTooLongException) and let truly unexpected exceptions bubble.

Suggested change
catch
{
return false;
}
catch (IOException)
{
return false;
}
catch (ArgumentException)
{
return false;
}
catch (NotSupportedException)
{
return false;
}
catch (PathTooLongException)
{
return false;
}

Copilot uses AI. Check for mistakes.
catch (UnauthorizedAccessException)
{
return true;
}
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

If the intent is to treat "access denied" as "drive is valid" for restricted sandboxes, consider also handling System.Security.SecurityException the same way as UnauthorizedAccessException. Some sandbox/policy configurations can surface as SecurityException, and returning false there could reintroduce the drive being skipped/treated invalid.

Suggested change
}
}
catch (SecurityException)
{
return true;
}

Copilot uses AI. Check for mistakes.

try
{
return (File.GetAttributes(rootDirectory) & FileAttributes.Directory) is not 0;
Copy link

Copilot AI Apr 14, 2026

Choose a reason for hiding this comment

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

The enum flag check using pattern matching (is not 0) is less conventional for bit flags and may be inconsistent with other flag checks in this codebase. Using the standard comparison form (!= 0) tends to be clearer and more idiomatic for FileAttributes bitmasks.

Suggested change
return (File.GetAttributes(rootDirectory) & FileAttributes.Directory) is not 0;
return (File.GetAttributes(rootDirectory) & FileAttributes.Directory) != 0;

Copilot uses AI. Check for mistakes.
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.

2 participants