Skip to content

Commit

Permalink
fs: fix functions executed in wrong context
Browse files Browse the repository at this point in the history
The callback should run in the global scope and not in the FSReqWrap
context.

PR-URL: nodejs#18668
Refs: nodejs#12562
Refs: nodejs#12976
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Gus Caplan <me@gus.host>
  • Loading branch information
BridgeAR authored and MayaLekova committed May 8, 2018
1 parent fdc5b07 commit 08c182b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/fs.js
Expand Up @@ -737,7 +737,7 @@ fs.ftruncateSync = function(fd, len = 0) {
};

fs.rmdir = function(path, callback) {
callback = maybeCallback(callback);
callback = makeCallback(callback);
path = getPathFromURL(path);
validatePath(path);
const req = new FSReqWrap();
Expand Down Expand Up @@ -1784,7 +1784,7 @@ fs.realpath = function realpath(p, options, callback) {


fs.realpath.native = function(path, options, callback) {
callback = maybeCallback(callback || options);
callback = makeCallback(callback || options);
options = getOptions(options, {});
path = getPathFromURL(path);
validatePath(path);
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-fs-mkdir-rmdir.js
Expand Up @@ -29,6 +29,7 @@ fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.ifError(err);

fs.mkdir(d, 0o666, common.mustCall(function(err) {
assert.strictEqual(this, undefined);
assert.ok(err, 'got no error');
assert.ok(/^EEXIST/.test(err.message), 'got no EEXIST message');
assert.strictEqual(err.code, 'EEXIST', 'got no EEXIST code');
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-fs-realpath-native.js
Expand Up @@ -6,7 +6,8 @@ const fs = require('fs');
if (!common.isOSX) common.skip('MacOS-only test.');

assert.strictEqual(fs.realpathSync.native('/users'), '/Users');
fs.realpath.native('/users', common.mustCall((err, res) => {
fs.realpath.native('/users', common.mustCall(function(err, res) {
assert.ifError(err);
assert.strictEqual(res, '/Users');
assert.strictEqual(this, undefined);
}));

0 comments on commit 08c182b

Please sign in to comment.