From 6feeb43a13bff05325e9d6d2037a2e6dcbc14737 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Wed, 22 Jul 2020 09:37:50 +0200 Subject: [PATCH 1/3] [browser][file system] GetLogicalDrives implementation - Directory.GetLogicalDrives threw PNSE. Follows existing code paths. - Add common DriveInfoInternal.Browser that is common code path for other implementations - Environment.GetLogicalDrives - DriveInfo.Drives Fix for FileSystemTest https://github.com/dotnet/runtime/blob/master/src/libraries/System.IO.FileSystem/tests/Directory/GetLogicalDrives.cs --- .../src/System/IO/DriveInfo.Browser.cs | 2 +- .../src/System.IO.FileSystem.csproj | 4 +++- .../src/System.Private.CoreLib.Shared.projitems | 3 ++- .../src/System/Environment.Browser.cs | 4 +++- .../src/System/IO/DriveInfoInternal.Browser.cs | 11 +++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Browser.cs diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs index 894c0a29a6410..7a47f69238fa0 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs @@ -15,6 +15,6 @@ public sealed partial class DriveInfo public long TotalFreeSpace => 0; public long TotalSize => 0; - private static string[] GetMountPoints() => Environment.GetLogicalDrives(); + private static string[] GetMountPoints() => DriveInfoInternal.GetLogicalDrives(); } } diff --git a/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj b/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj index df5ddd614c29f..827969b028138 100644 --- a/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj +++ b/src/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj @@ -193,7 +193,9 @@ + Link="Common\System\IO\DriveInfoInternal.Unix.cs" Condition="'$(TargetsBrowser)' != 'true'" /> + - + + diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs index 9ef90da4762d6..4f2beaa3b01bf 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs @@ -1,12 +1,14 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.IO; + namespace System { public static partial class Environment { // Emscripten VFS mounts at / and is the only drive - public static string[] GetLogicalDrives() => new string[] { "/" }; + public static string[] GetLogicalDrives() => DriveInfoInternal.GetLogicalDrives(); // In the mono runtime, this maps to gethostname, which returns 'emscripten'. // Returning the value here allows us to exclude more of the runtime. diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Browser.cs b/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Browser.cs new file mode 100644 index 0000000000000..858a56228216c --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Browser.cs @@ -0,0 +1,11 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System.IO +{ + /// Contains internal volume helpers that are shared between many projects. + internal static partial class DriveInfoInternal + { + internal static string[] GetLogicalDrives() => new string[] { "/" }; + } +} From 6aa1c521ea8638461d11f0ee0c0cd33a585d22ba Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Wed, 22 Jul 2020 09:38:55 +0200 Subject: [PATCH 2/3] Include in DriveInfo project. --- .../src/System.IO.FileSystem.DriveInfo.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj index fdc1f7b5f018a..f8936c7092b46 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj @@ -70,6 +70,8 @@ + From 909d56dd3127202eb974cf095792e3bf3de50162 Mon Sep 17 00:00:00 2001 From: Kenneth Pouncey Date: Wed, 22 Jul 2020 17:14:17 +0200 Subject: [PATCH 3/3] Address review comments remove second copy of DriveInfoInternal.Browser.cs --- .../src/System.IO.FileSystem.DriveInfo.csproj | 2 -- .../src/System/IO/DriveInfo.Browser.cs | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj index f8936c7092b46..fdc1f7b5f018a 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System.IO.FileSystem.DriveInfo.csproj @@ -70,8 +70,6 @@ - diff --git a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs index 7a47f69238fa0..894c0a29a6410 100644 --- a/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs +++ b/src/libraries/System.IO.FileSystem.DriveInfo/src/System/IO/DriveInfo.Browser.cs @@ -15,6 +15,6 @@ public sealed partial class DriveInfo public long TotalFreeSpace => 0; public long TotalSize => 0; - private static string[] GetMountPoints() => DriveInfoInternal.GetLogicalDrives(); + private static string[] GetMountPoints() => Environment.GetLogicalDrives(); } }