Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-08-02 02:56:13 +0400
committerisaacs <i@izs.me>2012-08-02 02:56:13 +0400
commit501fef23c38e03ed146b44eab0e71c2722cd1c8f (patch)
tree6761e17391643564a633808a5c11ee0eec9214d7 /node_modules/graceful-fs
parent0dc78b963983ab71f82ddb5f7c79c49476de4f96 (diff)
graceful-fs@1.1.10
Diffstat (limited to 'node_modules/graceful-fs')
-rw-r--r--node_modules/graceful-fs/graceful-fs.js32
-rw-r--r--node_modules/graceful-fs/package.json19
-rw-r--r--node_modules/graceful-fs/test/open.js41
3 files changed, 73 insertions, 19 deletions
diff --git a/node_modules/graceful-fs/graceful-fs.js b/node_modules/graceful-fs/graceful-fs.js
index 856fc66bf..5d136c27f 100644
--- a/node_modules/graceful-fs/graceful-fs.js
+++ b/node_modules/graceful-fs/graceful-fs.js
@@ -7,12 +7,10 @@ var fs = require("fs")
if (fs.open === gracefulOpen) return
var queue = []
- , curOpen = 0
, constants = require("constants")
-
exports = module.exports = fs
-
+fs._curOpen = 0
fs.MIN_MAX_OPEN = 64
fs.MAX_OPEN = 1024
@@ -39,17 +37,17 @@ function gracefulOpen (path, flags, mode, cb) {
if (typeof mode === "function") cb = mode, mode = null
if (typeof cb !== "function") cb = noop
- if (curOpen >= fs.MAX_OPEN) {
+ if (fs._curOpen >= fs.MAX_OPEN) {
queue.push(new OpenReq(path, flags, mode, cb))
setTimeout(flush)
return
}
open(path, flags, mode, function (er, fd) {
- if (er && er.code === "EMFILE" && curOpen > fs.MIN_MAX_OPEN) {
+ if (er && er.code === "EMFILE" && fs._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
+ fs.MAX_OPEN = fs._curOpen - 1
return fs.open(path, flags, mode, cb)
}
cb(er, fd)
@@ -58,33 +56,33 @@ function gracefulOpen (path, flags, mode, cb) {
function open (path, flags, mode, cb) {
cb = cb || noop
- curOpen ++
+ fs._curOpen ++
originalOpen.call(fs, path, flags, mode, function (er, fd) {
- if (er) {
- onclose()
- }
-
+ if (er) onclose()
cb(er, fd)
})
}
fs.openSync = function (path, flags, mode) {
- curOpen ++
- return originalOpenSync.call(fs, path, flags, mode)
+ var ret
+ try {
+ ret = originalOpenSync.call(fs, path, flags, mode)
+ fs._curOpen ++
+ } finally {}
+ return ret
}
function onclose () {
- curOpen --
+ fs._curOpen --
flush()
}
function flush () {
- while (curOpen < fs.MAX_OPEN) {
+ while (fs._curOpen < fs.MAX_OPEN) {
var req = queue.shift()
- if (!req) break
+ if (!req) return
open(req.path, req.flags || "r", req.mode || 0777, req.cb)
}
- if (queue.length === 0) return
}
fs.close = function (fd, cb) {
diff --git a/node_modules/graceful-fs/package.json b/node_modules/graceful-fs/package.json
index fe4de9e58..4f513626d 100644
--- a/node_modules/graceful-fs/package.json
+++ b/node_modules/graceful-fs/package.json
@@ -6,7 +6,7 @@
},
"name": "graceful-fs",
"description": "fs monkey-patching to avoid EMFILE and other problems",
- "version": "1.1.9",
+ "version": "1.1.10",
"repository": {
"type": "git",
"url": "git://github.com/isaacs/node-graceful-fs.git"
@@ -16,7 +16,22 @@
"node": ">=0.4.0"
},
"devDependencies": {},
+ "directories": {
+ "test": "test"
+ },
+ "dependencies": {},
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "keywords": [
+ "fs",
+ "EMFILE",
+ "error",
+ "handling",
+ "monkeypatch"
+ ],
+ "license": "BSD",
"readme": "Just like node's `fs` module, but it does an incremental back-off when\nEMFILE is encountered.\n\nUseful in asynchronous situations where one needs to try to open lots\nand lots of files.\n",
- "_id": "graceful-fs@1.1.9",
+ "_id": "graceful-fs@1.1.10",
"_from": "graceful-fs@~1.1.1"
}
diff --git a/node_modules/graceful-fs/test/open.js b/node_modules/graceful-fs/test/open.js
new file mode 100644
index 000000000..d05f880c8
--- /dev/null
+++ b/node_modules/graceful-fs/test/open.js
@@ -0,0 +1,41 @@
+var test = require('tap').test
+var fs = require('../graceful-fs.js')
+
+test('open an existing file works', function (t) {
+ var start = fs._curOpen
+ var fd = fs.openSync(__filename, 'r')
+ t.equal(fs._curOpen, start + 1)
+ fs.closeSync(fd)
+ t.equal(fs._curOpen, start)
+ fs.open(__filename, 'r', function (er, fd) {
+ if (er) throw er
+ t.equal(fs._curOpen, start + 1)
+ fs.close(fd, function (er) {
+ if (er) throw er
+ t.equal(fs._curOpen, start)
+ t.end()
+ })
+ })
+})
+
+test('open a non-existing file throws', function (t) {
+ var start = fs._curOpen
+ var er
+ try {
+ var fd = fs.openSync('this file does not exist', 'r')
+ } catch (x) {
+ er = x
+ }
+ t.ok(er, 'should throw')
+ t.notOk(fd, 'should not get an fd')
+ t.equal(er.code, 'ENOENT')
+ t.equal(fs._curOpen, start)
+
+ fs.open('neither does this file', 'r', function (er, fd) {
+ t.ok(er, 'should throw')
+ t.notOk(fd, 'should not get an fd')
+ t.equal(er.code, 'ENOENT')
+ t.equal(fs._curOpen, start)
+ t.end()
+ })
+})