Skip to content

Commit

Permalink
fs: properly handle fd passed to truncate()
Browse files Browse the repository at this point in the history
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 <cjihrig@gmail.com>
Reviewed-By: Timothy J Fontaine <tjfontaine@gmail.com>
  • Loading branch information
bjouhier authored and jasnell committed Mar 14, 2015
1 parent 8727042 commit 16b8aca
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,14 @@ function maybeCallback(cb) {
// for callbacks that are passed to the binding layer, callbacks that are
// invoked from JS already run in the proper scope.
function makeCallback(cb) {
if (!util.isFunction(cb)) {
if (util.isNullOrUndefined(cb)) {
return rethrow();
}

if (!util.isFunction(cb)) {
throw new TypeError('callback must be a function');
}

return function() {
return cb.apply(null, arguments);
};
Expand Down

0 comments on commit 16b8aca

Please sign in to comment.