AvianFlu / ncp

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

Copying a directory containing a set of directories #51

Open dimapaloskin opened 9 years ago

dimapaloskin commented 9 years ago

Hi.

I encountered the following problem. If you copy a directory containing a number of other directories ncp stops responding. This bug works on ubuntu and does not work on os x.

I think this is due to the fact that adding a directory in turn "running" variable increases, but the function of CB may not be started, because "function cb(skipped)" running only with files.

On my computer at work, I rewrote this section so: before

function getStats(source) {
    var stat = dereference ? fs.stat : fs.lstat;
    if (running >= limit) {
      return defer(function () {
        getStats(source);
      });
    }
    running++;
    stat(source, function (err, stats) {
      var item = {};
      if (err) {
        return onError(err);
      }

after

function getStats(source) {
    var stat = dereference ? fs.stat : fs.lstat;

    stat(source, function (err, stats) {
      var item = {};
      if (err) {
        return onError(err);
      }
      if (stats.isFile() && running >= limit) {
         return defer(function () {
           getStats(source);
         });
      }
      running++;

Your thoughts on this subject?