Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

74642 change isostorage path #75541

Merged
merged 12 commits into from
Sep 27, 2022
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
@@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal static partial class Helper
{
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
///
Expand All @@ -21,6 +19,8 @@ internal static partial class Helper
/// 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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the mono implementation you linked the code appends .isolated-storage at the very end and I can't see it anywhere in your PR. Is that done somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the latest change will change the behavior of all platforms, not just the mobile ones, right? I'm not sure if that's something we can/should do, because it could lead to the same problem just on different platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does .config get appended to the path on mobile if IsolatedStorageDirectoryName is just .isolated-storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in all cases config is appended
( in legacy mono also https://github.com/mono/mono/blob/b40e9939a7d07b30a75625692874f02bcc9be18f/mcs/class/corlib/System/Environment.cs#L623 ). During testing I noticed in some cases there was .config added and I think it was done by GetDataDirectory , it will be included in dataDirectory https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/Helper.Win32Unix.cs#L26

}
}
}
Original file line number Diff line number Diff line change
@@ -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);
mkhamoyan marked this conversation as resolved.
Show resolved Hide resolved

return root.ToString();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ internal IsolatedStorageFile(IsolatedStorageScope scope)
// 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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -52,6 +52,14 @@
<Compile Include="System\IO\IsolatedStorage\OpenFileTests.cs" />
<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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void GetDataDirectory(IsolatedStorageScope scope)
return;

string path = Helper.GetDataDirectory(scope);
Assert.Equal("IsolatedStorage", Path.GetFileName(path));
Assert.Equal(Helper.IsolatedStorageDirectoryName, Path.GetFileName(path));
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace System.IO.IsolatedStorage
{
public static class TestHelper
public static partial class TestHelper
{
private static PropertyInfo s_rootDirectoryProperty;
private static List<string> s_roots;
Expand All @@ -17,27 +17,8 @@ static TestHelper()
{
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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What tests are failing if this isn't changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As roots are different for mobile and non mobile platforms I needed to implement differently for them.


// We don't expose Roaming yet
// Helper.GetDataDirectory(IsolatedStorageScope.Roaming);
}
Expand Down