Skip to content

Commit

Permalink
Merge pull request #11844 from Youssef1313/issues/11620
Browse files Browse the repository at this point in the history
fix: Allow multiple reads of StorageFile
  • Loading branch information
agneszitte authored Apr 3, 2023
2 parents dfe308b + c961abb commit 680db20
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 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,17 @@ 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");
var file = await StorageFile.GetFileFromApplicationUriAsync(uri);
_ = await file.OpenStreamForReadAsync();
_ = await file.OpenStreamForReadAsync();
_ = await file.OpenStreamForWriteAsync();
_ = await file.OpenStreamForReadAsync();
}

[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);
}
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

0 comments on commit 680db20

Please sign in to comment.