Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs.lstatSync() isn't instance of fs.Stats on Node.js 0.12 #35

Closed
okuryu opened this issue Nov 1, 2014 · 5 comments
Closed

fs.lstatSync() isn't instance of fs.Stats on Node.js 0.12 #35

okuryu opened this issue Nov 1, 2014 · 5 comments

Comments

@okuryu
Copy link

okuryu commented Nov 1, 2014

Result of fs.lstatSync() isn't instance of fs.Stats with [email protected] on Node.js 0.11. This problem doesn't occur with [email protected].

Example code (index.js) as follows.

var gfs = require("graceful-fs");
var fs = require("fs");
var path = "file1.txt";

gfs.writeFileSync(path, "Files Test");
console.log(gfs.lstatSync(path) instanceof fs.Stats);
gfs.unlinkSync("file1.txt");

[email protected]:

$ node -v
v0.11.14
$ node index.js
true

[email protected]:

$ node -v
v0.11.14
$ node index.js
false
@okuryu
Copy link
Author

okuryu commented Dec 2, 2014

It's still occurs with [email protected].

@isaacs Could you take a look? 😢

@okuryu okuryu changed the title fs.lstatSync() isn't instance of fs.Stats on Node.js 0.11 fs.lstatSync() isn't instance of fs.Stats on Node.js 0.12 Feb 7, 2015
@cainjonm
Copy link

This also seems to effect the fs module globally too. Which i think is caused by nodejs/node-v0.x-archive@e9ce8fc

When graceful-fs is require'd, the Stats constructor is rebound in native code (https://github.com/joyent/node/blob/e9ce8fc82a6d12e790511b62852e820d8be03186/lib/fs.js#L151). If this makes sense, it would explain why importing graceful-fs seems to effect fs too (i think?). I have included code to show what I mean.

Using node v0.12.2 and graceful-fs version 3.0.6.

var fs = require("fs"); 
var path = "file1.txt"; 

fs.writeFileSync(path, "Files Test");
fs.stat(path, function (err, stat) { 
    console.log("A", stat instanceof fs.Stats); // true 

    var gfs = require("graceful-fs"); 

    fs.stat(path, function (err, stat) { 
        console.log("B", stat instanceof fs.Stats); // false <-- :(
        console.log("C", stat instanceof gfs.Stats); // true 
    }); 
}); 

etiktin added a commit to etiktin/node-graceful-fs that referenced this issue Jun 6, 2015
This commit fixes issue isaacs#35
@etiktin
Copy link
Contributor

etiktin commented Jun 6, 2015

@cainjonm, you are correct. The main issue here is breaking the global fs module by changing the Stats constructor that the native code uses.

PR #42 fixes it.

For the time being if you want to fix it in your code, you can add the following lines after the first load of gfs:

var binding = process.binding('fs')
if (binding.FSInitialize) {
  binding.FSInitialize(fs.Stats)
  gfs.Stats = fs.Stats
}

@okuryu
Copy link
Author

okuryu commented Jun 28, 2015

This seems to be resolved in graceful-fs v4.x, right?

@etiktin
Copy link
Contributor

etiktin commented Jun 28, 2015

Yes, it's resolved.
To be sure everything else works for you, I suggest you run npm test on your platform and see that everything works for you (on Windows, it seems that some of the tests fail, but it might be an issue with rimraf).

@isaacs isaacs closed this as completed Jun 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants