Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiepee <38186597+Miepee@users.noreply.github.com>2022-09-27 01:49:59 +0300
committerGitHub <noreply@github.com>2022-09-27 01:49:59 +0300
commit62db3613f21bca007e5b30af8342db32858ed2b9 (patch)
tree92a0e75d8692dfa6d9b0efc5e25c4a226944abd1 /src/libraries
parentfec8aeb79625af01d2a83854f0edf3bf8129c1ec (diff)
Fix some incorrect SpecialFolder entries for Unix (#68610)
* Fix incorrect SpecialFolder entries for Unix This fixes an incorrect Documents/Personal for Linux+Mac entry, incorrect Videos Mac entry, and an incorrect (Local) ApplicationData Mac entry. Fix #63214 * Don't make Unix tests assume Personal is Home * Use the same value for Mac's (Local)ApplicationData * Use NSPaths for OSX Special Folder The Apple documentation recommends to use these instead of hardcoding the paths, so the paths that had NSPath equivalents have been replaced. * Change System.Native CMakeLists to include OSX for SearchPath `a17e73466ca639388a3d89f4d6be0ab9703802fc` made OSX call the native NSearchPath functions, however a stub was initially called. This fixes it to call the native functions.
Diffstat (limited to 'src/libraries')
-rw-r--r--src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.cs1
-rw-r--r--src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems2
-rw-r--r--src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs61
-rw-r--r--src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs15
4 files changed, 49 insertions, 30 deletions
diff --git a/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.cs b/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.cs
index 89681a69c5e..ccb15a00227 100644
--- a/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.cs
+++ b/src/libraries/Common/src/Interop/OSX/System.Native/Interop.SearchPath.cs
@@ -19,6 +19,7 @@ internal static partial class Interop
NSDocumentDirectory = 9,
NSDesktopDirectory = 12,
NSCachesDirectory = 13,
+ NSApplicationSupportDirectory = 14,
NSMoviesDirectory = 17,
NSMusicDirectory = 18,
NSPicturesDirectory = 19
diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
index 8e15db94f55..d8620637574 100644
--- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
+++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems
@@ -2294,7 +2294,7 @@
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)System\IO\FileStatus.SetTimes.OSX.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(IsiOSLike)' == 'true'">
+ <ItemGroup Condition="'$(IsiOSLike)' == 'true' or '$(IsOSXLike)' == 'true'">
<Compile Include="$(CommonPath)Interop\OSX\System.Native\Interop.SearchPath.cs">
<Link>Common\Interop\OSX\Interop.SearchPath.cs</Link>
</Compile>
diff --git a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
index 7990febb5a1..1ec8fd1af28 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Environment.GetFolderPathCore.Unix.cs
@@ -9,6 +9,9 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
+#if TARGET_OSX
+using NSSearchPathDirectory = Interop.Sys.NSSearchPathDirectory;
+#endif
namespace System
{
@@ -17,7 +20,7 @@ namespace System
private static string GetFolderPathCore(SpecialFolder folder, SpecialFolderOption option)
{
// Get the path for the SpecialFolder
- string path = GetFolderPathCoreWithoutValidation(folder);
+ string path = GetFolderPathCoreWithoutValidation(folder) ?? string.Empty;
Debug.Assert(path != null);
// If we didn't get one, or if we got one but we're not supposed to verify it,
@@ -43,7 +46,7 @@ namespace System
return path;
}
- private static string GetFolderPathCoreWithoutValidation(SpecialFolder folder)
+ private static string? GetFolderPathCoreWithoutValidation(SpecialFolder folder)
{
// First handle any paths that involve only static paths, avoiding the overheads of getting user-local paths.
// https://www.freedesktop.org/software/systemd/man/file-hierarchy.html
@@ -85,42 +88,54 @@ namespace System
switch (folder)
{
case SpecialFolder.UserProfile:
- case SpecialFolder.MyDocuments: // same value as Personal
return home;
- case SpecialFolder.ApplicationData:
- return GetXdgConfig(home);
- case SpecialFolder.LocalApplicationData:
- // "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored."
- // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used."
- string? data = GetEnvironmentVariable("XDG_DATA_HOME");
- if (data is null || !data.StartsWith('/'))
- {
- data = Path.Combine(home, ".local", "share");
- }
- return data;
- case SpecialFolder.Desktop:
- case SpecialFolder.DesktopDirectory:
- return ReadXdgDirectory(home, "XDG_DESKTOP_DIR", "Desktop");
case SpecialFolder.Templates:
return ReadXdgDirectory(home, "XDG_TEMPLATES_DIR", "Templates");
- case SpecialFolder.MyVideos:
- return ReadXdgDirectory(home, "XDG_VIDEOS_DIR", "Videos");
-
+ // TODO: Consider merging the OSX path with the rest of the Apple systems here:
+ // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Environment.iOS.cs
#if TARGET_OSX
+ case SpecialFolder.Desktop:
+ case SpecialFolder.DesktopDirectory:
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSDesktopDirectory);
+ case SpecialFolder.ApplicationData:
+ case SpecialFolder.LocalApplicationData:
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSApplicationSupportDirectory);
+ case SpecialFolder.MyDocuments: // same value as Personal
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSDocumentDirectory);
case SpecialFolder.MyMusic:
- return Path.Combine(home, "Music");
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSMusicDirectory);
+ case SpecialFolder.MyVideos:
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSMoviesDirectory);
case SpecialFolder.MyPictures:
- return Path.Combine(home, "Pictures");
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSPicturesDirectory);
case SpecialFolder.Fonts:
return Path.Combine(home, "Library", "Fonts");
case SpecialFolder.Favorites:
return Path.Combine(home, "Library", "Favorites");
case SpecialFolder.InternetCache:
- return Path.Combine(home, "Library", "Caches");
+ return Interop.Sys.SearchPath(NSSearchPathDirectory.NSCachesDirectory);
#else
+ case SpecialFolder.Desktop:
+ case SpecialFolder.DesktopDirectory:
+ return ReadXdgDirectory(home, "XDG_DESKTOP_DIR", "Desktop");
+ case SpecialFolder.ApplicationData:
+ return GetXdgConfig(home);
+ case SpecialFolder.LocalApplicationData:
+ // "$XDG_DATA_HOME defines the base directory relative to which user specific data files should be stored."
+ // "If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used."
+ string? data = GetEnvironmentVariable("XDG_DATA_HOME");
+ if (data is null || !data.StartsWith('/'))
+ {
+ data = Path.Combine(home, ".local", "share");
+ }
+ return data;
+ case SpecialFolder.MyDocuments: // same value as Personal
+ return ReadXdgDirectory(home, "XDG_DOCUMENTS_DIR", "Documents");
case SpecialFolder.MyMusic:
return ReadXdgDirectory(home, "XDG_MUSIC_DIR", "Music");
+ case SpecialFolder.MyVideos:
+ return ReadXdgDirectory(home, "XDG_VIDEOS_DIR", "Videos");
case SpecialFolder.MyPictures:
return ReadXdgDirectory(home, "XDG_PICTURES_DIR", "Pictures");
case SpecialFolder.Fonts:
diff --git a/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
index 416c5859001..3c82cfe0032 100644
--- a/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
+++ b/src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs
@@ -332,19 +332,21 @@ namespace System.Tests
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Browser)]
- public void GetFolderPath_Unix_PersonalExists()
+ public void GetFolderPath_Unix_UserProfileExists()
{
- Assert.True(Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Personal)));
+ Assert.True(Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)));
}
[Fact]
[PlatformSpecific(TestPlatforms.AnyUnix | TestPlatforms.Browser)] // Tests OS-specific environment
- public void GetFolderPath_Unix_PersonalIsHomeAndUserProfile()
+ public void GetFolderPath_Unix_PersonalIsDocumentsAndUserProfile()
{
if (!PlatformDetection.IsiOS && !PlatformDetection.IstvOS && !PlatformDetection.IsMacCatalyst)
{
- Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.Personal));
- Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
+ Assert.Equal(Path.Combine(Environment.GetEnvironmentVariable("HOME"), "Documents"),
+ Environment.GetFolderPath(Environment.SpecialFolder.Personal, Environment.SpecialFolderOption.DoNotVerify));
+ Assert.Equal(Path.Combine(Environment.GetEnvironmentVariable("HOME"), "Documents"),
+ Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.DoNotVerify));
}
Assert.Equal(Environment.GetEnvironmentVariable("HOME"), Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));
@@ -357,6 +359,7 @@ namespace System.Tests
[InlineData(Environment.SpecialFolder.Desktop)]
[InlineData(Environment.SpecialFolder.DesktopDirectory)]
[InlineData(Environment.SpecialFolder.Fonts)]
+ [InlineData(Environment.SpecialFolder.MyDocuments)]
[InlineData(Environment.SpecialFolder.MyMusic)]
[InlineData(Environment.SpecialFolder.MyPictures)]
[InlineData(Environment.SpecialFolder.MyVideos)]
@@ -391,7 +394,7 @@ namespace System.Tests
[Theory]
[PlatformSpecific(TestPlatforms.AnyUnix)] // Tests OS-specific environment
[InlineData(Environment.SpecialFolder.UserProfile, Environment.SpecialFolderOption.None)]
- [InlineData(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.None)] // MyDocuments == Personal
+ [InlineData(Environment.SpecialFolder.MyDocuments, Environment.SpecialFolderOption.DoNotVerify)] // MyDocuments == Personal
[InlineData(Environment.SpecialFolder.CommonApplicationData, Environment.SpecialFolderOption.None)]
[InlineData(Environment.SpecialFolder.CommonTemplates, Environment.SpecialFolderOption.DoNotVerify)]
[InlineData(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.DoNotVerify)]