AvianFlu / ncp

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

Clobber mode issue #64

Open redgecombe opened 9 years ago

redgecombe commented 9 years ago

There seems to be an issue copying a directory over another directory using clobber mode. I am finding that intermittently the completion callback is never triggered.

I did a little digging and saw that the "running" count becomes negative in my case.

I think the issue is in the onFile function here:

      if(clobber) {
        rmFile(target, function () {
          copyFile(file, target);
        });
      }
      if (modified) {
        var stat = dereference ? fs.stat : fs.lstat;
        stat(target, function(err, stats) {
            //if souce modified time greater to target modified time copy file
            if (file.mtime.getTime()>stats.mtime.getTime())
                copyFile(file, target);
            else return cb();
        });
      }

If clobber is true, there can be two calls to copyFile, eventually causing two calls to cb, resulting in the started/finished/running counts getting out of sync. I think this is related to this change: https://github.com/AvianFlu/ncp/commit/85cd50a5736f009cb2b50ac2a090542eb27b7e9c

Thanks

coderaiser commented 9 years ago

Fixed in #68.