graceful-fs
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -11,3 +11,4 @@ // this keeps a queue of opened file descriptors, and will make | ||
fs.MAX_OPEN = 256 | ||
fs.MIN_MAX_OPEN = 64 | ||
fs.MAX_OPEN = 1024 | ||
@@ -20,31 +21,2 @@ fs._open = fs.open | ||
// lstat on windows, missing from early 0.5 versions | ||
if (process.platform === "win32" && !process.binding("fs").lstat) { | ||
fs.lstat = fs.stat | ||
fs.lstatSync = fs.statSync | ||
} | ||
// lutimes | ||
var constants = require("constants") | ||
if (!fs.lutimes) fs.lutimes = function (path, at, mt, cb) { | ||
fs.open(path, constants.O_SYMLINK, function (er, fd) { | ||
cb = cb || noop | ||
if (er) return cb(er) | ||
fs.futimes(fd, at, mt, function (er) { | ||
if (er) { | ||
fs.close(fd, function () {}) | ||
return cb(er) | ||
} | ||
fs.close(fd, cb) | ||
}) | ||
}) | ||
} | ||
if (!fs.lutimesSync) fs.lutimesSync = function (path, at, mt) { | ||
var fd = fs.openSync(path, constants.O_SYMLINK) | ||
fs.futimesSync(fd, at, mt) | ||
fs.closeSync(fd) | ||
} | ||
// prevent EMFILE errors | ||
@@ -69,3 +41,12 @@ function OpenReq (path, flags, mode, cb) { | ||
} | ||
open(path, flags, mode, cb) | ||
open(path, flags, mode, function (er, fd) { | ||
if (er && er.code === "EMFILE" && curOpen > fs.MIN_MAX_OPEN) { | ||
// that was too many. reduce max, get back in queue. | ||
// this should only happen once in a great while, and only | ||
// if the ulimit -n is set lower than 1024. | ||
fs.MAX_OPEN = curOpen - 1 | ||
return fs.open(path, flags, mode, cb) | ||
} | ||
cb(er, fd) | ||
}) | ||
} | ||
@@ -99,3 +80,3 @@ | ||
if (!req) break | ||
open(req.path, req.flags, req.mode, req.cb) | ||
open(req.path, req.flags || "r", req.mode || 0777, req.cb) | ||
} | ||
@@ -118,2 +99,7 @@ if (queue.length === 0) return | ||
// (re-)implement some things that are known busted or missing. | ||
var constants = require("constants") | ||
// lchmod, broken prior to 0.6.2 | ||
@@ -123,49 +109,17 @@ // back-port the fix here. | ||
process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) { | ||
fs.lchmod = function(path, mode, callback) { | ||
callback = callback || noop; | ||
fs.open(path, constants.O_WRONLY | constants.O_SYMLINK, function(err, fd) { | ||
fs.lchmod = function (path, mode, callback) { | ||
callback = callback || noop | ||
fs.open( path | ||
, constants.O_WRONLY | constants.O_SYMLINK | ||
, mode | ||
, function (err, fd) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
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.fchmod(fd, mode, function (err) { | ||
fs.close(fd, function(err2) { | ||
callback(err || err2); | ||
}); | ||
}); | ||
}); | ||
}; | ||
fs.lchmodSync = function(path, mode) { | ||
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK); | ||
// prefer to return the chmod error, if one occurs, | ||
// but still try to close, and report closing errors if they occur. | ||
var err, err2; | ||
try { | ||
var ret = fs.fchmodSync(fd, mode); | ||
} catch (er) { | ||
err = er; | ||
} | ||
try { | ||
fs.closeSync(fd); | ||
} catch (er) { | ||
err2 = er; | ||
} | ||
if (err || err2) throw (err || err2); | ||
return ret; | ||
}; | ||
} | ||
// lutimes, not yet implemented in node | ||
if (constants.hasOwnProperty('O_SYMLINK') && !fs.lutimes) { | ||
fs.lutimes = function (path, atime, mtime, cb) { | ||
cb = cb || noop | ||
fs.open(path, constants.O_SYMLINK | constants.O_WRONLY, function (er, fd) { | ||
if (er) return cb(er) | ||
fs.futimes(fd, atime, mtime, function (er) { | ||
fs.close(fd, function (er2) { | ||
cb(er || er2) | ||
callback(err || err2) | ||
}) | ||
@@ -176,4 +130,4 @@ }) | ||
fs.lutimesSync = function(path, atime, mtime) { | ||
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK) | ||
fs.lchmodSync = function (path, mode) { | ||
var fd = fs.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode) | ||
@@ -184,3 +138,3 @@ // prefer to return the chmod error, if one occurs, | ||
try { | ||
var ret = fs.futimesSync(fd, atime, mtime) | ||
var ret = fs.fchmodSync(fd, mode) | ||
} catch (er) { | ||
@@ -198,1 +152,61 @@ err = er | ||
} | ||
// lstat on windows, missing from early 0.5 versions | ||
// replacing with stat isn't quite perfect, but good enough to get by. | ||
if (process.platform === "win32" && !process.binding("fs").lstat) { | ||
fs.lstat = fs.stat | ||
fs.lstatSync = fs.statSync | ||
} | ||
// lutimes implementation, or no-op | ||
if (!fs.lutimes) { | ||
if (constants.hasOwnProperty("O_SYMLINK")) { | ||
fs.lutimes = function (path, at, mt, cb) { | ||
fs.open(path, constants.O_SYMLINK, function (er, fd) { | ||
cb = cb || noop | ||
if (er) return cb(er) | ||
fs.futimes(fd, at, mt, function (er) { | ||
fs.close(fd, function (er2) { | ||
return cb(er || er2) | ||
}) | ||
}) | ||
}) | ||
} | ||
fs.lutimesSync = function (path, at, mt) { | ||
var fd = fs.openSync(path, constants.O_SYMLINK) | ||
, err | ||
, err2 | ||
, ret | ||
try { | ||
var ret = fs.futimesSync(fd, at, mt) | ||
} catch (er) { | ||
err = er | ||
} | ||
try { | ||
fs.closeSync(fd) | ||
} catch (er) { | ||
err2 = er | ||
} | ||
if (err || err2) throw (err || err2) | ||
return ret | ||
} | ||
} else if (fs.utimensat && constants.hasOwnProperty("AT_SYMLINK_NOFOLLOW")) { | ||
// maybe utimensat will be bound soonish? | ||
fs.lutimes = function (path, at, mt, cb) { | ||
fs.utimensat(path, at, mt, constants.AT_SYMLINK_NOFOLLOW, cb) | ||
} | ||
fs.lutimesSync = function (path, at, mt) { | ||
return fs.utimensatSync(path, at, mt, constants.AT_SYMLINK_NOFOLLOW) | ||
} | ||
} else { | ||
fs.lutimes = function (_a, _b, _c, cb) { process.nextTick(cb) } | ||
fs.lutimesSync = function () {} | ||
} | ||
} |
@@ -5,3 +5,3 @@ { | ||
"description": "fs monkey-patching to avoid EMFILE and other problems", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6595
5
173