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
Use Directory.EnumerateFiles
instead of Directory.GetFiles
in WhichUtil.
#2882
Conversation
@@ -69,6 +69,8 @@ public static class Runner | |||
public static readonly OSPlatform Platform = OSPlatform.OSX; | |||
#elif OS_WINDOWS | |||
public static readonly OSPlatform Platform = OSPlatform.Windows; | |||
#else | |||
public static readonly OSPlatform Platform = OSPlatform.Linux; |
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.
add a #else
to provide default value, so VSCode won't barking on us.
@@ -79,6 +81,8 @@ public static class Runner | |||
public static readonly Architecture PlatformArchitecture = Architecture.Arm; | |||
#elif ARM64 | |||
public static readonly Architecture PlatformArchitecture = Architecture.Arm64; | |||
#else | |||
public static readonly Architecture PlatformArchitecture = Architecture.X64; |
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.
same, help vscode a little bit...
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.
This makes sense and I'm happy to +1 it.
Rather than defaulting to X64 in this case, is it possible to, like, raise an error of some kind if we can't determine the system architecture? As a future developer, I'd rather see a compile-time error than have the preprocessor silently assume I'm on X64 when I'm not.
(I'm far from a C# preprocessor expert, so I'll defer to your judgment here and +1 whatever you think is best.)
[Fact] | ||
[Trait("Level", "L0")] | ||
[Trait("Category", "Common")] | ||
public void UseWhich2FindGit() |
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.
these tests are copy paste all existing tests but change Which()
to Which2()
{ | ||
try | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(pathSegment, command)) |
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.
GetFiles
changed to EnumerateFiles
searchPattern = StringUtil.Format($"{command}.*"); | ||
try | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(pathSegment, searchPattern)) |
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.
GetFiles
changed to EnumerateFiles
#else | ||
try | ||
{ | ||
foreach (var file in Directory.EnumerateFiles(pathSegment, command)) |
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.
GetFiles
changed to EnumerateFiles
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.
Left a minor comment. Overall +1! To me—someone who's only just literate in C#—it makes sense.
1bd3712
to
34d206a
Compare
Directory.GetFiles
will return only after all search finish.Directory.EnumerateFiles
will return file as they been found, so we can process them immediately.We introduce
Which2()
in addition toWhich()
, and the usage ofWhich2()
is controlled by feature flag.After we verify the new
Which2()
is functional properly, we can switch all the code path to useWhich2()
https://github.com/github/c2c-actions-support/issues/2902