Skip to content

Commit

Permalink
Merge master
Browse files Browse the repository at this point in the history
  • Loading branch information
janjongboom committed Jun 1, 2012
2 parents a6f719d + 372663b commit 315a480
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 9 deletions.
3 changes: 1 addition & 2 deletions plugins-server/cloud9.ide.revisions/revisions.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -294,12 +294,11 @@ require("util").inherits(RevisionsPlugin, Plugin);
}; };


if (!exists) { if (!exists) {
fs.mkdir(parentDir, "0755", createRevisionsFile); fs.mkdirP(parentDir, "0755", createRevisionsFile);
} }
else { else {
createRevisionsFile(); createRevisionsFile();
} }

}); });
}); });
} }
Expand Down
75 changes: 70 additions & 5 deletions plugins-server/cloud9.sandbox.fs/fs.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@ module.exports = function (projectDir, unixId) {
* Wrapper around Path.exists * Wrapper around Path.exists
*/ */
this.exists = function (path, callback) { this.exists = function (path, callback) {
var self = this;

callback = this.$normalizeCallback(callback); callback = this.$normalizeCallback(callback);

this.$resolvePath(path, function (err, path) {
self.$resolvePath(path, function (err, path) {
if (err) return callback(err); if (err) return callback(err);


Path.exists(path, function (exists) { Path.exists(path, function (exists) {
Expand Down Expand Up @@ -169,4 +166,72 @@ module.exports = function (projectDir, unixId) {
this.mkdir = function () { this.mkdir = function () {
return this.$chownWrapper.call(this, "mkdir", arguments); return this.$chownWrapper.call(this, "mkdir", arguments);
}; };
};
/**
* Equivalent to "mkdir - p"
* Adapted from https://github.com/substack/node-mkdirp
*/
this.mkdirP = function mkdirP(path, mode, f, made) {
var self = this;
if (typeof mode === "function" || mode === undefined) {
f = mode;
mode = 0777 & (~process.umask());
}

if (!made) {
made = null;
}

var cb = f || function () {};
if (typeof mode === "string") {
mode = parseInt(mode, 8);
}

self.mkdir(path, mode, function (er) {
if (!er) {
made = made || path;
return cb(null, made);
}

switch (er.code) {
case "ENOENT":
mkdirP.call(self, Path.dirname(path), mode, function (er, made) {
if (er) {
cb(er, made);
}
else {
mkdirP.call(self, path, mode, cb, made);
}
});
break;

case "EROFS":
// a read-only file system.
// However, the dir could already exist, in which case
// the EROFS error will be obscuring a EEXIST!
// Fallthrough to that case.
case "EEXIST":
Fs.stat(path, function (er2, stat) {
// if the stat fails, then that's super weird.
// let the original EEXIST be the failure reason.
if (er2 || !stat.isDirectory()) {
cb(er, made);
}
else cb(null, made);
});
break;

default:
cb(er, made);
break;
}
});
};

/**
* Wrapper around unlink
*/
this.unlink = function () {
return this.$simpleWrapper.call(this, "unlink", arguments);
};
};
30 changes: 28 additions & 2 deletions plugins-server/cloud9.sandbox.fs/fs_test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -167,7 +167,33 @@ module.exports = {


next(); next();
}); });
} },

"test mkdirP should chown": function (next) {
var mkdir = Fs.mkdir = sinon.stub().callsArgWith(2, null);
var chown = Fs.chown = sinon.stub().callsArgWith(3, null);
this.fs.mkdirP("somefolder/andItsChildren/andItsGrandChildren", "0775", function (err) {
assert.equal(err, null);
sinon.assert.calledWith(chown, "/usr/jan/1299/somefolder/andItsChildren/andItsGrandChildren", 987, 987);

next();
});
},

"test mkdirP should actually create the dir": function (next) {
var fs = new SandboxFs(__dirname, null);

fs.mkdirP("folder/child/grandchild", "0775", function (err) {
assert.equal(err, null);

fs.exists("folder/child/grandchild", function (err, exists) {
assert.equal(err, null);
assert.equal(exists, true);

require("rimraf")(__dirname + "/folder", next);
});
});
}
}; };


!module.parent && require("asyncjs").test.testcase(module.exports, "Sandbox.Fs").exec(); !module.parent && require("asyncjs").test.testcase(module.exports, "Sandbox.Fs").exec();

0 comments on commit 315a480

Please sign in to comment.