-
Notifications
You must be signed in to change notification settings - Fork 237
[Ignore] Fix recursion count bug #802
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
Conversation
In Diff Settings, select Hide whitespace changes to make this easier to review |
@@ -292,7 +292,9 @@ public IEnumerable<string> EnumeratePSFiles() | |||
return Enumerable.Empty<string>(); | |||
} | |||
|
|||
return this.RecursivelyEnumerateFiles(WorkspacePath); | |||
var foundFiles = new List<string>(); | |||
this.RecursivelyEnumerateFiles(WorkspacePath, ref foundFiles); |
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.
ref
isn't needed here, but I used it as a guide to the reader that this is effectively the result of the method.
// If we get too deep, keep processing but go no deeper | ||
if (currDepth >= recursionDepthLimit) | ||
{ | ||
this.logger.Write(LogLevel.Warning, $"Recursion depth limit hit for path {folderPath}"); |
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 message will be more accurate now
|
||
foreach (string subDir in subDirs) | ||
{ | ||
RecursivelyEnumerateFiles(subDir, ref foundFiles, currDepth + 1); |
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.
Thoughts on currDepth: currDepth + 1
in the last arg?
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
|
||
return; | ||
} | ||
catch (Exception e) when (e is SecurityException || e is UnauthorizedAccessException) |
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 don't have a better suggestion and think this is the right way to do it... but damn these catch statements take up a lot of space.
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.
If they start getting too wide I tend to wrap them like so:
catch (Exception e) when (e is SecurityException ||
e is UnauthorizedAccessException)
But I don't think this one is too wide.
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.
yeah I don't think it's too wide - I meant the 3 catches right after each other twice in this function.
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 don't like the repetition, but I think a function call around a lambda just to catch certain exceptions is a rather nasty abuse.
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.
(Would be more abstractable in a world where exceptions were returned as union types...)
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!
@rkeithhill Saw that I'd implemented the recursion depth checking incorrectly (I was checking the stack size, which included all the files in parent directories).
I've rewritten this in the simpler recursive function form, which should actually be more efficient (in some ways), although there are pros and cons.
The other thing I noticed tracing this is that we create files for everything in the
.git
directory. We should really implement a file-ignore config and make it default to all files beginning with.
or something.