-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
move File.Exists and File.ReadAllBytes to Common #53168
Conversation
…tion and implementation differences
Tagging subscribers to this area: @carlossanlop Issue DetailsI wanted to start working on and then I realized that we have a copy of runtime/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs Lines 10 to 16 in d1a0a20
The problem is that it was not kept in sync. The differences:
I moved it to
|
CoreLib uses these two APIs for specific purpose where we do not need any of this. You can add a comment to CoreLib copy that this is missing instead of increasing the amount of duplicated code. Instead of this, it may be better to fold System.IO.FileSystem into CoreLib (contributes to #2138). @marek-safar asked me about it a while ago. System.IO.FileSystem has a dependency on Linq that would need to be cleaned up before it can be done. |
We still have the code duplicated in binaries, and more of it than before. |
@jkotas I like the idea of folding |
@jkotas Why move the whole FileSystem namespace to CoreLib? If Linq has dependencies to FileSystem types, can't we instead move only the types that are needed? For example, I'm interested in knowing the reasoning to move the whole namespace. cc @ericstj |
I think that the file and directory enumeration APIs that exist in System.IO.FileSystem.dll really belong to CoreLib. Note that we have a parallel implementation of file and directory enumeration APIs in CoreCLR PAL (https://github.com/dotnet/runtime/blob/main/src/coreclr/pal/src/file/find.cpp). We are not able to do C# rewrite of the logic that depends on these since the managed file and directory enumeration APIs do not live in CoreLib. Once we move the the managed file and directory enumeration APIs to CoreLib, we will be one stop closer to be able to rewrite a bunch more runtime code in C#.
Use of Linq in System.IO as anti-pattern. We try to avoid use Linq at the lower levels of the stack since it has large performance overhead. I would be good to get rid of Linq in System.IO regardless. |
I wanted to start working on
File.OpenHandle
which is part of #24847 (comment)and then I realized that we have a copy of
File.Exists
andFile.ReadAllBytes
inSystem.Private.CoreLib
which was promised to keep in sync withSystem.File.IO
:runtime/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs
Lines 10 to 16 in d1a0a20
The problem is that it was not kept in sync. The differences:
TrimEndingDirectorySeparator
forFile.Exists
File.ReadAllBytes
:I moved it to
Common
so we have a single implementation and no code duplication now.