Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
Merge pull request #42 from smucode/master
Browse files Browse the repository at this point in the history
Null check in copyDirSyncRecursive
  • Loading branch information
Ryan McGrath committed Nov 16, 2012
2 parents 32c2af7 + 5e80ff9 commit 080761c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/wrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions tests/copydirsync_unix.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 080761c

Please sign in to comment.