Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,9 @@ internal static string GetPersonalModulePath()
#if UNIX
return Platform.SelectProductNameForDirectory(Platform.XDG_Type.USER_MODULES);
#else
string myDocumentsPath = InternalTestHooks.SetMyDocumentsSpecialFolderToBlank ? string.Empty : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string myDocumentsPath = InternalTestHooks.SetMyDocumentsSpecialFolderToBlank
? string.Empty
: Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.DoNotVerify);
return string.IsNullOrEmpty(myDocumentsPath) ? null : Path.Combine(myDocumentsPath, Utils.ModuleDirectory);
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = SafeDoesPathExist(drive.Root);
}

if (validDrive)
Expand Down Expand Up @@ -908,7 +908,7 @@ protected override Collection<PSDriveInfo> InitializeDefaultDrives()

if (newDrive.DriveType == DriveType.Fixed)
{
if (!newDrive.RootDirectory.Exists)
if (!SafeDoesPathExist(newDrive.RootDirectory.FullName))
{
continue;
}
Expand Down Expand Up @@ -1227,6 +1227,29 @@ protected override void GetItem(string path)
}
}

private static bool SafeDoesPathExist(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;
Comment on lines +1241 to +1245
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

SafeDoesPathExist treats any UnauthorizedAccessException as “exists”. Because this helper is used by NewDrive, it changes behavior for access-denied non-root directories as well (not just drive roots/AppContainer). If you want to keep the change narrowly scoped, consider constraining the special-case to volume-root paths (where Path.GetPathRoot(...) matches the input) or clarifying the intended broader behavior in the helper’s comment/name.

Copilot uses AI. Check for mistakes.
}
catch
{
return false;
}
}

private FileSystemInfo GetFileSystemItem(string path, ref bool isContainer, bool showHidden)
{
path = NormalizePath(path);
Expand Down
Loading