Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<ItemGroup Condition="'$(TargetPlatformIdentifier)' != ''">
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageException.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageFile.cs" />
<Compile Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'"
Include="System\IO\IsolatedStorage\IsolatedStorageFile.AnyMobile.cs" />
<Compile Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS'"
Include="System\IO\IsolatedStorage\IsolatedStorageFile.NonMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageFileStream.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorage.cs" />
<Compile Include="System\IO\IsolatedStorage\IsolatedStorageScope.cs" />
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);

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
Expand Up @@ -51,6 +51,10 @@
<Compile Include="System\IO\IsolatedStorage\MoveFileTests.cs" />
<Compile Include="System\IO\IsolatedStorage\OpenFileTests.cs" />
<Compile Include="System\IO\IsolatedStorage\TestHelper.cs" />
<Compile Condition="'$(TargetPlatformIdentifier)' == 'Android' or '$(TargetPlatformIdentifier)' == 'iOS' or '$(TargetPlatformIdentifier)' == 'MacCatalyst' or '$(TargetPlatformIdentifier)' == 'tvOS'"
Include="System\IO\IsolatedStorage\TestHelper.AnyMobile.cs" />
<Compile Condition="'$(TargetPlatformIdentifier)' != 'Android' and '$(TargetPlatformIdentifier)' != 'iOS' and '$(TargetPlatformIdentifier)' != 'MacCatalyst' and '$(TargetPlatformIdentifier)' != 'tvOS'"
Include="System\IO\IsolatedStorage\TestHelper.NonMobile.cs" />
<Compile Include="System\IO\IsolatedStorage\RemoveTests.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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);
}
}
}
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