From 2992f7417bc3e179a8f5ffaac278b66e79d01a0b Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 16 Jul 2014 15:23:11 -0400 Subject: [PATCH 1/3] Failing test for issue #239 --- tests/bugs/issue239.js | 21 +++++++++++++++++++++ tests/index.js | 1 + 2 files changed, 22 insertions(+) create mode 100644 tests/bugs/issue239.js diff --git a/tests/bugs/issue239.js b/tests/bugs/issue239.js new file mode 100644 index 0000000..8e70f1a --- /dev/null +++ b/tests/bugs/issue239.js @@ -0,0 +1,21 @@ +var Filer = require('../..'); +var util = require('../lib/test-utils.js'); +var expect = require('chai').expect; + +describe('fs.writeFile and non-existing directory, issue 239', function() { + beforeEach(util.setup); + afterEach(util.cleanup); + + it('should give ENOENT if writing to a dir that does not exist', function(done) { + var fs = util.fs(); + + fs.writeFile('/abc.txt', 'content', function(err) { + expect(err).not.to.exist; + + fs.writeFile('/abc.txt/abc.txt', 'content', function(err) { + expect(err.code).to.equal('ENOENT'); + done(); + }); + }); + }); +}); diff --git a/tests/index.js b/tests/index.js index 0fb467a..b427ee3 100644 --- a/tests/index.js +++ b/tests/index.js @@ -67,3 +67,4 @@ require("./spec/node-js/simple/test-fs-watch-recursive"); // NOTE: bugs/issue225.js has to be run outside this step, see gruntfile.js require("./bugs/issue105"); require("./bugs/issue106"); +require("./bugs/issue239"); From 4623b568fb223bdcd1eaaa8a8c3ffa630cb5112e Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 16 Jul 2014 15:40:40 -0400 Subject: [PATCH 2/3] Add node.type test for read_directory_data - causes new test failures --- src/filesystem/implementation.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index 7084be0..ab962b8 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -607,6 +607,8 @@ function open_file(context, path, flags, callback) { function read_directory_data(error, result) { if(error) { callback(error); + } else if(result.type !== MODE_DIRECTORY) { + callback(new Errors.ENOENT()); } else { directoryNode = result; context.get(directoryNode.data, check_if_file_exists); From 2eae45f402a684985d20699e54fe31e1002cac53 Mon Sep 17 00:00:00 2001 From: "David Humphrey (:humph) david.humphrey@senecacollege.ca" Date: Wed, 16 Jul 2014 16:54:02 -0400 Subject: [PATCH 3/3] s/type/mode/ --- src/filesystem/implementation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js index ab962b8..60eed43 100644 --- a/src/filesystem/implementation.js +++ b/src/filesystem/implementation.js @@ -607,7 +607,7 @@ function open_file(context, path, flags, callback) { function read_directory_data(error, result) { if(error) { callback(error); - } else if(result.type !== MODE_DIRECTORY) { + } else if(result.mode !== MODE_DIRECTORY) { callback(new Errors.ENOENT()); } else { directoryNode = result;