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

Use Directory.EnumerateFiles instead of Directory.GetFiles in WhichUtil. #2882

Merged
merged 3 commits into from Sep 26, 2023

Conversation

TingluoHuang
Copy link
Member

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 to Which(), and the usage of Which2() is controlled by feature flag.

After we verify the new Which2() is functional properly, we can switch all the code path to use Which2()

https://github.com/github/c2c-actions-support/issues/2902

@TingluoHuang TingluoHuang requested a review from a team as a code owner September 25, 2023 22:20
@@ -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;
Copy link
Member Author

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;
Copy link
Member Author

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...

Copy link
Member

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()
Copy link
Member Author

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))
Copy link
Member Author

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))
Copy link
Member Author

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))
Copy link
Member Author

Choose a reason for hiding this comment

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

GetFiles changed to EnumerateFiles

Copy link
Member

@pje pje left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants