diff --git a/src/constants.js b/src/constants.js index 6c6a59e..bad5944 100644 --- a/src/constants.js +++ b/src/constants.js @@ -68,7 +68,7 @@ define(function(require) { SUPER_NODE_ID: '00000000-0000-0000-0000-000000000000', - //Reserved FileDescriptors for streams + // Reserved File Descriptors for streams STDIN: 0, STDOUT: 1, STDERR: 2, @@ -80,4 +80,4 @@ define(function(require) { } }; -}); \ No newline at end of file +}); diff --git a/src/filesystem/interface.js b/src/filesystem/interface.js index 8704835..9e14385 100644 --- a/src/filesystem/interface.js +++ b/src/filesystem/interface.js @@ -22,7 +22,7 @@ define(function(require) { var STDIN = require('src/constants').STDIN; var STDOUT = require('src/constants').STDOUT; var STDERR = require('src/constants').STDERR; - var FD = require('src/constants').FIRST_DESCRIPTOR; + var FIRST_DESCRIPTOR = require('src/constants').FIRST_DESCRIPTOR; // The core fs operations live on impl var impl = require('src/filesystem/implementation'); @@ -82,12 +82,11 @@ define(function(require) { fs.stdin = STDIN; fs.stdout = STDOUT; fs.stderr = STDERR; - fs.firstFD = FD; // Safely expose the list of open files and file // descriptor management functions var openFiles = {}; - var nextDescriptor = 3; + var nextDescriptor = FIRST_DESCRIPTOR; Object.defineProperty(this, "openFiles", { get: function() { return openFiles; } }); diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js index 6ab8cf4..0dd4c87 100644 --- a/tests/spec/fs.open.spec.js +++ b/tests/spec/fs.open.spec.js @@ -62,7 +62,7 @@ define(["Filer", "util"], function(Filer, util) { it('should return a unique file descriptor', function(done) { var fs = util.fs(); - var fd1 + var fd1; fs.open('/file1', 'w+', function(error, fd) { if(error) throw error; @@ -79,6 +79,18 @@ define(["Filer", "util"], function(Filer, util) { }); }); + it('should return the argument value of the file descriptor index matching the value set by the first useable file descriptor constant', function(done) { + var fs = util.fs(); + var firstFD = require('src/constants').FIRST_DESCRIPTOR; + var fd1; + + fs.open('/file1', 'w+', function(error, fd) { + if(error) throw error; + expect(fd).to.equal(firstFD); + done(); + }); + }); + it('should create a new file when flagged for write', function(done) { var fs = util.fs();