AvianFlu / ncp

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

Can't copy on windows #106

Closed zombieJ closed 8 years ago

zombieJ commented 8 years ago

Add some console on that:

  function copyFile(file, target) {
    var readStream = fs.createReadStream(file.name),
        writeStream = fs.createWriteStream(target, { mode: file.mode });

    readStream.on('error', function () {
        console.log("Read Err:", arguments);
    });
    writeStream.on('error', function () {
        console.log("Write Err:", arguments);
    });
    writeStream.on('close', function () {
        console.log("Write Close:", arguments);
    });

    if(transform) {
      transform(readStream, writeStream, file);
    } else {
      writeStream.on('open', function() {
          console.log("Open:", file.mode, file.name, target);
        readStream.pipe(writeStream);
      });
    }
    writeStream.once('finish', function() {
        console.log("done", target);
        if (modified) {
            //target file modified date sync.
            fs.utimesSync(target, file.atime, file.mtime);
            cb();
        }
        else cb();
    });
  }

console.log('open') works and other console not trigger. Create 0 size file. I'm not sure whether is a nodeJS bug?

zombieJ commented 8 years ago

Find the reason. Using mocha will call process.exit which will force close the process and let the copy process stopped.