Skip to content

Commit

Permalink
Merge pull request #52 from xogeny/master
Browse files Browse the repository at this point in the history
This fixes (what I think) is a bug in copySync
  • Loading branch information
jprichardson committed Mar 1, 2014
2 parents 47b87c1 + 4eaf198 commit 0fd7588
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function copySync(src, dest, filter) {
if (!destExists) mkdir.mkdirsSync(dest);
var contents = fs.readdirSync(src);
contents.forEach(function (content) {
copySync(src + "/" + content, dest + "/" + content);
copySync(src + "/" + content, dest + "/" + content, filter);
});
}
}
36 changes: 36 additions & 0 deletions test/copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,42 @@ describe('fs-extra', function() {

done()
});
it("should should apply filter recursively", function(done) {
var FILES = 2,
src = path.join(DIR, 'src'),
dest = path.join(DIR, 'dest'),
filter = /0$/i,
i, j;
mkdir.sync(src);
for (i = 0; i < FILES; ++i)
testutil.createFileWithData(path.join(src, i.toString()), SIZE);
var subdir = path.join(src, 'subdir');
mkdir.sync(subdir);
for (i = 0; i < FILES; ++i)
testutil.createFileWithData(path.join(subdir, i.toString()), SIZE);
fs.copySync(src, dest, filter);
T(fs.existsSync(dest));
T(FILES>1);

for (i = 0; i < FILES; ++i) {
if (i==0) {
T(fs.existsSync(path.join(dest, i.toString())))
} else {
T(!fs.existsSync(path.join(dest, i.toString())))
}
};

var destSub = path.join(dest, 'subdir');
for (j = 0; j < FILES; ++j) {
if (j==0) {
T(fs.existsSync(path.join(destSub, j.toString())));
} else {
T(!fs.existsSync(path.join(destSub, j.toString())));
}
}

done()
});
describe("> when the destination dir does not exist", function() {
it("should create the destination directory and copy the file", function(done) {
var src = path.join(DIR, 'data/');
Expand Down

0 comments on commit 0fd7588

Please sign in to comment.