mirror of https://github.com/nodejs/node.git
detect 0 length fs writes with tests
parent
4db608dbba
commit
6744e59e46
|
@ -208,6 +208,7 @@ fs.write = function (fd, buffer, offset, length, position, callback) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
length = buffer.length;
|
length = buffer.length;
|
||||||
}
|
}
|
||||||
|
if(!length) return;
|
||||||
|
|
||||||
binding.write(fd, buffer, offset, length, position, callback || noop);
|
binding.write(fd, buffer, offset, length, position, callback || noop);
|
||||||
};
|
};
|
||||||
|
@ -221,6 +222,7 @@ fs.writeSync = function (fd, buffer, offset, length, position) {
|
||||||
offset = 0;
|
offset = 0;
|
||||||
length = buffer.length;
|
length = buffer.length;
|
||||||
}
|
}
|
||||||
|
if(!length) return 0;
|
||||||
|
|
||||||
return binding.write(fd, buffer, offset, length, position);
|
return binding.write(fd, buffer, offset, length, position);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,10 @@ fn = path.join(common.fixturesDir, 'write.txt');
|
||||||
|
|
||||||
foo = 'foo'
|
foo = 'foo'
|
||||||
var fd = fs.openSync(fn, 'w');
|
var fd = fs.openSync(fn, 'w');
|
||||||
|
|
||||||
|
written = fs.writeSync(fd, '');
|
||||||
|
assert.strictEqual(0, written);
|
||||||
|
|
||||||
fs.writeSync(fd, foo);
|
fs.writeSync(fd, foo);
|
||||||
|
|
||||||
bar = 'bár'
|
bar = 'bár'
|
||||||
|
|
|
@ -10,6 +10,9 @@ var found;
|
||||||
fs.open(fn, 'w', 0644, function (err, fd) {
|
fs.open(fn, 'w', 0644, function (err, fd) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log('open done');
|
console.log('open done');
|
||||||
|
fs.write(fd, '', 0, 'utf8', function(err, written) {
|
||||||
|
assert.fail('zero length write should not go through to callback');
|
||||||
|
});
|
||||||
fs.write(fd, expected, 0, "utf8", function (err, written) {
|
fs.write(fd, expected, 0, "utf8", function (err, written) {
|
||||||
console.log('write done');
|
console.log('write done');
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
|
|
Loading…
Reference in New Issue