diff --git a/lib/wrench.js b/lib/wrench.js index ce7acda..fe3b21d 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -187,9 +187,9 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { if(!opts.whitelist && opts.filter && files[i].match(opts.filter)) continue; // if opts.whitelist is true every file or directory which doesn't match opts.filter will be ignored if(opts.whitelist && opts.filter && !files[i].match(opts.filter)) continue; + if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue; var currFile = fs.lstatSync(sourceDir + "/" + files[i]); - if(currFile.isDirectory()) { /* recursion this thing right on back. */ exports.copyDirSyncRecursive(sourceDir + "/" + files[i], newDirLocation + "/" + files[i], opts); diff --git a/tests/copydirsync_unix.js b/tests/copydirsync_unix.js new file mode 100644 index 0000000..59949a8 --- /dev/null +++ b/tests/copydirsync_unix.js @@ -0,0 +1,72 @@ +var testCase = require('nodeunit').testCase; +var fs = require('fs'); +var wrench = require('../lib/wrench'); +var path = require('path'); + +function checkResultHidden(test, files) { + var check = [ + '.hidden', + '.hidden.txt', + 'bar.txt', + 'foo', + path.join('.hidden', 'dolor.md'), + path.join('foo', 'bar'), + path.join('foo', 'dolor.md'), + path.join('foo', 'lorem.txt'), + path.join('foo', 'bar', 'ipsum.js') + ]; + + test.deepEqual(files, check); +} + +function checkResultShown(test, files) { + var check = [ + 'bar.txt', + 'foo', + path.join('foo', 'bar'), + path.join('foo', 'dolor.md'), + path.join('foo', 'lorem.txt'), + path.join('foo', 'bar', 'ipsum.js') + ]; + + test.deepEqual(files, check); +} + +module.exports = testCase({ + test_copyDirSyncRecursiveHidden: function(test) { + var dir = path.join(__dirname, 'shown'); + var testdir = path.join(__dirname, 'testdir'); + + test.ok(path.existsSync(dir), 'Folders should exist'); + + wrench.mkdirSyncRecursive(testdir, 0777); + wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false }); + + var files = wrench.readdirSyncRecursive(testdir); + + checkResultHidden(test, files); + + wrench.rmdirSyncRecursive(testdir); + + test.done(); + }, + test_copyDirSyncRecursiveShown: function(test) { + var dir = path.join(__dirname, 'shown'); + var testdir = path.join(__dirname, 'testdir'); + + test.ok(path.existsSync(dir), 'Folders should exist'); + + wrench.mkdirSyncRecursive(testdir, 0777); + wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: true }); + + var files = wrench.readdirSyncRecursive(testdir); + + checkResultShown(test, files); + + wrench.rmdirSyncRecursive(testdir); + + test.done(); + } +}); + +// vim: et ts=4 sw=4 diff --git a/tests/runner.js b/tests/runner.js index a5cc8f7..8f90dae 100644 --- a/tests/runner.js +++ b/tests/runner.js @@ -3,5 +3,6 @@ module.exports = { group_mkdir: require('./mkdir'), - group_readdir: require('./readdir') + group_readdir: require('./readdir'), + group_copydir: require('./copydirsync_unix') }; diff --git a/tests/shown/.hidden.txt b/tests/shown/.hidden.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/shown/.hidden/dolor.md b/tests/shown/.hidden/dolor.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/shown/bar.txt b/tests/shown/bar.txt new file mode 100644 index 0000000..e69de29 diff --git a/tests/shown/foo/bar/ipsum.js b/tests/shown/foo/bar/ipsum.js new file mode 100644 index 0000000..e69de29 diff --git a/tests/shown/foo/dolor.md b/tests/shown/foo/dolor.md new file mode 100644 index 0000000..e69de29 diff --git a/tests/shown/foo/lorem.txt b/tests/shown/foo/lorem.txt new file mode 100644 index 0000000..e69de29