Merge pull request #233 from humphd/ensure-root-dir

s/make_root_directory/ensure_root_directory/ and stop failing on existing node. Fixes #232.
This commit is contained in:
Alan K 2014-07-21 10:02:11 -04:00
commit 10f1f43d93
2 changed files with 12 additions and 8 deletions

View File

@ -356,17 +356,21 @@ function set_extended_attribute (context, path_or_fd, name, value, flag, callbac
} }
/** /**
* make_root_directory * ensure_root_directory. Creates a root node if necessary.
*
* Note: this should only be invoked when formatting a new file system.
* Multiple invocations of this by separate instances will still result
* in only a single super node.
*/ */
// Note: this should only be invoked when formatting a new file system function ensure_root_directory(context, callback) {
function make_root_directory(context, callback) {
var superNode; var superNode;
var directoryNode; var directoryNode;
var directoryData; var directoryData;
function write_super_node(error, existingNode) { function ensure_super_node(error, existingNode) {
if(!error && existingNode) { if(!error && existingNode) {
callback(new Errors.EEXIST()); // Another instance has beat us and already created the super node.
callback();
} else if(error && !(error instanceof Errors.ENOENT)) { } else if(error && !(error instanceof Errors.ENOENT)) {
callback(error); callback(error);
} else { } else {
@ -406,7 +410,7 @@ function make_root_directory(context, callback) {
} }
} }
context.get(SUPER_NODE_ID, write_super_node); context.get(SUPER_NODE_ID, ensure_super_node);
} }
/** /**
@ -2048,7 +2052,7 @@ function ftruncate(fs, context, fd, length, callback) {
} }
module.exports = { module.exports = {
makeRootDirectory: make_root_directory, ensureRootDirectory: ensure_root_directory,
open: open, open: open,
close: close, close: close,
mknod: mknod, mknod: mknod,

View File

@ -244,7 +244,7 @@ function FileSystem(options, callback) {
complete(err); complete(err);
return; return;
} }
impl.makeRootDirectory(context, complete); impl.ensureRootDirectory(context, complete);
}); });
}); });
} }