AvianFlu / ncp

Asynchronous recursive file copying with Node.js.
MIT License
680 stars 103 forks source link

Fix multiple calls to callback when overwriting files #77

Open jfremy opened 9 years ago

jfremy commented 9 years ago

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.