Browse files

added null check so copyDirSyncRecursive will work without passing opts

  • Loading branch information...
1 parent 32c2af7 commit 5e80ff972c469f7347c7846a2ed25d69937a61bc @smucode smucode committed Nov 15, 2012
Showing with 10 additions and 2 deletions.
  1. +1 −2 lib/wrench.js
  2. +9 −0 tests/copydirsync_unix.js
View
3 lib/wrench.js
@@ -164,7 +164,6 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
* Note: Directories should be passed to this function without a trailing slash.
*/
exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
-
if (!opts || !opts.preserve) {
try {
if(fs.statSync(newDirLocation).isDirectory()) exports.rmdirSyncRecursive(newDirLocation);
@@ -194,7 +193,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
var fCopyFile = function(srcFile, destFile) {
- if (opts.preserveFiles && fs.existsSync(destFile)) return;
+ if (typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return;
var contents = fs.readFileSync(srcFile);
fs.writeFileSync(destFile, contents);
View
9 tests/copydirsync_unix.js
@@ -77,6 +77,15 @@ function checkResultOverwriteFiles(test, files) {
}
module.exports = testCase({
+ test_copyDirSyncRecursiveWithoutOptions: function(test) {
+ var dir = path.join(__dirname, 'shown');
+ var testdir = path.join(__dirname, 'testdir');
+
+ wrench.copyDirSyncRecursive(dir, testdir);
+
+ wrench.rmdirSyncRecursive(testdir);
+ test.done();
+ },
test_copyDirSyncRecursiveHidden: function(test) {
var dir = path.join(__dirname, 'shown');
var testdir = path.join(__dirname, 'testdir');

0 comments on commit 5e80ff9

Please sign in to comment.