diff --git a/src/file.js b/src/file.js index 640928e428..307305fc4d 100644 --- a/src/file.js +++ b/src/file.js @@ -8,12 +8,13 @@ node.fs.cat = function (path, encoding, callback) { var file = new node.fs.File({encoding: encoding}); file.onError = function (method, errno, msg) { + //node.debug("cat error"); callback(-1); }; var content = (encoding == node.constants.UTF8 ? "" : []); var pos = 0; - var chunkSize = 10*1024; + var chunkSize = 16*1024; function readChunk () { file.read(chunkSize, pos, function (chunk) { @@ -32,10 +33,8 @@ node.fs.cat = function (path, encoding, callback) { }); } - file.open(path, "r", function () { - readChunk(); - }); -} + file.open(path, "r", function () { readChunk(); }); +}; node.fs.File = function (options) { var self = this; @@ -71,7 +70,11 @@ node.fs.File = function (options) { var errno = arguments[0]; - if (errno < 0) { + //node.debug("poll errno: " + JSON.stringify(errno)); + //node.debug("poll action: " + JSON.stringify(action)); + //node.debug("poll rest: " + JSON.stringify(rest)); + + if (errno !== 0) { if (self.onError) self.onError(action.method, errno, node.fs.strerror(errno)); actionQueue = []; // empty the queue. @@ -82,9 +85,6 @@ node.fs.File = function (options) { for (var i = 1; i < arguments.length; i++) rest.push(arguments[i]); - //node.debug("poll action: " + JSON.stringify(action)); - //node.debug("poll rest: " + JSON.stringify(rest)); - if (action.callback) action.callback.apply(this, rest); diff --git a/src/node.js b/src/node.js index e3d9d1688c..1e81684fc9 100644 --- a/src/node.js +++ b/src/node.js @@ -136,7 +136,7 @@ clearInterval = clearTimeout; function loadScript (filename, target, callback) { node.fs.cat(filename, "utf8", function (status, content) { if (status != 0) { - stderr.puts("Error reading " + filename + ": " + node.fs.strerror(status)); + stderr.puts("Error reading " + filename); node.exit(1); } diff --git a/test/test-cat-noexist.js b/test/test-cat-noexist.js new file mode 100644 index 0000000000..961f6ecf5a --- /dev/null +++ b/test/test-cat-noexist.js @@ -0,0 +1,11 @@ +include("mjsunit"); + +function onLoad () { + var dirname = node.path.dirname(__filename); + var fixtures = node.path.join(dirname, "fixtures"); + var filename = node.path.join(fixtures, "does_not_exist.txt"); + + node.fs.cat(filename, "raw", function (status, data) { + assertTrue(status != 0); + }); +};