-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Conversation
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.
thanks...
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.
LGTM
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 |
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.
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) |
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.
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"); |
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.
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; |
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.
used in multiple places now, so moved to private field
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.
Clean LGTM
We can/should cherry-pick this directly into |
fixes issue #146 and #154