4374b79.diff 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. commit 4374b79aed648738d2458ce027cbe2b372bf7b3a
  2. Author: isaacs <i@izs.me>
  3. Date: Wed Jun 26 12:12:17 2019 -0700
  4. Add support for stat options
  5. Fix #158
  6. diff --git a/polyfills.js b/polyfills.js
  7. index b964ed0..bc9759b 100644
  8. --- a/polyfills.js
  9. +++ b/polyfills.js
  10. @@ -273,17 +273,23 @@ function patch (fs) {
  11. }
  12. + // stat options added in v10.5.0
  13. + var supportsStatOptions = /^v[1-9][1-9]|^v10\.[5-9]/.test(process.version)
  14. function statFix (orig) {
  15. if (!orig) return orig
  16. // Older versions of Node erroneously returned signed integers for
  17. // uid + gid.
  18. - return function (target, cb) {
  19. - return orig.call(fs, target, function (er, stats) {
  20. - if (!stats) return cb.apply(this, arguments)
  21. + return function (target, options, cb) {
  22. + if (typeof options === 'function')
  23. + cb = options, options = null
  24. + function callback (er, stats) {
  25. + if (!stats) return cb && cb.apply(this, arguments)
  26. if (stats.uid < 0) stats.uid += 0x100000000
  27. if (stats.gid < 0) stats.gid += 0x100000000
  28. if (cb) cb.apply(this, arguments)
  29. - })
  30. + }
  31. + return supportsStatOptions ? orig.call(fs, target, options || {}, callback)
  32. + : orig.call(fs, target, callback)
  33. }
  34. }
  35. @@ -291,8 +297,8 @@ function patch (fs) {
  36. if (!orig) return orig
  37. // Older versions of Node erroneously returned signed integers for
  38. // uid + gid.
  39. - return function (target) {
  40. - var stats = orig.call(fs, target)
  41. + return function (target, options) {
  42. + var stats = orig.call(fs, target, options)
  43. if (stats.uid < 0) stats.uid += 0x100000000
  44. if (stats.gid < 0) stats.gid += 0x100000000
  45. return stats;