diff --git a/lib/ncp.js b/lib/ncp.js index 96eed47..44c33c9 100644 --- a/lib/ncp.js +++ b/lib/ncp.js @@ -30,7 +30,7 @@ function ncp (source, dest, options, callback) { limit = (limit < 1) ? 1 : (limit > 512) ? 512 : limit; startCopy(currentPath); - + function startCopy(source) { started++; if (filter) { @@ -113,10 +113,10 @@ function ncp (source, dest, options, callback) { function copyFile(file, target) { var readStream = fs.createReadStream(file.name), writeStream = fs.createWriteStream(target, { mode: file.mode }); - + readStream.on('error', onError); writeStream.on('error', onError); - + if(transform) { transform(readStream, writeStream, file); } else { @@ -208,14 +208,17 @@ function ncp (source, dest, options, callback) { }); }); } - function makeLink(linkPath, target) { - fs.symlink(linkPath, target, function (err) { - if (err) { - return onError(err); - } - return cb(); - }); + fs.stat(linkPath, function(err, stat) { + if (err) + return onError(err) + fs.symlink(linkPath, target, stat.isFile() ? 'file' : 'dir', function (err) { + if (err) { + return onError(err); + } + return cb(); + }); + }) } function isWritable(path, done) { @@ -241,7 +244,7 @@ function ncp (source, dest, options, callback) { if (typeof errs.write === 'undefined') { errs.push(err); } - else { + else { errs.write(err.stack + '\n\n'); } return cb(); @@ -256,6 +259,4 @@ function ncp (source, dest, options, callback) { } } } -} - - +} \ No newline at end of file