[browser][file system] GetLogicalDrives implementation (#39763)
authorKenneth Pouncey <kjpou@pt.lu>
Wed, 22 Jul 2020 23:30:50 +0000 (01:30 +0200)
committerGitHub <noreply@github.com>
Wed, 22 Jul 2020 23:30:50 +0000 (01:30 +0200)
- 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/libraries/System.IO.FileSystem/src/System.IO.FileSystem.csproj
src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
src/libraries/System.Private.CoreLib/src/System/Environment.Browser.cs
src/libraries/System.Private.CoreLib/src/System/IO/DriveInfoInternal.Browser.cs [new file with mode: 0644]

index df5ddd6..827969b 100644 (file)
     <Compile Include="$(CommonPath)Interop\Unix\System.Native\Interop.Unlink.cs"
              Link="Common\Interop\Unix\Interop.Unlink.cs" />
     <Compile Include="$(CoreLibSharedDir)System\IO\DriveInfoInternal.Unix.cs"
-             Link="Common\System\IO\DriveInfoInternal.Unix.cs" />
+             Link="Common\System\IO\DriveInfoInternal.Unix.cs" Condition="'$(TargetsBrowser)' != 'true'" />
+    <Compile Include="$(CoreLibSharedDir)System\IO\DriveInfoInternal.Browser.cs"
+             Link="Common\System\IO\DriveInfoInternal.Browser.cs" Condition="'$(TargetsBrowser)' == 'true'" />
     <Compile Include="$(CoreLibSharedDir)System\IO\PathInternal.Unix.cs"
              Link="System\IO\PathInternal.Unix.cs" />
     <Compile Include="$(CommonPath)Interop\Unix\Interop.Libraries.cs"
index b217b42..b00e089 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GlobalizationMode.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\HijriCalendar.Unix.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)System\Guid.Unix.cs" />
-    <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Unix.cs" Condition="'$(TargetsBrowser)' != 'true'"/>
+    <Compile Include="$(MSBuildThisFileDirectory)System\IO\DriveInfoInternal.Browser.cs" Condition="'$(TargetsBrowser)' == 'true'"/>
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Lock.OSX.cs" Condition="'$(IsOSXLike)' == 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Lock.Unix.cs" Condition="'$(IsOSXLike)' != 'true'" />
     <Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStream.Unix.cs" />
index 9ef90da..4f2beaa 100644 (file)
@@ -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 (file)
index 0000000..858a562
--- /dev/null
@@ -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
+{
+    /// <summary>Contains internal volume helpers that are shared between many projects.</summary>
+    internal static partial class DriveInfoInternal
+    {
+        internal static string[] GetLogicalDrives() => new string[] { "/" };
+    }
+}