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

Fix multiple calls to callback when overwriting files #77

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jfremy
Copy link

@jfremy jfremy commented Jan 16, 2015

The logic when overwriting a file seems wrong. If you look at the code path, if clobber is true and modified is false, then there will be a systematic call to cb in the last else statement of onFile.

I've seen the bug in an app of mine that uses ncp but it was hard to trigger and all your unit tests passed.
So I added an additional sanity check in the cb handler that verifies that running is postive or zero and that finished is lower or equal to started.
After doing that, your tests would nearly all fails because of multiple calls to done => which means that one of those invalid situations happened while with the fix in inFile it does work.

@@ -254,6 +254,15 @@ function ncp (source, dest, options, callback) {
function cb(skipped) {
if (!skipped) running--;
finished++;
if(running < 0 || finished > started) {

Choose a reason for hiding this comment

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

good idea, this will help catch other mis-matches

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.

None yet

2 participants