-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Unify BufferedFileStreamStrategy seeking #78984
Conversation
Tagging subscribers to this area: @dotnet/area-system-io |
src/libraries/System.Private.CoreLib/src/System/IO/Strategies/BufferedFileStreamStrategy.cs
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephentoub thanks for pointing this out. To answer your question I've studied our code and realized that most likely this setter is never executed?
FileStream.Postion = value
is calling _strategy.Seek
instead _strategy.Position = value
.
runtime/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
Lines 484 to 492 in 843441e
set | |
{ | |
if (value < 0) | |
{ | |
ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.value, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); | |
} | |
_strategy.Seek(value, SeekOrigin.Begin); | |
} |
My guess is that we are doing so because we actually want it to throw for closed or non-seekable files the same way we do for the getter:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/FileStream.cs
Lines 469 to 482 in 843441e
public override long Position | |
{ | |
get | |
{ | |
if (_strategy.IsClosed) | |
{ | |
ThrowHelper.ThrowObjectDisposedException_FileClosed(); | |
} | |
else if (!CanSeek) | |
{ | |
ThrowHelper.ThrowNotSupportedException_UnseekableStream(); | |
} | |
return _strategy.Position; |
@pedrobsaila I encourage you to refactor both FileStream.Position { set; }
and BufferedFileStreamStrategy.Position { set; }
.
If you can simplify the code and avoid similar confusions, we are going to merge the refactor.
Thank you for working on this and apologies for the confusion, I should have done better research when I was creating the issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pedrobsaila thank you for your contribution and appologies for the delay in the review.
I am going to clone your fork and push some minor fixes to it to save the time and get the PR merged today.
Fixes #78457