Skip to content

[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

Merged
merged 4 commits into from
Nov 30, 2018

Conversation

rjmholt
Copy link
Contributor

@rjmholt rjmholt commented Nov 29, 2018

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

@rjmholt
Copy link
Contributor Author

rjmholt commented Nov 29, 2018

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

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}");
Copy link
Contributor Author

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

@rjmholt rjmholt Nov 29, 2018

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?

Copy link
Contributor

@rkeithhill rkeithhill left a 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)
Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

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

LGTM!

@rjmholt rjmholt merged commit c0d5f0f into PowerShell:master Nov 30, 2018
@rjmholt rjmholt deleted the fix-recursion-count-bug branch December 12, 2018 05:59
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