Browse Source

Fix bug: catting non-existent files

v0.7.4-release
Ryan 16 years ago
parent
commit
ed283dc280
  1. 18
      src/file.js
  2. 2
      src/node.js
  3. 11
      test/test-cat-noexist.js

18
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);

2
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);
}

11
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);
});
};
Loading…
Cancel
Save