System.IO.Abstractions icon indicating copy to clipboard operation
System.IO.Abstractions copied to clipboard

OpenWrite doesn't prevent writing

Open Benjamin-Berry opened this issue 1 year ago • 2 comments

Describe the bug Stream.CopyTpAsync still works with a write only stream.

To Reproduce var fs = new MockFileSystem();

...

using var estream = entry.Open(); using var fstream = file.OpenWrite(); var temp = fstream.CanRead; // false await fstream.CopyToAsync(estream);

Expected behavior MockFileSystem and FileSystem would behave the same.

Additional context I'm writing into a ZipArchive but that shouldn't matter. Swapping to use FileSystem in the Unit test does throw a permissions exception.

Benjamin-Berry avatar Oct 09 '24 16:10 Benjamin-Berry

@Benjamin-Berry : Could you please provide a complete repro example as it is unclear from your description what entry and file should be or what settings you applied.

vbreuss avatar Oct 10 '24 06:10 vbreuss

I can't give you any proprietary code.

var fs = new MockFileSystem(); var directory = fs.DirectoryInfo.New("somepath"); foreach (var file in directory.GetFiles(".", SearchOption.AllDirectories)) { using var estream = new MemoryStream(); using var fstream = file.OpenWrite(); var temp = fstream.CanRead; // false await fstream.CopyToAsync(estream); }

Benjamin-Berry avatar Oct 10 '24 13:10 Benjamin-Berry

This is addressed in release v21.1.2.

github-actions[bot] avatar Nov 08 '24 08:11 github-actions[bot]