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

fix: Allow multiple reads of StorageFile #11844

Merged
merged 2 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/Uno.UI.RuntimeTests/Tests/Windows_Storage/Given_StorageFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,25 @@ public async Task When_Open_By_Encoded_URI_With_Space()
}
}

[TestMethod]
public async Task When_Open_Multiple_Reads_Single_Write()
{
var uri = new Uri($"ms-appx:///Assets/Asset With Spaces.svg");

try
{
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
_ = await file.OpenStreamForReadAsync();
_ = await file.OpenStreamForReadAsync();
_ = await file.OpenStreamForWriteAsync();
_ = await file.OpenStreamForReadAsync();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
Youssef1313 marked this conversation as resolved.
Show resolved Hide resolved
}
}

[TestMethod]
#if __MACOS__ && !NET6_0_OR_GREATER
[Ignore] // Not supported for Xamarin.mac target
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UWP/System.IO/WindowsRuntimeStorageExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static async Task<Stream> OpenStreamForReadAsync(this IStorageFile window
{
if (windowsRuntimeFile is StorageFile file)
{
return await file.OpenStream(CancellationToken.None, FileAccessMode.Read, StorageOpenOptions.None);
return await file.OpenStream(CancellationToken.None, FileAccessMode.Read, StorageOpenOptions.AllowReadersAndWriters);
dr1rrb marked this conversation as resolved.
Show resolved Hide resolved
}
else
{
Expand All @@ -32,7 +32,7 @@ public static async Task<Stream> OpenStreamForWriteAsync(this IStorageFile windo
{
if (windowsRuntimeFile is StorageFile file)
{
return await file.OpenStream(CancellationToken.None, FileAccessMode.ReadWrite, StorageOpenOptions.None);
return await file.OpenStream(CancellationToken.None, FileAccessMode.ReadWrite, StorageOpenOptions.AllowOnlyReaders);
}
else
{
Expand Down