Skip to content

Commit

Permalink
Fix makeTree and tolerate "b" in mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kriszyp committed Jul 30, 2010
1 parent e03af2c commit fcc7f99
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions lib/fs.js
Expand Up @@ -116,26 +116,33 @@ exports.close = function(file){

var nodeOpenSync = exports.openSync;
exports.openSync = function(){
if(typeof mode == "string"){
arguments[1] = mode.replace(/b/,'');
}
return File(nodeOpenSync.apply(this, arguments));
};

nodeOpen = exports.open;
exports.open = function(){
exports.open = function(path, mode){
if(typeof mode == "string"){
arguments[1] = mode.replace(/b/,'');
}
return File(nodeOpen.apply(this, arguments));
};

exports.makeDirectory = exports.mkdirSync;

exports.makeTree = function(path){
var index = path.lastIndexOf('/');
if(index === -1){
return;
if(path.charAt(path.length-1) == '/') {
path = path.substring(0, path.length - 1);
}
var path = path.substring(0, index);
try{
fs.statSync(path);
}catch(e){
exports.makeTree(path);
var index = path.lastIndexOf('/');
if(index > -1){
exports.makeTree(path.substring(0, index));
}
fs.mkdirSync(path, 0777);
}
};

0 comments on commit fcc7f99

Please sign in to comment.