Skip to content

Commit

Permalink
Minor code restructuring on fs.stat options
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jun 26, 2019
1 parent 2284a19 commit 3579a9d
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions polyfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,6 @@ function patch (fs) {
}
}


function statFix (orig) {
if (!orig) return orig
// Older versions of Node erroneously returned signed integers for
Expand All @@ -282,16 +281,15 @@ function patch (fs) {
cb = options
options = null
}
function callback(err, stats) {
if (!stats && cb) return cb.apply(this, arguments)
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
function callback (er, stats) {
if (stats) {
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
}
if (cb) cb.apply(this, arguments)
}
if (options) {
return orig.call(fs, target, options, callback);
}
return orig.call(fs, target, callback);
return options ? orig.call(fs, target, options, callback)
: orig.call(fs, target, callback)
}
}

Expand All @@ -300,12 +298,8 @@ function patch (fs) {
// Older versions of Node erroneously returned signed integers for
// uid + gid.
return function (target, options) {
var stats
if (options) {
stats = orig.call(fs, target, options)
} else {
stats = orig.call(fs, target)
}
var stats = options ? orig.call(fs, target, options)
: orig.call(fs, target)
if (stats.uid < 0) stats.uid += 0x100000000
if (stats.gid < 0) stats.gid += 0x100000000
return stats;
Expand Down

0 comments on commit 3579a9d

Please sign in to comment.