Skip to content

fix: maxdepth doesn't limit total number of copies#549

Merged
freitagbr merged 2 commits intomasterfrom
fix-cp-limit
Nov 10, 2016
Merged

fix: maxdepth doesn't limit total number of copies#549
freitagbr merged 2 commits intomasterfrom
fix-cp-limit

Conversation

@nfischer
Copy link
Copy Markdown
Member

@nfischer nfischer commented Nov 5, 2016

Prevent maxdepth from limiting the total number of copies, only allow it to
limit the maximum depth

Fixes #547

Prevent maxdepth from limiting the total number of copies, only allow it to
limit the maximum depth

Fixes #547
@nfischer nfischer added the fix Bug/defect, or a fix for such a problem label Nov 5, 2016
@nfischer nfischer added this to the v0.7.x milestone Nov 5, 2016
@nfischer
Copy link
Copy Markdown
Member Author

nfischer commented Nov 5, 2016

Apparently the maxdepth feature added in #232 wasn't implemented correctly. It was compared against the total number of calls to the function, not to the depth of the function call stack. We incremented the value, but we forgot to decrement it. Because objects in JS are pass-by-reference, all invocations of the function reference the same depth counter.

@nfischer
Copy link
Copy Markdown
Member Author

nfischer commented Nov 7, 2016

@freitagbr will you have time to review in the next couple days? If not, I can merge myself.

@freitagbr
Copy link
Copy Markdown
Contributor

Yes, I will review this soon.

@nfischer
Copy link
Copy Markdown
Member Author

@freitagbr changes are finished

opts.depth++;
// Ensure there is not a run away recursive copy
if (currentDepth >= common.config.maxdepth) return;
currentDepth++;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Well, ok. I was thinking that depth would be the last function parameter, so that you wouldn't have to explicitly call cpdirSyncRecursive with it. To initialize the depth:

if (!depth) depth = 0;

just like we initialize opts. Then you can depth++ or call cpdirSyncRecursive(..., depth + 1), whichever you think is clearer.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As for the order, I usually leave options as the final parameter. cpdirSyncRecursive is totally internal, so requiring the depth parameter isn't so awful.

If we allow depth and opts to both be optional, then we have to account for the case when depth is missing but opts isn't, and vice-versa. Sounds very bug-prone to me, for very little external benefit.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, I can see that. As long as it's internal, it shouldn't be a problem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok, just give it an LGTM when ready to merge

@freitagbr
Copy link
Copy Markdown
Contributor

LGTM

@nfischer
Copy link
Copy Markdown
Member Author

LGTM (forgot that you don't have lgtm permission yet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug/defect, or a fix for such a problem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants