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

Add FileStreamOptions overloads #52720

Merged
merged 12 commits into from
Jun 10, 2021
Merged

Conversation

manandre
Copy link
Contributor

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented May 13, 2021

Tagging subscribers to this area: @carlossanlop
See info in area-owners.md if you want to be subscribed.

Issue Details

Closes #24698

/cc @Duranom @adamsitnik

Author: manandre
Assignees: -
Labels:

area-System.IO, new-api-needs-documentation

Milestone: -

@stephentoub stephentoub added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label May 25, 2021
@stephentoub
Copy link
Member

Thanks for the PR. The APIs need to be revisited in light of #24698 (comment).

@manandre manandre changed the title Add FileOptions overloads Add FileStreamOptions overloads May 28, 2021
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manandre big thanks for your contribution and apologies for the re-design of the APIs and merge conflicts. I've left some comments and suggestions, PTAL.

src/libraries/System.IO.FileSystem/tests/File/Open.cs Outdated Show resolved Hide resolved
src/libraries/System.IO.FileSystem/tests/File/Open.cs Outdated Show resolved Hide resolved
src/libraries/System.IO.FileSystem/tests/FileInfo/Open.cs Outdated Show resolved Hide resolved
src/libraries/System.IO.FileSystem/tests/FileInfo/Open.cs Outdated Show resolved Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated Show resolved Hide resolved
src/libraries/System.Runtime/ref/System.Runtime.cs Outdated Show resolved Hide resolved
src/libraries/System.Private.CoreLib/src/System/IO/File.cs Outdated Show resolved Hide resolved
manandre and others added 2 commits May 31, 2021 22:02
@manandre manandre requested a review from adamsitnik June 1, 2021 16:09
@adamsitnik adamsitnik removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jun 8, 2021
@adamsitnik adamsitnik added this to the 6.0.0 milestone Jun 8, 2021
@adamsitnik adamsitnik added this to In progress in System.IO - FileStream via automation Jun 8, 2021
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, big thanks for your help @manandre, and once again apologies for the inconvenience from our side

System.IO - FileStream automation moved this from In progress to Reviewer approved Jun 8, 2021
private static Stream ValidateArgsAndOpenPath(string path, Encoding encoding, int bufferSize)
{
ValidateArgs(path, encoding);
if (bufferSize <= 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to make this < rather than <= ? Or that'll be handled separately?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it should be handled separately in #53497

AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", true));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", true, Encoding.UTF8));
AssertExtensions.Throws<ArgumentException>(null, () => new StreamWriter("", Encoding.UTF8, new FileStreamOptions()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only see negative tests here for StreamReader/Writer. Are there tests that validate the ctors do what they're supposed to do when used correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fully agree they are missing, but I did not find any 'positive' test covering the existing constructors with path, FileMode, FileAccess, FileShare, bufferSize and FileOptions parameters.
Which type of tests do you expect here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which type of tests do you expect here?

I was primarily thinking about tests to validate that we're correctly passing through the arguments, e.g. that if you pass CustomEncoding as the encoding, that's actually what gets used by the writer.

@@ -42,6 +42,24 @@ protected override FileStream CreateFileStream(string path, FileMode mode, FileA
}
}

public class File_Open_str_fm_fa_fs_buffer_fo : FileStream_ctor_str_fm_fa_fs_buffer_fo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this test name correct? I thought the pattern was based on the arguments being accepted by the method, but these methods are all path,options rather than path,FileMode,FileAccess,FileShare,bufferSize,FileOptions.

Same for the subsequent change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have aligned these tests with the existing options-based test classes from FileStream.

const string Text = "This is some text for testing.";
string path = GetTestFilePath();

using (var writer = new StreamWriter(path, false, encoding))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect to see FileStreamOptions being used here (as this is the ctor you are adding in this PR)

@adamsitnik adamsitnik merged commit 8538436 into dotnet:main Jun 10, 2021
System.IO - FileStream automation moved this from Reviewer approved to Done Jun 10, 2021
@manandre manandre deleted the fileoptions-overloads branch June 10, 2021 06:17
@ghost ghost locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Development

Successfully merging this pull request may close these issues.

Add isAsync overload for Create/Open/etc.
3 participants