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;
Comment thread
SeeminglyScience marked this conversation as resolved.
}
// 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 thread
SeeminglyScience marked this conversation as resolved.
catch
{
return false;
}
Comment thread
SeeminglyScience marked this conversation as resolved.
}

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