new options: 'preserveFiles' and 'inflateSymlinks' #38

Merged
refaelos merged 2 commits from master into master 2012-11-10 17:32:55 -08:00
5 changed files with 19 additions and 8 deletions
Showing only changes of commit fcc6760b11 - Show all commits

View file

@ -183,8 +183,12 @@ exports.copyDirSyncRecursive = function(sourceDir, newDirLocation, opts) {
var files = fs.readdirSync(sourceDir);
for(var i = 0; i < files.length; i++) {
// ignores all files or directories which match the RegExp in opts.filter
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]);
var fCopyFile = function(srcFile, destFile) {
@ -289,7 +293,7 @@ exports.rmdirRecursive = function rmdirRecursive(dir, clbk){
return fs.rmdir(dir, clbk);
var file = dir+'/'+filename;
fs.stat(file, function(err, stat){
fs.lstat(file, function(err, stat){
if (err) return clbk(err);
if (stat.isDirectory())
rmdirRecursive(file, rmFile);
@ -384,6 +388,10 @@ exports.LineReader = function(filename, bufferSize) {
};
exports.LineReader.prototype = {
close: function() {
return fs.closeSync(this.fd);
},
getBufferAndSetCurrentPosition: function(position) {
var res = fs.readSync(this.fd, this.bufferSize, position, "ascii");

View file

@ -1,7 +1,7 @@
{
"name": "wrench",
"description": "Recursive filesystem (and other) operations that Node *should* have.",
"version": "1.3.9",
"version": "1.4.0",
"author": "Ryan McGrath <ryan@venodesigns.net>",
"repository": {

View file

@ -45,6 +45,10 @@ var f = new wrench.LineReader('x.txt');
while(f.hasNextLine()) {
util.puts(x.getNextLine());
}
// Note: You will need to close that above line reader at some point, otherwise
// you will run into a "too many open files" error. f.close() or fs.closeSync(f.fd) are
// your friends, as only you know when it is safe to close.
```
### Asynchronous operations
@ -54,7 +58,6 @@ var files = [];
wrench.readdirRecursive('my_directory_name', function(error, curFiles) {
// curFiles is what you want
});
```
Questions, comments? Hit me up. (ryan [at] venodesigns.net | http://twitter.com/ryanmcgrath)

View file

@ -7,11 +7,11 @@ module.exports = testCase({
test_mkdirSyncRecursive: function(test) {
var dir = __dirname + '/_tmp/foo/bar';
test.equals(path.existsSync(dir), false, 'Dir shouldn\'t exist - clean it up manually?');
test.equals(fs.existsSync(dir), false, 'Dir shouldn\'t exist - clean it up manually?');
wrench.mkdirSyncRecursive(dir, 0777);
test.equals(path.existsSync(dir), true, 'Dir should exist now');
test.equals(fs.existsSync(dir), true, 'Dir should exist now');
// clean up
while (dir != __dirname) {

View file

@ -23,7 +23,7 @@ module.exports = testCase({
test_readdirSyncRecursive: function(test) {
var dir = path.join(__dirname, 'readdir');
test.ok(path.existsSync(dir), 'Folders should exist');
test.ok(fs.existsSync(dir), 'Folders should exist');
var files = wrench.readdirSyncRecursive(dir);
@ -33,7 +33,7 @@ module.exports = testCase({
test_readdirRecursive: function(test) {
var dir = path.join(__dirname, 'readdir');
test.ok(path.existsSync(dir), 'Folders should exist');
test.ok(fs.existsSync(dir), 'Folders should exist');
var allFiles = [];