graceful-fs
Advanced tools
Comparing version 4.1.11 to 4.1.12
var fs = require('fs') | ||
var polyfills = require('./polyfills.js') | ||
var legacy = require('./legacy-streams.js') | ||
var clone = require('./clone.js') | ||
var queue = [] | ||
@@ -27,5 +29,6 @@ | ||
module.exports = patch(require('./fs.js')) | ||
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) { | ||
module.exports = patch(fs) | ||
module.exports = patch(clone(fs)) | ||
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched) { | ||
module.exports = patch(fs) | ||
fs.__patched = true; | ||
} | ||
@@ -37,4 +40,3 @@ | ||
// in play at the same time. | ||
module.exports.close = | ||
fs.close = (function (fs$close) { return function (fd, cb) { | ||
module.exports.close = (function (fs$close) { return function (fd, cb) { | ||
return fs$close.call(fs, fd, function (err) { | ||
@@ -49,4 +51,3 @@ if (!err) | ||
module.exports.closeSync = | ||
fs.closeSync = (function (fs$closeSync) { return function (fd) { | ||
module.exports.closeSync = (function (fs$closeSync) { return function (fd) { | ||
// Note that graceful-fs also retries when fs.closeSync() fails. | ||
@@ -59,2 +60,13 @@ // Looks like a bug to me, although it's probably a harmless one. | ||
// Only patch fs once, otherwise we'll run into a memory leak if | ||
// graceful-fs is loaded multiple times, such as in test environments that | ||
// reset the loaded modules between tests. | ||
// We look for the string `graceful-fs` from the comment above. This | ||
// way we are not adding any extra properties and it will detect if older | ||
// versions of graceful-fs are installed. | ||
if (!fs.closeSync.toString().includes('graceful-fs')) { | ||
fs.closeSync = module.exports.closeSync; | ||
fs.close = module.exports.close; | ||
} | ||
function patch (fs) { | ||
@@ -151,2 +163,3 @@ // Everything that references the open() function needs to be in here | ||
enqueue([go$readdir, [args]]) | ||
else { | ||
@@ -171,8 +184,12 @@ if (typeof cb === 'function') | ||
var fs$ReadStream = fs.ReadStream | ||
ReadStream.prototype = Object.create(fs$ReadStream.prototype) | ||
ReadStream.prototype.open = ReadStream$open | ||
if (fs$ReadStream) { | ||
ReadStream.prototype = Object.create(fs$ReadStream.prototype) | ||
ReadStream.prototype.open = ReadStream$open | ||
} | ||
var fs$WriteStream = fs.WriteStream | ||
WriteStream.prototype = Object.create(fs$WriteStream.prototype) | ||
WriteStream.prototype.open = WriteStream$open | ||
if (fs$WriteStream) { | ||
WriteStream.prototype = Object.create(fs$WriteStream.prototype) | ||
WriteStream.prototype.open = WriteStream$open | ||
} | ||
@@ -179,0 +196,0 @@ fs.ReadStream = ReadStream |
{ | ||
"name": "graceful-fs", | ||
"description": "A drop-in replacement for fs, making various improvements.", | ||
"version": "4.1.11", | ||
"version": "4.1.12", | ||
"repository": { | ||
@@ -11,3 +11,3 @@ "type": "git", | ||
"engines": { | ||
"node": ">=0.4.0" | ||
"node": ">=6" | ||
}, | ||
@@ -18,2 +18,5 @@ "directories": { | ||
"scripts": { | ||
"preversion": "npm test", | ||
"postversion": "npm publish", | ||
"postpublish": "git push origin --all; git push origin --tags", | ||
"test": "node test.js | tap -" | ||
@@ -39,5 +42,6 @@ }, | ||
"devDependencies": { | ||
"import-fresh": "^2.0.0", | ||
"mkdirp": "^0.5.0", | ||
"rimraf": "^2.2.8", | ||
"tap": "^5.4.2" | ||
"tap": "^12.0.1" | ||
}, | ||
@@ -44,0 +48,0 @@ "files": [ |
275
polyfills.js
@@ -1,2 +0,1 @@ | ||
var fs = require('./fs.js') | ||
var constants = require('constants') | ||
@@ -148,58 +147,18 @@ | ||
}})(fs.readSync) | ||
} | ||
function patchLchmod (fs) { | ||
fs.lchmod = function (path, mode, callback) { | ||
fs.open( path | ||
, constants.O_WRONLY | constants.O_SYMLINK | ||
, mode | ||
, function (err, fd) { | ||
if (err) { | ||
if (callback) callback(err) | ||
return | ||
} | ||
// prefer to return the chmod error, if one occurs, | ||
// but still try to close, and report closing errors if they occur. | ||
fs.fchmod(fd, mode, function (err) { | ||
fs.close(fd, function(err2) { | ||
if (callback) callback(err || err2) | ||
}) | ||
}) | ||
}) | ||
} | ||
fs.lchmodSync = function (path, mode) { | ||
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode) | ||
// prefer to return the chmod error, if one occurs, | ||
// but still try to close, and report closing errors if they occur. | ||
var threw = true | ||
var ret | ||
try { | ||
ret = fs.fchmodSync(fd, mode) | ||
threw = false | ||
} finally { | ||
if (threw) { | ||
try { | ||
fs.closeSync(fd) | ||
} catch (er) {} | ||
} else { | ||
fs.closeSync(fd) | ||
} | ||
} | ||
return ret | ||
} | ||
} | ||
function patchLutimes (fs) { | ||
if (constants.hasOwnProperty("O_SYMLINK")) { | ||
fs.lutimes = function (path, at, mt, cb) { | ||
fs.open(path, constants.O_SYMLINK, function (er, fd) { | ||
if (er) { | ||
if (cb) cb(er) | ||
function patchLchmod (fs) { | ||
fs.lchmod = function (path, mode, callback) { | ||
fs.open( path | ||
, constants.O_WRONLY | constants.O_SYMLINK | ||
, mode | ||
, function (err, fd) { | ||
if (err) { | ||
if (callback) callback(err) | ||
return | ||
} | ||
fs.futimes(fd, at, mt, function (er) { | ||
fs.close(fd, function (er2) { | ||
if (cb) cb(er || er2) | ||
// prefer to return the chmod error, if one occurs, | ||
// but still try to close, and report closing errors if they occur. | ||
fs.fchmod(fd, mode, function (err) { | ||
fs.close(fd, function(err2) { | ||
if (callback) callback(err || err2) | ||
}) | ||
@@ -210,8 +169,11 @@ }) | ||
fs.lutimesSync = function (path, at, mt) { | ||
var fd = fs.openSync(path, constants.O_SYMLINK) | ||
fs.lchmodSync = function (path, mode) { | ||
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode) | ||
// prefer to return the chmod error, if one occurs, | ||
// but still try to close, and report closing errors if they occur. | ||
var threw = true | ||
var ret | ||
var threw = true | ||
try { | ||
ret = fs.futimesSync(fd, at, mt) | ||
ret = fs.fchmodSync(fd, mode) | ||
threw = false | ||
@@ -229,105 +191,142 @@ } finally { | ||
} | ||
} | ||
} else { | ||
fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb) } | ||
fs.lutimesSync = function () {} | ||
function patchLutimes (fs) { | ||
if (constants.hasOwnProperty("O_SYMLINK")) { | ||
fs.lutimes = function (path, at, mt, cb) { | ||
fs.open(path, constants.O_SYMLINK, function (er, fd) { | ||
if (er) { | ||
if (cb) cb(er) | ||
return | ||
} | ||
fs.futimes(fd, at, mt, function (er) { | ||
fs.close(fd, function (er2) { | ||
if (cb) cb(er || er2) | ||
}) | ||
}) | ||
}) | ||
} | ||
fs.lutimesSync = function (path, at, mt) { | ||
var fd = fs.openSync(path, constants.O_SYMLINK) | ||
var ret | ||
var threw = true | ||
try { | ||
ret = fs.futimesSync(fd, at, mt) | ||
threw = false | ||
} finally { | ||
if (threw) { | ||
try { | ||
fs.closeSync(fd) | ||
} catch (er) {} | ||
} else { | ||
fs.closeSync(fd) | ||
} | ||
} | ||
return ret | ||
} | ||
} else { | ||
fs.lutimes = function (_a, _b, _c, cb) { if (cb) process.nextTick(cb) } | ||
fs.lutimesSync = function () {} | ||
} | ||
} | ||
} | ||
function chmodFix (orig) { | ||
if (!orig) return orig | ||
return function (target, mode, cb) { | ||
return orig.call(fs, target, mode, function (er) { | ||
if (chownErOk(er)) er = null | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
function chmodFix (orig) { | ||
if (!orig) return orig | ||
return function (target, mode, cb) { | ||
return orig.call(fs, target, mode, function (er) { | ||
if (chownErOk(er)) er = null | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
} | ||
} | ||
} | ||
function chmodFixSync (orig) { | ||
if (!orig) return orig | ||
return function (target, mode) { | ||
try { | ||
return orig.call(fs, target, mode) | ||
} catch (er) { | ||
if (!chownErOk(er)) throw er | ||
function chmodFixSync (orig) { | ||
if (!orig) return orig | ||
return function (target, mode) { | ||
try { | ||
return orig.call(fs, target, mode) | ||
} catch (er) { | ||
if (!chownErOk(er)) throw er | ||
} | ||
} | ||
} | ||
} | ||
function chownFix (orig) { | ||
if (!orig) return orig | ||
return function (target, uid, gid, cb) { | ||
return orig.call(fs, target, uid, gid, function (er) { | ||
if (chownErOk(er)) er = null | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
function chownFix (orig) { | ||
if (!orig) return orig | ||
return function (target, uid, gid, cb) { | ||
return orig.call(fs, target, uid, gid, function (er) { | ||
if (chownErOk(er)) er = null | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
} | ||
} | ||
} | ||
function chownFixSync (orig) { | ||
if (!orig) return orig | ||
return function (target, uid, gid) { | ||
try { | ||
return orig.call(fs, target, uid, gid) | ||
} catch (er) { | ||
if (!chownErOk(er)) throw er | ||
function chownFixSync (orig) { | ||
if (!orig) return orig | ||
return function (target, uid, gid) { | ||
try { | ||
return orig.call(fs, target, uid, gid) | ||
} catch (er) { | ||
if (!chownErOk(er)) throw er | ||
} | ||
} | ||
} | ||
} | ||
function statFix (orig) { | ||
if (!orig) return orig | ||
// Older versions of Node erroneously returned signed integers for | ||
// uid + gid. | ||
return function (target, cb) { | ||
return orig.call(fs, target, function (er, stats) { | ||
if (!stats) return cb.apply(this, arguments) | ||
function statFix (orig) { | ||
if (!orig) return orig | ||
// Older versions of Node erroneously returned signed integers for | ||
// uid + gid. | ||
return function (target, cb) { | ||
return orig.call(fs, target, function (er, stats) { | ||
if (!stats) return cb.apply(this, arguments) | ||
if (stats.uid < 0) stats.uid += 0x100000000 | ||
if (stats.gid < 0) stats.gid += 0x100000000 | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
} | ||
} | ||
function statFixSync (orig) { | ||
if (!orig) return orig | ||
// Older versions of Node erroneously returned signed integers for | ||
// uid + gid. | ||
return function (target) { | ||
var stats = orig.call(fs, target) | ||
if (stats.uid < 0) stats.uid += 0x100000000 | ||
if (stats.gid < 0) stats.gid += 0x100000000 | ||
if (cb) cb.apply(this, arguments) | ||
}) | ||
return stats; | ||
} | ||
} | ||
} | ||
function statFixSync (orig) { | ||
if (!orig) return orig | ||
// Older versions of Node erroneously returned signed integers for | ||
// uid + gid. | ||
return function (target) { | ||
var stats = orig.call(fs, target) | ||
if (stats.uid < 0) stats.uid += 0x100000000 | ||
if (stats.gid < 0) stats.gid += 0x100000000 | ||
return stats; | ||
} | ||
} | ||
// ENOSYS means that the fs doesn't support the op. Just ignore | ||
// that, because it doesn't matter. | ||
// | ||
// if there's no getuid, or if getuid() is something other | ||
// than 0, and the error is EINVAL or EPERM, then just ignore | ||
// it. | ||
// | ||
// This specific case is a silent failure in cp, install, tar, | ||
// and most other unix tools that manage permissions. | ||
// | ||
// When running as root, or if other types of errors are | ||
// encountered, then it's strict. | ||
function chownErOk (er) { | ||
if (!er) | ||
return true | ||
// ENOSYS means that the fs doesn't support the op. Just ignore | ||
// that, because it doesn't matter. | ||
// | ||
// if there's no getuid, or if getuid() is something other | ||
// than 0, and the error is EINVAL or EPERM, then just ignore | ||
// it. | ||
// | ||
// This specific case is a silent failure in cp, install, tar, | ||
// and most other unix tools that manage permissions. | ||
// | ||
// When running as root, or if other types of errors are | ||
// encountered, then it's strict. | ||
function chownErOk (er) { | ||
if (!er) | ||
return true | ||
if (er.code === "ENOSYS") | ||
return true | ||
if (er.code === "ENOSYS") | ||
return true | ||
var nonroot = !process.getuid || process.getuid() !== 0 | ||
if (nonroot) { | ||
if (er.code === "EINVAL" || er.code === "EPERM") | ||
return true | ||
} | ||
var nonroot = !process.getuid || process.getuid() !== 0 | ||
if (nonroot) { | ||
if (er.code === "EINVAL" || er.code === "EPERM") | ||
return true | ||
return false | ||
} | ||
return false | ||
} |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
25559
4
6
620
8