Comparing version 0.2.5 to 0.2.6
@@ -26,7 +26,7 @@ var fs = require('fs'), | ||
function startCopy(item) { | ||
function startCopy(source) { | ||
started++; | ||
if (filter) { | ||
if (filter instanceof RegExp) { | ||
if (!filter.test(item)) { | ||
if (!filter.test(source)) { | ||
return cb(true); | ||
@@ -36,3 +36,3 @@ } | ||
else if (typeof filter === 'function') { | ||
if (!filter(item)) { | ||
if (!filter(source)) { | ||
return cb(true); | ||
@@ -42,16 +42,22 @@ } | ||
} | ||
return getStats(item); | ||
return getStats(source); | ||
} | ||
function getStats(item) { | ||
function getStats(source) { | ||
if (running >= limit) { | ||
return process.nextTick(function () { | ||
getStats(item); | ||
getStats(source); | ||
}); | ||
} | ||
running++; | ||
fs.lstat(item, function (err, stats) { | ||
fs.lstat(source, function (err, stats) { | ||
var item = {}; | ||
if (err) { | ||
return onError(err); | ||
} | ||
// We need to get the mode from the stats object and preserve it. | ||
item.name = source; | ||
item.mode = stats.mode; | ||
if (stats.isDirectory()) { | ||
@@ -64,3 +70,4 @@ return onDir(item); | ||
else if (stats.isSymbolicLink()) { | ||
return onLink(item); | ||
// Symlinks don't really need to know about the mode. | ||
return onLink(source); | ||
} | ||
@@ -71,3 +78,3 @@ }); | ||
function onFile(file) { | ||
var target = file.replace(currentPath, targetPath); | ||
var target = file.name.replace(currentPath, targetPath); | ||
isWritable(target, function (writable) { | ||
@@ -84,4 +91,4 @@ if (writable) { | ||
function copyFile(file, target) { | ||
var readStream = fs.createReadStream(file), | ||
writeStream = fs.createWriteStream(target); | ||
var readStream = fs.createReadStream(file.name), | ||
writeStream = fs.createWriteStream(target, { mode: file.mode }); | ||
readStream.pipe(writeStream); | ||
@@ -101,3 +108,3 @@ readStream.once('end', cb); | ||
function onDir(dir) { | ||
var target = dir.replace(currentPath, targetPath); | ||
var target = dir.name.replace(currentPath, targetPath); | ||
isWritable(target, function (writable) { | ||
@@ -107,3 +114,3 @@ if (writable) { | ||
} | ||
copyDir(dir, target); | ||
copyDir(dir.name); | ||
}); | ||
@@ -113,7 +120,7 @@ } | ||
function mkDir(dir, target) { | ||
fs.mkdir(target, 0755, function (err) { | ||
fs.mkdir(target, dir.mode, function (err) { | ||
if (err) { | ||
return onError(err); | ||
} | ||
copyDir(dir); | ||
copyDir(dir.name); | ||
}); | ||
@@ -210,4 +217,4 @@ } | ||
} | ||
} | ||
}; | ||
{ | ||
"name" : "ncp", | ||
"version" : "0.2.5", | ||
"version" : "0.2.6", | ||
"author": "AvianFlu <charlie@charlieistheman.com>", | ||
@@ -5,0 +5,0 @@ "description" : "Asynchronous recursive file copy utility.", |
@@ -13,24 +13,22 @@ var assert = require('assert'), | ||
vows.describe('ncp').addBatch({ | ||
'When using `ncp`': { | ||
'and copying files from one directory to another': { | ||
'When copying a directory of files': { | ||
topic: function () { | ||
var cb = this.callback; | ||
rimraf(out, function () { | ||
ncp(src, out, cb); | ||
}); | ||
}, | ||
'files should be copied': { | ||
topic: function () { | ||
var cb = this.callback; | ||
rimraf(out, function () { | ||
ncp(src, out, cb); | ||
readDirFiles(src, 'utf8', function (srcErr, srcFiles) { | ||
readDirFiles(out, 'utf8', function (outErr, outFiles) { | ||
cb(outErr, srcFiles, outFiles); | ||
}); | ||
}); | ||
}, | ||
'it should copy files': { | ||
topic: function () { | ||
var cb = this.callback; | ||
readDirFiles(src, 'utf8', function (srcErr, srcFiles) { | ||
readDirFiles(out, 'utf8', function (outErr, outFiles) { | ||
cb(outErr, srcFiles, outFiles); | ||
}); | ||
}); | ||
}, | ||
'and destination files should match source files': function (err, srcFiles, outFiles) { | ||
assert.isNull(err); | ||
assert.deepEqual(srcFiles, outFiles); | ||
} | ||
'and the destination should match the source': function (err, srcFiles, outFiles) { | ||
assert.isNull(err); | ||
assert.deepEqual(srcFiles, outFiles); | ||
} | ||
@@ -40,37 +38,35 @@ } | ||
}).addBatch({ | ||
'When using ncp': { | ||
'and copying files using filter': { | ||
topic: function() { | ||
'When copying files using filter': { | ||
topic: function() { | ||
var cb = this.callback; | ||
var filter = function(name) { | ||
return name.substr(name.length - 1) != 'a' | ||
} | ||
rimraf(out, function () { | ||
ncp(src, out, {filter: filter}, cb); | ||
}); | ||
}, | ||
'it should copy files': { | ||
topic: function () { | ||
var cb = this.callback; | ||
var filter = function(name) { | ||
return name.substr(name.length - 1) != 'a' | ||
} | ||
rimraf(out, function () { | ||
ncp(src, out, {filter: filter}, cb); | ||
}); | ||
}, | ||
'it should copy files': { | ||
topic: function () { | ||
var cb = this.callback; | ||
readDirFiles(src, 'utf8', function (srcErr, srcFiles) { | ||
function filter(files) { | ||
for (var fileName in files) { | ||
var curFile = files[fileName]; | ||
if (curFile instanceof Object) | ||
return filter(curFile); | ||
if (fileName.substr(fileName.length - 1) == 'a') | ||
delete files[fileName]; | ||
} | ||
readDirFiles(src, 'utf8', function (srcErr, srcFiles) { | ||
function filter(files) { | ||
for (var fileName in files) { | ||
var curFile = files[fileName]; | ||
if (curFile instanceof Object) | ||
return filter(curFile); | ||
if (fileName.substr(fileName.length - 1) == 'a') | ||
delete files[fileName]; | ||
} | ||
filter(srcFiles); | ||
readDirFiles(out, 'utf8', function (outErr, outFiles) { | ||
cb(outErr, srcFiles, outFiles); | ||
}); | ||
} | ||
filter(srcFiles); | ||
readDirFiles(out, 'utf8', function (outErr, outFiles) { | ||
cb(outErr, srcFiles, outFiles); | ||
}); | ||
}, | ||
'and destination files should match source files that pass filter': function (err, srcFiles, outFiles) { | ||
assert.isNull(err); | ||
assert.deepEqual(srcFiles, outFiles); | ||
} | ||
}); | ||
}, | ||
'and destination files should match source files that pass filter': function (err, srcFiles, outFiles) { | ||
assert.isNull(err); | ||
assert.deepEqual(srcFiles, outFiles); | ||
} | ||
@@ -77,0 +73,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12048
19
272
2