Skip to content

Commit

Permalink
Use util._extend instead of the eval evil
Browse files Browse the repository at this point in the history
Fix #31
  • Loading branch information
isaacs committed Sep 12, 2014
1 parent 0caa115 commit 34e473a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
14 changes: 4 additions & 10 deletions fs.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
// eeeeeevvvvviiiiiiillllll
// more evil than monkey-patching the native builtin?
// Not sure.
// extend the builtin so that our monkeypatchery doesn't
// muck with things not using graceful-fs

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)
var util = require('util')
module.exports = util._extend({}, require('fs'))
1 change: 0 additions & 1 deletion test/readdir-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ 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()
})
Expand Down
28 changes: 28 additions & 0 deletions test/stat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var test = require('tap').test
var gfs = require('../graceful-fs.js')
var fs = require('fs')

var gstat, fstat

test('gfs.stat', function (t) {
gfs.stat(__filename, function (er, st) {
if (er) throw er
gstat = st
t.ok(st instanceof gfs.Stats, 'should instanceof gfs.Stats')
t.end()
})
})

test('fs.stat', function (t) {
fs.stat(__filename, function (er, st) {
if (er) throw er
fstat = st
t.ok(st instanceof fs.Stats, 'should instanceof fs.Stats')
t.end()
})
})

test('stats should match', function (t) {
t.similar(gstat, fstat)
t.end()
})

2 comments on commit 34e473a

@tschaub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on 560aaf5, I'm curious if others are reporting EMFILE with 3.0.3. I have a case where things work with 3.0.2 and fail with 3.0.3 (EMFILE). I'll open an issue if I can narrow it down a bit.

@tschaub
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#34 includes a small script to reproduce one issue on Node 0.10.

Please sign in to comment.