From a2cac1647d521af8f863b56904b08abac4389004 Mon Sep 17 00:00:00 2001 From: refaelos Date: Mon, 15 Oct 2012 14:53:42 +0200 Subject: [PATCH 1/4] not copying hidden files/folders --- lib/wrench.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/wrench.js b/lib/wrench.js index 00f4166..38eec08 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -183,6 +183,8 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { var files = fs.readdirSync(sourceDir); for(var i = 0; i < files.length; i++) { + if (/^\./.test(files[i])) continue; + var currFile = fs.lstatSync(sourceDir + "/" + files[i]); if(currFile.isDirectory()) { From c2674863e9547df5f874d4a43c2b1f920b9c31eb Mon Sep 17 00:00:00 2001 From: refaelos Date: Mon, 15 Oct 2012 14:59:06 +0200 Subject: [PATCH 2/4] added excludeHidden flag --- lib/wrench.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/wrench.js b/lib/wrench.js index 38eec08..18fa706 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -183,7 +183,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { var files = fs.readdirSync(sourceDir); for(var i = 0; i < files.length; i++) { - if (/^\./.test(files[i])) continue; + if (opts.excludeHidden && /^\./.test(files[i])) continue; var currFile = fs.lstatSync(sourceDir + "/" + files[i]); From 8097eb52bdb596cbac488e80430df1a8f2f84b62 Mon Sep 17 00:00:00 2001 From: refaelos Date: Mon, 15 Oct 2012 15:33:36 +0200 Subject: [PATCH 3/4] added tests --- tests/copydirsync_unix.js | 72 ++++++++++++++++++++++++++++++++++++ tests/runner.js | 3 +- tests/shown/.hidden.txt | 0 tests/shown/.hidden/dolor.md | 0 tests/shown/bar.txt | 0 tests/shown/foo/bar/ipsum.js | 0 tests/shown/foo/dolor.md | 0 tests/shown/foo/lorem.txt | 0 8 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/copydirsync_unix.js create mode 100644 tests/shown/.hidden.txt create mode 100644 tests/shown/.hidden/dolor.md create mode 100644 tests/shown/bar.txt create mode 100644 tests/shown/foo/bar/ipsum.js create mode 100644 tests/shown/foo/dolor.md create mode 100644 tests/shown/foo/lorem.txt diff --git a/tests/copydirsync_unix.js b/tests/copydirsync_unix.js new file mode 100644 index 0000000..d8e85db --- /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, { excludeHidden: 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, { excludeHidden: 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 From 658589c35e9d10ffb6b6096e222820519a6541b0 Mon Sep 17 00:00:00 2001 From: refaelos Date: Mon, 15 Oct 2012 15:35:43 +0200 Subject: [PATCH 4/4] changed excludeHidden to excludeHiddenUnix b/c the testing for hidden file is only applicable for unix --- lib/wrench.js | 2 +- tests/copydirsync_unix.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/wrench.js b/lib/wrench.js index 18fa706..13514d0 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -183,7 +183,7 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) { var files = fs.readdirSync(sourceDir); for(var i = 0; i < files.length; i++) { - if (opts.excludeHidden && /^\./.test(files[i])) continue; + if (opts.excludeHiddenUnix && /^\./.test(files[i])) continue; var currFile = fs.lstatSync(sourceDir + "/" + files[i]); diff --git a/tests/copydirsync_unix.js b/tests/copydirsync_unix.js index d8e85db..59949a8 100644 --- a/tests/copydirsync_unix.js +++ b/tests/copydirsync_unix.js @@ -40,7 +40,7 @@ module.exports = testCase({ test.ok(path.existsSync(dir), 'Folders should exist'); wrench.mkdirSyncRecursive(testdir, 0777); - wrench.copyDirSyncRecursive(dir, testdir, { excludeHidden: false }); + wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: false }); var files = wrench.readdirSyncRecursive(testdir); @@ -57,7 +57,7 @@ module.exports = testCase({ test.ok(path.existsSync(dir), 'Folders should exist'); wrench.mkdirSyncRecursive(testdir, 0777); - wrench.copyDirSyncRecursive(dir, testdir, { excludeHidden: true }); + wrench.copyDirSyncRecursive(dir, testdir, { excludeHiddenUnix: true }); var files = wrench.readdirSyncRecursive(testdir);