[Pkg-javascript-commits] [node-graceful-fs] 01/07: Imported Upstream version 3.0.2

Jérémy Lal kapouer at moszumanska.debian.org
Tue Jul 29 00:48:56 UTC 2014


This is an automated email from the git hooks/post-receive script.

kapouer pushed a commit to branch master
in repository node-graceful-fs.

commit 051256aee1114445e2cbb4e9a9e17c5fe1360e05
Author: Jérémy Lal <kapouer at melix.org>
Date:   Tue Jul 29 02:43:03 2014 +0200

    Imported Upstream version 3.0.2
---
 README.md            | 21 ++++++++++++---------
 fs.js                | 11 +++++++++++
 graceful-fs.js       | 18 ++++++++++++------
 package.json         |  2 +-
 polyfills.js         | 45 ++++++++++++++++++++++++++++++++++++---------
 test/open.js         |  2 +-
 test/readdir-sort.js | 21 +++++++++++++++++++++
 7 files changed, 94 insertions(+), 26 deletions(-)

diff --git a/README.md b/README.md
index 01af3d6..13a2e86 100644
--- a/README.md
+++ b/README.md
@@ -7,14 +7,13 @@ The improvements are meant to normalize behavior across different
 platforms and environments, and to make filesystem access more
 resilient to errors.
 
-## Improvements over fs module
+## Improvements over [fs module](http://api.nodejs.org/fs.html)
 
 graceful-fs:
 
-* keeps track of how many file descriptors are open, and by default
-  limits this to 1024. Any further requests to open a file are put in a
-  queue until new slots become available. If 1024 turns out to be too
-  much, it decreases the limit further.
+* Queues up `open` and `readdir` calls, and retries them once
+  something closes if there is an EMFILE error from too many file
+  descriptors.
 * fixes `lchmod` for Node versions prior to 0.6.2.
 * implements `fs.lutimes` if possible. Otherwise it becomes a noop.
 * ignores `EINVAL` and `EPERM` errors in `chown`, `fchown` or
@@ -26,8 +25,12 @@ On Windows, it retries renaming a file for up to one second if `EACCESS`
 or `EPERM` error occurs, likely because antivirus software has locked
 the directory.
 
-## Configuration
+## USAGE
 
-The maximum number of open file descriptors that graceful-fs manages may
-be adjusted by setting `fs.MAX_OPEN` to a different number. The default
-is 1024.
+```javascript
+// use just like fs
+var fs = require('graceful-fs')
+
+// now go and do stuff with it...
+fs.readFileSync('some-file-or-whatever')
+```
diff --git a/fs.js b/fs.js
new file mode 100644
index 0000000..ae9fd6f
--- /dev/null
+++ b/fs.js
@@ -0,0 +1,11 @@
+// eeeeeevvvvviiiiiiillllll
+// more evil than monkey-patching the native builtin?
+// Not sure.
+
+var mod = require("module")
+var pre = '(function (exports, require, module, __filename, __dirname) { '
+var post = '});'
+var src = pre + process.binding('natives').fs + post
+var vm = require('vm')
+var fn = vm.runInThisContext(src)
+return fn(exports, require, module, __filename, __dirname)
diff --git a/graceful-fs.js b/graceful-fs.js
index a46b5b2..77fc702 100644
--- a/graceful-fs.js
+++ b/graceful-fs.js
@@ -1,20 +1,17 @@
 // Monkey-patching the fs module.
 // It's ugly, but there is simply no other way to do this.
-var fs = module.exports = require('fs')
+var fs = module.exports = require('./fs.js')
 
 var assert = require('assert')
 
 // fix up some busted stuff, mostly on windows and old nodes
 require('./polyfills.js')
 
-// The EMFILE enqueuing stuff
-
 var util = require('util')
 
 function noop () {}
 
 var debug = noop
-var util = require('util')
 if (util.debuglog)
   debug = util.debuglog('gfs')
 else if (/\bgfs\b/i.test(process.env.NODE_DEBUG || ''))
@@ -86,6 +83,8 @@ ReaddirReq.prototype.process = function() {
 }
 
 ReaddirReq.prototype.done = function(er, files) {
+  if (files && files.sort)
+    files = files.sort()
   Req.prototype.done.call(this, er, files)
   onclose()
 }
@@ -126,8 +125,15 @@ function Req () {
 }
 
 Req.prototype.done = function (er, result) {
-  // if an error, and the code is EMFILE, then get in the queue
-  if (er && er.code === "EMFILE") {
+  var tryAgain = false
+  if (er) {
+    var code = er.code
+    var tryAgain = code === "EMFILE"
+    if (process.platform === "win32")
+      tryAgain = tryAgain || code === "OK"
+  }
+
+  if (tryAgain) {
     this.failures ++
     enqueue(this)
   } else {
diff --git a/package.json b/package.json
index 3663a44..b15f91f 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Isaac Z. Schlueter <i at izs.me> (http://blog.izs.me)",
   "name": "graceful-fs",
   "description": "A drop-in replacement for fs, making various improvements.",
-  "version": "2.0.0",
+  "version": "3.0.2",
   "repository": {
     "type": "git",
     "url": "git://github.com/isaacs/node-graceful-fs.git"
diff --git a/polyfills.js b/polyfills.js
index afc83b3..9d62af5 100644
--- a/polyfills.js
+++ b/polyfills.js
@@ -1,4 +1,4 @@
-var fs = require('fs')
+var fs = require('./fs.js')
 var constants = require('constants')
 
 var origCwd = process.cwd
@@ -116,15 +116,25 @@ if (!fs.lutimes) {
 
 // https://github.com/isaacs/node-graceful-fs/issues/4
 // Chown should not fail on einval or eperm if non-root.
+// It should not fail on enosys ever, as this just indicates
+// that a fs doesn't support the intended operation.
 
 fs.chown = chownFix(fs.chown)
 fs.fchown = chownFix(fs.fchown)
 fs.lchown = chownFix(fs.lchown)
 
+fs.chmod = chownFix(fs.chmod)
+fs.fchmod = chownFix(fs.fchmod)
+fs.lchmod = chownFix(fs.lchmod)
+
 fs.chownSync = chownFixSync(fs.chownSync)
 fs.fchownSync = chownFixSync(fs.fchownSync)
 fs.lchownSync = chownFixSync(fs.lchownSync)
 
+fs.chmodSync = chownFix(fs.chmodSync)
+fs.fchmodSync = chownFix(fs.fchmodSync)
+fs.lchmodSync = chownFix(fs.lchmodSync)
+
 function chownFix (orig) {
   if (!orig) return orig
   return function (target, uid, gid, cb) {
@@ -146,15 +156,32 @@ function chownFixSync (orig) {
   }
 }
 
+// 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 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.
-  if (!er || (!process.getuid || process.getuid() !== 0)
-      && (er.code === "EINVAL" || er.code === "EPERM")) return true
+  if (!er)
+    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
+  }
+
+  return false
 }
 
 
diff --git a/test/open.js b/test/open.js
index 104f36b..85732f2 100644
--- a/test/open.js
+++ b/test/open.js
@@ -2,7 +2,7 @@ var test = require('tap').test
 var fs = require('../graceful-fs.js')
 
 test('graceful fs is monkeypatched fs', function (t) {
-  t.equal(fs, require('fs'))
+  t.equal(fs, require('../fs.js'))
   t.end()
 })
 
diff --git a/test/readdir-sort.js b/test/readdir-sort.js
new file mode 100644
index 0000000..fe005aa
--- /dev/null
+++ b/test/readdir-sort.js
@@ -0,0 +1,21 @@
+var test = require("tap").test
+var fs = require("../fs.js")
+
+var readdir = fs.readdir
+fs.readdir = function(path, cb) {
+  process.nextTick(function() {
+    cb(null, ["b", "z", "a"])
+  })
+}
+
+var g = require("../")
+
+test("readdir reorder", function (t) {
+  g.readdir("whatevers", function (er, files) {
+    if (er)
+      throw er
+    console.error(files)
+    t.same(files, [ "a", "b", "z" ])
+    t.end()
+  })
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-graceful-fs.git



More information about the Pkg-javascript-commits mailing list