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

root search pattern for hashfiles #151

Merged
merged 4 commits into from
Oct 29, 2019
Merged

Conversation

ericsciple
Copy link
Collaborator

@ericsciple ericsciple commented Oct 28, 2019

fixes issue #146 and #154

Copy link
Member

@TingluoHuang TingluoHuang left a comment

Choose a reason for hiding this comment

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

thanks...

Copy link
Contributor

@dakale dakale left a comment

Choose a reason for hiding this comment

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

LGTM

@thboop
Copy link
Collaborator

thboop commented Oct 28, 2019

lgtm

@@ -28,9 +29,26 @@ internal sealed class HashFiles : Function
string searchRoot = workspaceData.Value;
string pattern = Parameters[0].Evaluate(context).ConvertToString();

// Convert slashes on Windows
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the PR. Simply rooting the path caused issues on Windows.

Now i've also added code to treat \ and / equivalent on Windows. This is consistent with the updated ADR.

var files = Directory.GetFiles(searchRoot, "*", SearchOption.AllDirectories).OrderBy(x => x).ToList();
var files = Directory.GetFiles(searchRoot, "*", SearchOption.AllDirectories)
.Select(x => s_isWindows ? x.Replace('\\', '/') : x)
.OrderBy(x => x, StringComparer.Ordinal)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I spent time thinking about the default comparer, current culture vs ordinal. Even though i eventually realized the default is ordinal here (iirc), i went ahead and specified ordinal explicitly so it's now obvious to the reader that the author thought about it.

if (files.Count == 0)
{
throw new ArgumentException($"'hashFiles({pattern})' failed. Directory '{searchRoot}' is empty");
throw new ArgumentException($"hashFiles('{ExpressionUtility.StringEscape(pattern)}') failed. Directory '{searchRoot}' is empty");
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

better error message so the syntax doesnt look malformed

@@ -83,12 +106,14 @@ internal sealed class HashFiles : Function
}
}

private static readonly bool s_isWindows = Environment.OSVersion.Platform != PlatformID.Unix && Environment.OSVersion.Platform != PlatformID.MacOSX;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

used in multiple places now, so moved to private field

Copy link
Collaborator

@thboop thboop left a comment

Choose a reason for hiding this comment

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

Clean LGTM

@thboop
Copy link
Collaborator

thboop commented Oct 29, 2019

We can/should cherry-pick this directly into releases/m160 as well

@ericsciple ericsciple merged commit 51581ac into master Oct 29, 2019
@ericsciple ericsciple deleted the users/ersciple/m161root branch October 29, 2019 17:23
ericsciple added a commit that referenced this pull request Oct 30, 2019
* Update dotnet install script (#155)

* root search pattern for hashfiles and allow forward slash on windows (#151)
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.

5 participants