diff options
author | Meri Khamoyan <96171496+mkhamoyan@users.noreply.github.com> | 2022-09-27 10:01:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-27 10:01:57 +0300 |
commit | bc27a6a7319d7244de2570b47b43465d2215e4f6 (patch) | |
tree | 1d4ddddf9a53d3255ba18f03f20626e82e9600d7 /src/libraries | |
parent | a7ae0720f4a491b40db858130039e9a20adb34d4 (diff) |
74642 change isostorage path (#75541)
* #74642 changed isolated storage path for mobile platforms
Diffstat (limited to 'src/libraries')
13 files changed, 140 insertions, 34 deletions
diff --git a/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj b/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj index 9b5284960f9..2309a8c007a 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj +++ b/src/libraries/System.IO.IsolatedStorage/src/System.IO.IsolatedStorage.csproj @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)</TargetFrameworks> + <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android;$(NetCoreAppCurrent)</TargetFrameworks> </PropertyGroup> <!-- DesignTimeBuild requires all the TargetFramework Derived Properties to not be present in the first property group. --> <PropertyGroup> @@ -19,10 +19,18 @@ <Compile Include="$(CommonPath)System\Security\IdentityHelper.cs" Link="Common\System\Security\IdentityHelper.cs" /> </ItemGroup> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'"> + <Compile Include="System\IO\IsolatedStorage\Helper.AnyMobile.cs" /> + <Compile Include="System\IO\IsolatedStorage\IsolatedStorageFile.AnyMobile.cs" /> + </ItemGroup> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS' and '$(TargetPlatformIdentifier)' != ''"> + <Compile Include="System\IO\IsolatedStorage\Helper.NonMobile.cs" /> + <Compile Include="System\IO\IsolatedStorage\IsolatedStorageFile.NonMobile.cs" /> + </ItemGroup> <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'windows'"> <Compile Include="System\IO\IsolatedStorage\Helper.Win32.cs" /> </ItemGroup> - <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Unix'"> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'"> <Compile Include="System\IO\IsolatedStorage\Helper.Unix.cs" /> </ItemGroup> <ItemGroup> diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs new file mode 100644 index 00000000000..4121814515f --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.AnyMobile.cs @@ -0,0 +1,10 @@ +// 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.IsolatedStorage +{ + internal static partial class Helper + { + public const string IsolatedStorageDirectoryName = ".isolated-storage"; + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs new file mode 100644 index 00000000000..cde27b6c5e2 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.NonMobile.cs @@ -0,0 +1,10 @@ +// 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.IsolatedStorage +{ + internal static partial class Helper + { + public const string IsolatedStorageDirectoryName = "IsolatedStorage"; + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs index 5a55e866789..7577ea7ee04 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs @@ -12,7 +12,7 @@ namespace System.IO.IsolatedStorage { internal static string GetDataDirectory(IsolatedStorageScope scope) { - // This is the relevant special folder for the given scope plus "IsolatedStorage". + // This is the relevant special folder for the given scope plus IsolatedStorageDirectoryName. // It is meant to replicate the behavior of the VM ComIsolatedStorage::GetRootDir(). // (note that Silverlight used "CoreIsolatedStorage" for a directory name and did not support machine scope) diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs index 3b5d6b6afbc..984eeed4046 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.cs @@ -5,14 +5,12 @@ namespace System.IO.IsolatedStorage { internal static partial class Helper { - private const string IsolatedStorageDirectoryName = "IsolatedStorage"; - private static string? s_machineRootDirectory; private static string? s_roamingUserRootDirectory; private static string? s_userRootDirectory; /// <summary> - /// The full root directory is the relevant special folder from Environment.GetFolderPath() plus "IsolatedStorage" + /// The full root directory is the relevant special folder from Environment.GetFolderPath() plus IsolatedStorageDirectoryName /// and a set of random directory names if not roaming. (The random directories aren't created for WinRT as /// the FolderPath locations for WinRT are app isolated already.) /// @@ -21,6 +19,8 @@ namespace System.IO.IsolatedStorage /// User: @"C:\Users\jerem\AppData\Local\IsolatedStorage\10v31ho4.bo2\eeolfu22.f2w\" /// User|Roaming: @"C:\Users\jerem\AppData\Roaming\IsolatedStorage\" /// Machine: @"C:\ProgramData\IsolatedStorage\nin03cyc.wr0\o3j0urs3.0sn\" + /// Android path: "/data/user/0/net.dot.System.IO.IsolatedStorage.Tests/files/.config/.isolated-storage/" + /// iOS path: "/var/mobile/Containers/Data/Application/A323CBB9-A2B3-4432-9449-48CC20C07A7D/Documents/.config/.isolated-storage/" /// /// Identity for the current store gets tacked on after this. /// </summary> diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs new file mode 100644 index 00000000000..69a2f706779 --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.AnyMobile.cs @@ -0,0 +1,13 @@ +// 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.IsolatedStorage +{ + public sealed partial class IsolatedStorageFile : IsolatedStorage, IDisposable + { + private string GetIsolatedStorageRoot() + { + return Helper.GetRootDirectory(Scope); + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs new file mode 100644 index 00000000000..4f547d55cff --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.NonMobile.cs @@ -0,0 +1,19 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Text; + +namespace System.IO.IsolatedStorage +{ + public sealed partial class IsolatedStorageFile : IsolatedStorage, IDisposable + { + private string GetIsolatedStorageRoot() + { + StringBuilder root = new StringBuilder(Helper.GetRootDirectory(Scope)); + root.Append(SeparatorExternal); + root.Append(IdentityHash); + + return root.ToString(); + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs index 0f024ca64fb..4afd6468cea 100644 --- a/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs +++ b/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFile.cs @@ -43,9 +43,7 @@ namespace System.IO.IsolatedStorage // InitStore will set up the IdentityHash InitStore(scope, null, null); - StringBuilder sb = new StringBuilder(Helper.GetRootDirectory(scope)); - sb.Append(SeparatorExternal); - sb.Append(IdentityHash); + StringBuilder sb = new StringBuilder(GetIsolatedStorageRoot()); sb.Append(SeparatorExternal); if (Helper.IsApplication(scope)) diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj index b075376fa8b..0410513c46c 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj +++ b/src/libraries/System.IO.IsolatedStorage/tests/System.IO.IsolatedStorage.Tests.csproj @@ -1,6 +1,6 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks> + <TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser;$(NetCoreAppCurrent)-MacCatalyst;$(NetCoreAppCurrent)-iOS;$(NetCoreAppCurrent)-tvOS;$(NetCoreAppCurrent)-Android</TargetFrameworks> <IgnoreForCI Condition="'$(TargetOS)' == 'Browser'">true</IgnoreForCI> </PropertyGroup> <ItemGroup> @@ -17,7 +17,7 @@ <Compile Include="..\src\System\IO\IsolatedStorage\Helper.Win32.cs" Link="Internals\Helper.Win32.cs" /> </ItemGroup> - <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Unix' or '$(TargetPlatformIdentifier)' == 'Browser'"> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'windows'"> <Compile Include="..\src\System\IO\IsolatedStorage\Helper.Unix.cs" Link="Internals\Helper.Unix.cs" /> </ItemGroup> @@ -53,6 +53,14 @@ <Compile Include="System\IO\IsolatedStorage\TestHelper.cs" /> <Compile Include="System\IO\IsolatedStorage\RemoveTests.cs" /> </ItemGroup> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'"> + <Compile Include="..\src\System\IO\IsolatedStorage\Helper.AnyMobile.cs" /> + <Compile Include="System\IO\IsolatedStorage\TestHelper.AnyMobile.cs" /> + </ItemGroup> + <ItemGroup Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS' and '$(TargetPlatformIdentifier)' != ''"> + <Compile Include="..\src\System\IO\IsolatedStorage\Helper.NonMobile.cs" /> + <Compile Include="System\IO\IsolatedStorage\TestHelper.NonMobile.cs" /> + </ItemGroup> <ItemGroup> <ProjectReference Include="$(LibrariesProjectRoot)System.DirectoryServices\src\System.DirectoryServices.csproj" /> </ItemGroup> diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs index 2fe50e59055..60d65949da7 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/HelperTests.cs @@ -45,7 +45,7 @@ namespace System.IO.IsolatedStorage.Tests return; string path = Helper.GetDataDirectory(scope); - Assert.Equal("IsolatedStorage", Path.GetFileName(path)); + Assert.Equal(Helper.IsolatedStorageDirectoryName, Path.GetFileName(path)); } } } diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs new file mode 100644 index 00000000000..63709fd41ab --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.AnyMobile.cs @@ -0,0 +1,23 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Collections.Generic; + +namespace System.IO.IsolatedStorage +{ + public static partial class TestHelper + { + private static List<string> GetRoots() + { + List<string> roots = new List<string>(); + string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); + string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); + roots.Add(randomUserRoot); + + // Application scope doesn't go under a random dir + roots.Add(userRoot); + return roots; + } + } +} diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs new file mode 100644 index 00000000000..e0217dc241a --- /dev/null +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.NonMobile.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Reflection; +using System.Collections.Generic; + +namespace System.IO.IsolatedStorage +{ + public static partial class TestHelper + { + private static List<string> GetRoots() + { + string hash; + object identity; + Helper.GetDefaultIdentityAndHash(out identity, out hash, '.'); + List<string> roots = new List<string>(); + string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); + string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); + + roots.Add(Path.Combine(randomUserRoot, hash)); + // Application scope doesn't go under a random dir + roots.Add(Path.Combine(userRoot, hash)); + + // https://github.com/dotnet/runtime/issues/2092 + // https://github.com/dotnet/runtime/issues/21742 + if (OperatingSystem.IsWindows() + && !PlatformDetection.IsInAppContainer) + { + roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine)); + } + + return roots; + } + } +} +
\ No newline at end of file diff --git a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs index e3e7f423a7b..06339504237 100644 --- a/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs +++ b/src/libraries/System.IO.IsolatedStorage/tests/System/IO/IsolatedStorage/TestHelper.cs @@ -8,7 +8,7 @@ using System.Text; namespace System.IO.IsolatedStorage { - public static class TestHelper + public static partial class TestHelper { private static PropertyInfo s_rootDirectoryProperty; private static List<string> s_roots; @@ -17,27 +17,8 @@ namespace System.IO.IsolatedStorage { s_rootDirectoryProperty = typeof(IsolatedStorageFile).GetProperty("RootDirectory", BindingFlags.NonPublic | BindingFlags.Instance); - s_roots = new List<string>(); - - string hash; - object identity; - Helper.GetDefaultIdentityAndHash(out identity, out hash, '.'); - - string userRoot = Helper.GetDataDirectory(IsolatedStorageScope.User); - string randomUserRoot = Helper.GetRandomDirectory(userRoot, IsolatedStorageScope.User); - s_roots.Add(Path.Combine(randomUserRoot, hash)); - - // Application scope doesn't go under a random dir - s_roots.Add(Path.Combine(userRoot, hash)); - - // https://github.com/dotnet/runtime/issues/2092 - // https://github.com/dotnet/runtime/issues/21742 - if (OperatingSystem.IsWindows() - && !PlatformDetection.IsInAppContainer) - { - s_roots.Add(Helper.GetDataDirectory(IsolatedStorageScope.Machine)); - } - + s_roots = GetRoots(); + // We don't expose Roaming yet // Helper.GetDataDirectory(IsolatedStorageScope.Roaming); } |