Skip to content

Commit 16b8aca

Browse files
bjouhierjasnell
authored andcommitted
fs: properly handle fd passed to truncate()
Currently, fs.truncate() silently fails when a file descriptor is passed as the first argument. This commit changes this behavior to properly call fs.ftruncate(). This commit also adds proper type checking to the callback provided to makeCallback(). PR-URL: nodejs#9161 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Timothy J Fontaine <[email protected]>
1 parent 8727042 commit 16b8aca

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

lib/fs.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ function maybeCallback(cb) {
8787
// for callbacks that are passed to the binding layer, callbacks that are
8888
// invoked from JS already run in the proper scope.
8989
function makeCallback(cb) {
90-
if (!util.isFunction(cb)) {
90+
if (util.isNullOrUndefined(cb)) {
9191
return rethrow();
9292
}
9393

94+
if (!util.isFunction(cb)) {
95+
throw new TypeError('callback must be a function');
96+
}
97+
9498
return function() {
9599
return cb.apply(null, arguments);
96100
};

0 commit comments

Comments
 (0)