0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00

Fix bug: catting non-existent files

This commit is contained in:
Ryan 2009-06-01 12:56:28 +02:00
parent 4fbe15f065
commit ed283dc280
3 changed files with 21 additions and 10 deletions

View File

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

View File

@ -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 Normal file
View File

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