From 6716a1ff1a40aa32ffc8cfdc476c9dc7dc054424 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Mon, 7 Jul 2014 17:02:42 -0400 Subject: [PATCH] s/make_root_directory/ensure_root_directory/ and stop failing on existing node. Fixes #232. --- src/filesystem/implementation.js | 18 +++++++++++------- src/filesystem/interface.js | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 4744428..3753e3f 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -350,17 +350,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 make_root_directory(context, callback) { +function ensure_root_directory(context, callback) { var superNode; var directoryNode; var directoryData; - function write_super_node(error, existingNode) { + function ensure_super_node(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)) { callback(error); } else { @@ -388,7 +392,7 @@ function make_root_directory(context, callback) { } } - context.get(SUPER_NODE_ID, write_super_node); + context.get(SUPER_NODE_ID, ensure_super_node); } /** @@ -2010,7 +2014,7 @@ function ftruncate(fs, context, fd, length, callback) { } module.exports = { - makeRootDirectory: make_root_directory, + ensureRootDirectory: ensure_root_directory, open: open, close: close, mknod: mknod, diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index 4a77b56..7525f89 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -206,7 +206,7 @@ function FileSystem(options, callback) { complete(err); return; } - impl.makeRootDirectory(context, complete); + impl.ensureRootDirectory(context, complete); }); }); }