Skip to content
This repository
Browse code

added null check so copyDirSyncRecursive will work without passing opts

  • Loading branch information...
commit 5e80ff972c469f7347c7846a2ed25d69937a61bc 1 parent 32c2af7
Stig Murberg smucode authored

Showing 2 changed files with 10 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 2  lib/wrench.js
  2. +9 0 tests/copydirsync_unix.js
3  lib/wrench.js
@@ -164,7 +164,6 @@ exports.rmdirSyncRecursive = function(path, failSilent) {
164 164 * Note: Directories should be passed to this function without a trailing slash.
165 165 */
166 166 exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
167   -
168 167 if (!opts || !opts.preserve) {
169 168 try {
170 169 if(fs.statSync(newDirLocation).isDirectory()) exports.rmdirSyncRecursive(newDirLocation);
@@ -194,7 +193,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
194 193 var currFile = fs.lstatSync(sourceDir + "/" + files[i]);
195 194
196 195 var fCopyFile = function(srcFile, destFile) {
197   - if (opts.preserveFiles && fs.existsSync(destFile)) return;
  196 + if (typeof opts !== 'undefined' && opts.preserveFiles && fs.existsSync(destFile)) return;
198 197
199 198 var contents = fs.readFileSync(srcFile);
200 199 fs.writeFileSync(destFile, contents);
9 tests/copydirsync_unix.js
@@ -77,6 +77,15 @@ function checkResultOverwriteFiles(test, files) {
77 77 }
78 78
79 79 module.exports = testCase({
  80 + test_copyDirSyncRecursiveWithoutOptions: function(test) {
  81 + var dir = path.join(__dirname, 'shown');
  82 + var testdir = path.join(__dirname, 'testdir');
  83 +
  84 + wrench.copyDirSyncRecursive(dir, testdir);
  85 +
  86 + wrench.rmdirSyncRecursive(testdir);
  87 + test.done();
  88 + },
80 89 test_copyDirSyncRecursiveHidden: function(test) {
81 90 var dir = path.join(__dirname, 'shown');
82 91 var testdir = path.join(__dirname, 'testdir');

0 comments on commit 5e80ff9

Please sign in to comment.
Something went wrong with that request. Please try again.