-
Notifications
You must be signed in to change notification settings - Fork 8.3k
WIP: Enable usage in AppContainers #27266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -569,7 +569,7 @@ protected override PSDriveInfo NewDrive(PSDriveInfo drive) | |||||||||||||||||||||||||||||||||||||||||
| if (driveIsFixed) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| // Since the drive is fixed, ensure the root is valid. | ||||||||||||||||||||||||||||||||||||||||||
| validDrive = Directory.Exists(drive.Root); | ||||||||||||||||||||||||||||||||||||||||||
| validDrive = IsValidFixedDrive(drive.Root); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (validDrive) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -908,7 +908,7 @@ protected override Collection<PSDriveInfo> InitializeDefaultDrives() | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| if (newDrive.DriveType == DriveType.Fixed) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| if (!newDrive.RootDirectory.Exists) | ||||||||||||||||||||||||||||||||||||||||||
| if (!IsValidFixedDrive(newDrive.RootDirectory.FullName)) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1227,6 +1227,29 @@ protected override void GetItem(string path) | |||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private static bool IsValidFixedDrive(string rootDirectory) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists(rootDirectory)) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| try | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| return (File.GetAttributes(rootDirectory) & FileAttributes.Directory) is not 0; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| // In some scenarios (like AppContainers) direct access to the root directory may | ||||||||||||||||||||||||||||||||||||||||||
| // be prevented, but more specific paths may be accessible. | ||||||||||||||||||||||||||||||||||||||||||
| catch (UnauthorizedAccessException) | ||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
| } | |
| } | |
| catch (SecurityException) | |
| { | |
| return true; | |
| } |
Copilot
AI
Apr 14, 2026
There was a problem hiding this comment.
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.
| catch | |
| { | |
| return false; | |
| } | |
| catch (IOException) | |
| { | |
| return false; | |
| } | |
| catch (ArgumentException) | |
| { | |
| return false; | |
| } | |
| catch (NotSupportedException) | |
| { | |
| return false; | |
| } | |
| catch (PathTooLongException) | |
| { | |
| return false; | |
| } |
There was a problem hiding this comment.
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 forFileAttributesbitmasks.