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

Commit

Permalink
Merge in @refaelos excludeHidden && excludeHiddenUnix patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan McGrath committed Nov 9, 2012
2 parents 5119852 + 658589c commit 6c90fc6
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/wrench.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
72 changes: 72 additions & 0 deletions tests/copydirsync_unix.js
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@

module.exports = {
group_mkdir: require('./mkdir'),
group_readdir: require('./readdir')
group_readdir: require('./readdir'),
group_copydir: require('./copydirsync_unix')
};
Empty file added tests/shown/.hidden.txt
Empty file.
Empty file added tests/shown/.hidden/dolor.md
Empty file.
Empty file added tests/shown/bar.txt
Empty file.
Empty file added tests/shown/foo/bar/ipsum.js
Empty file.
Empty file added tests/shown/foo/dolor.md
Empty file.
Empty file added tests/shown/foo/lorem.txt
Empty file.

0 comments on commit 6c90fc6

Please sign in to comment.