Skip to content

Commit

Permalink
[patch] sync/async: use native realpath if available to unwrap …
Browse files Browse the repository at this point in the history
…symlinks (#217)
  • Loading branch information
SimenB authored and ljharb committed Apr 7, 2020
1 parent c1750d6 commit bab1166
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');
var isCore = require('./is-core');

var realpath = typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;

var defaultIsFile = function isFile(file, cb) {
fs.stat(file, function (err, stat) {
if (!err) {
Expand All @@ -27,7 +29,7 @@ var defaultIsDir = function isDirectory(dir, cb) {

var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts, cb) {
if (opts && opts.preserveSymlinks === false) {
fs.realpath(x, function (realPathErr, realPath) {
realpath(x, function (realPathErr, realPath) {
if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);
else cb(null, realPathErr ? x : realPath);
});
Expand Down
4 changes: 3 additions & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
var normalizeOptions = require('./normalize-options.js');

var realpath = typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;

var defaultIsFile = function isFile(file) {
try {
var stat = fs.statSync(file);
Expand All @@ -28,7 +30,7 @@ var defaultIsDir = function isDirectory(dir) {
var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts) {
if (opts && opts.preserveSymlinks === false) {
try {
return fs.realpathSync(x);
return realpath(x);
} catch (realPathErr) {
if (realPathErr.code !== 'ENOENT') {
throw realPathErr;
Expand Down

0 comments on commit bab1166

Please sign in to comment.