runtime icon indicating copy to clipboard operation
runtime copied to clipboard

IsolatedStorageFileStream no longer derives from FileStream...

Open niemyjski opened this issue 10 years ago • 12 comments

The base implementation was changed and the class name wasn't updated.

https://github.com/dotnet/corefx/blob/master/src/System.IO.IsolatedStorage/src/System/IO/IsolatedStorage/IsolatedStorageFileStream.cs

niemyjski avatar May 27 '16 19:05 niemyjski

Looks like @dsgouda ported this; any particular reason we dropped the FileStream inheritance?

ianhays avatar May 27 '16 21:05 ianhays

I'm afraid @weshaggard may have to take a look at this.

dsgouda avatar May 31 '16 17:05 dsgouda

I don't remember why we did that but I suspect it was because of some restricts with the FileStream we expose or the fact we support it on UWP.

@niemyjski what is it that you are trying to use from FileStream that we didn't expose on IsolatedStrorageFileStream.

weshaggard avatar May 31 '16 17:05 weshaggard

Using Stream worked, it just broke our api signature.. Also the type name doesn't represent the base type

niemyjski avatar May 31 '16 23:05 niemyjski

@ianhays what's the plan here?

joshfree avatar Jun 02 '16 16:06 joshfree

It makes me nervous to change the signature so late into RTM, particularly since we don't know why it was changed in the first place. Testing on UWP is tricky and the implications of a major change with a day left in RTM and maybe one more test build before escrow scare me.

That said, I could think of a few reasons why we wouldn't want to have it inherit from FileStream (FileStream restrictions, easier UWP sandboxing), but I don't know that those are worth breaking the signature.

/cc: @ericstj

ianhays avatar Jun 02 '16 17:06 ianhays

/cc @pallavit

We shipped it stable at UWP RTM (package 4.0.0) deriving from Stream. This isn't any sort of regression so we can move this request out of 1.0.0-rtm.

IIRC There were a couple reasons for stripping the base type. We wanted to separate FileSystem out as a non-exchange type from all contracts (thus the separation of FileSystem and FileSystem.Primitives). We wanted Stream to be the exchange type. You can implement IsolatedStorage without a full filesystem implementation (and in fact, this is what some platforms already do) and we didn't want the surface area to be bringing in FileSystem even if the platform didn't want to support it. Additionally, the FileStream type is not friendly to implementation replacement. Every constructor on it takes either a path or a handle which have to hit the actual filesystem. These make it near-impossible to implement IsolatedStorage with an in-memory representation of the file. (that's probably a separate issue as well).

ericstj avatar Jun 02 '16 17:06 ericstj

I did a bit of digging into this.

IsoStream is a wrapper around a FileStream that enforces the stream's location be limited to a certain location. In the old code, IsoStream inherited from FileStream but overrided everything and used none of FileStreams public constructors. Instead, FileStream added a zero-arg constructor specifically for IsoStream:

        //This exists only to support IsolatedStorageFileStream.
        //Any changes to FileStream must include the corresponding changes in IsolatedStorage.
        internal FileStream() { 
        }

Since IsoStream is no longer internal to FileStream in CoreFX, it would then have to use the public constructors of FileStream. This would require a fair amount of rewriting to make IsoStream no longer contain its own FileStream copy but to instead delegate to the FileStream methods that it inherits. I'm not sure if this is even possible given the requirements that IsoStream has, and even if it were possible I'm not sure its what we want IsoStream to do since it would tether it more closely to FileStream rather than having it be its own entity.

ianhays avatar Jun 02 '16 17:06 ianhays

Thanks Eric!

@niemyjski Could you provide more information on how the FileStream->Stream change broke your API signature i.e. in what way were you relying on the IsoStream?

Changing the IsoStream to inherit from FileStream would require some major changes both to the IsoStream implementation as well as to FileStream since the internal zero-arg FileStream constructor is no longer an option. It's unlikely that any such changes to FileStream would be worth it to fix the IsoStream compat since that would then break FileStream compat by introducing new API. For now I'm going to move this back to 1.1.0.

ianhays avatar Jun 02 '16 18:06 ianhays

We have public interfaces that people can have custom implementations for storage and he like and this changed our Api signature from using file streams to stream... People will need to update there code after upgrading our nuget package..

Also the name of the class should have changed after the base class change as per the frameworks guidelines..

Finally, wouldn't we want those iso security features (sandboxing)

niemyjski avatar Jun 03 '16 02:06 niemyjski

We have public interfaces that people can have custom implementations for storage and he like and this changed our Api signature from using file streams to stream... People will need to update there code after upgrading our nuget package..

We shipped IsoStream for UWP inheriting from Stream, so from a compat perspective we're going to be modifying behavior regardless. Since the CoreFX IsoStream is there entirely for back-compat (i.e. is legacy support) for UWP, it makes a bit more sense imo to maintain API parity with that over full .NET. In fact, IsoStream is only included right now for WinRT. @danmosemsft

Also the name of the class should have changed after the base class change as per the frameworks guidelines..

Wouldn't changing the name introduce more compat issues? What about people that are using the type but don't depend on the FileStream inheritance? Then instead of impacting a subset of IsoStream users, we'll be impacting all of them.

Finally, wouldn't we want those iso security features (sandboxing)

How would inheriting from Stream instead of FileStream affect sandboxing?

ianhays avatar Jun 06 '16 19:06 ianhays

I'm going to close this for now. We can revisit it in the future once/if we get more feedback on the API change.

ianhays avatar Jun 27 '16 19:06 ianhays