Comparing version 0.2.0 to 0.3.0
@@ -124,2 +124,21 @@ /* | ||
var copyFile = function(from, to, callback) { | ||
var dir = path.dirname(to); | ||
mkdirp(dir, function() { | ||
var fromFile = fs.createReadStream(from), | ||
toFile = fs.createWriteStream(to), | ||
err, | ||
onError = function (e) { | ||
err = e; | ||
}; | ||
fromFile.on('error', onError); | ||
toFile.on('error', onError); | ||
fromFile.once('end', function() { | ||
callback(); | ||
}); | ||
fromFile.pipe(toFile); | ||
}); | ||
}; | ||
var createFiles = function(files, to, options, callback) { | ||
@@ -137,28 +156,20 @@ var next = process.nextTick, | ||
to = options.toHash[from], | ||
dir = path.dirname(to); | ||
bail; | ||
if (!from) { | ||
return check(); | ||
} | ||
mkdirp(dir, function() { | ||
var fromFile = fs.createReadStream(from), | ||
toFile = fs.createWriteStream(to), | ||
bail, | ||
onError = function (err) { | ||
if (/EMFILE/.test(err)) { | ||
bail = true; | ||
files.push(from); | ||
} else if (err) { | ||
options.errors.push(err); | ||
} | ||
}; | ||
fromFile.on('error', onError); | ||
toFile.on('error', onError); | ||
fromFile.pipe(toFile); | ||
fromFile.once('end', function() { | ||
if (!bail) { | ||
complete++; | ||
} | ||
next(copy); | ||
}); | ||
copyFile(from, to, function(err) { | ||
/*istanbul ignore next*/ | ||
//This shouldn't happen with graceful-fs, but just in case | ||
if (/EMFILE/.test(err)) { | ||
bail = true; | ||
files.push(from); | ||
} else if (err) { | ||
options.errors.push(err); | ||
} | ||
/*istanbul ignore next*/ | ||
if (!bail) { | ||
complete++; | ||
} | ||
next(copy); | ||
}); | ||
@@ -189,2 +200,3 @@ }; | ||
fs.stat(file, stack.add(function(err, stat) { | ||
/*istanbul ignore next*/ | ||
if (err) { | ||
@@ -241,4 +253,7 @@ errors.push(err); | ||
} else { | ||
/*istanbul ignore next*/ | ||
err = new Error('Unable to copy directory' + (out.length ? ' entirely' : '')); | ||
/*istanbul ignore next*/ | ||
err.list = options.errors; | ||
/*istanbul ignore next*/ | ||
callback(err, out.sort()); | ||
@@ -255,3 +270,3 @@ } | ||
if (err) { | ||
return callback(new Error('From should be a directory')); | ||
return callback(new Error('From should be a file or directory')); | ||
} | ||
@@ -268,3 +283,6 @@ if (stat && stat.isDirectory()) { | ||
} else { | ||
callback(new Error('From should be a directory')); | ||
if (stat.isFile()) { | ||
return copyFile(options.from, path.join(to, path.basename(options.from)), callback); | ||
} | ||
callback(new Error('From should be a file or directory')); | ||
} | ||
@@ -271,0 +289,0 @@ }); |
@@ -5,3 +5,3 @@ { | ||
"author": "Dav Glass <davglass@gmail.com>", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"dependencies": { | ||
@@ -8,0 +8,0 @@ "graceful-fs": "~1.2.0", |
@@ -170,2 +170,43 @@ var vows = require('vows'), | ||
}, | ||
'and should copy minimatch from bad filter': { | ||
topic: function() { | ||
var out = path.join(to, '4'), | ||
self = this; | ||
this.outDir = out; | ||
cpr(from, out, { | ||
confirm: true, | ||
deleteFirst: true, | ||
filter: 'bs content' | ||
}, function(err, status) { | ||
var t = { | ||
status: status, | ||
dirs: { | ||
from: fs.readdirSync(path.join(from, 'jshint/node_modules')).sort(), | ||
to: fs.readdirSync(path.join(out, 'jshint/node_modules')).sort() | ||
} | ||
}; | ||
self.callback(err, t); | ||
}); | ||
}, | ||
'and has ./out/4': function(topic) { | ||
var stat = fs.statSync(this.outDir); | ||
assert.ok(stat.isDirectory()); | ||
}, | ||
'and dirs are not equal': function(topic) { | ||
assert.deepEqual(topic.dirs.to, topic.dirs.from); | ||
}, | ||
'and from directory has minimatch dir': function(topic) { | ||
var fromHasGFS = topic.dirs.from.some(function(item) { | ||
return (item === 'minimatch'); | ||
}); | ||
assert.isTrue(fromHasGFS); | ||
}, | ||
'and to directory does have minimatch dir': function(topic) { | ||
var toHasGFS = topic.dirs.to.some(function(item) { | ||
return (item === 'minimatch'); | ||
}); | ||
assert.isTrue(toHasGFS); | ||
} | ||
}, | ||
'and should copy node_modules with overwrite flag': { | ||
@@ -228,9 +269,9 @@ topic: function() { | ||
assert(topic.err instanceof Error); | ||
assert.equal('From should be a directory', topic.err.message); | ||
assert.equal('From should be a file or directory', topic.err.message); | ||
} | ||
}, | ||
"should fail on from not a dir": { | ||
"should fail on non-file": { | ||
topic: function() { | ||
var self = this; | ||
cpr(__filename, path.join(to, 'does/not/matter'), function(err, status) { | ||
cpr('/dev/null', path.join(to, 'does/not/matter'), function(err, status) { | ||
self.callback(null, { | ||
@@ -245,4 +286,16 @@ err: err, | ||
assert(topic.err instanceof Error); | ||
assert.equal('From should be a directory', topic.err.message); | ||
assert.equal('From should be a file or directory', topic.err.message); | ||
} | ||
}, | ||
"should copy one file": { | ||
topic: function() { | ||
cpr(__filename, path.join(to, 'one-file-test/'), this.callback); | ||
}, | ||
"should copy one file": function(topic) { | ||
assert.isUndefined(topic); | ||
}, | ||
'has ./out/one-file-test/full.js': function(topic) { | ||
var stat = fs.statSync(path.join(to, 'one-file-test/full.js')); | ||
assert.ok(stat.isFile()); | ||
}, | ||
} | ||
@@ -249,0 +302,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
25631
586