Skip to content

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

#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
Contributor

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
Contributor

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

3 participants