Wrong fs.stat size on win32 #1647

Closed
fprijate opened this Issue Sep 4, 2011 · 7 comments

Projects

None yet

5 participants

@fprijate

platform win32, MSVC build

fs.stat and fs.statSync return wrong size

@piscisaureus
Node.js Foundation member

We may be mixing up struct _stat and struct _stat64.

@fprijate

Yes with this change size is correct (on XP)
On win7 probably _wstat64 ?

diff D:/INSTALL/AJAX/node/src/node.h D:/INSTALL/AJAX/node1/src/node.h
117,119c117,119
< # define NODE_STAT _stati64
< # define NODE_FSTAT _fstati64
< # define NODE_STAT_STRUCT struct _stati64
---
> # define NODE_STAT _stat
> # define NODE_FSTAT _fstat
> # define NODE_STAT_STRUCT struct _stat

@piscisaureus
Node.js Foundation member

This bug should be closed after the next libuv update.

@cryptix

Looks fixed to me. (msvc build @8153a21, xp sp3)

var assert = require('assert');
var fs = require('fs');

var data = Buffer("Some data to test writing and stating afterwards");


// sync
var fd = fs.openSync('test.txt', 'w');
fs.writeSync(fd, data, 0, data.length, 0);
fs.close(fd);

var s = fs.statSync('test.txt');
assert.equal(s.size+1, data.length);

// async
fs.open('test.txt', 'w', function(err, fd) {
  fs.write(fd, data, 0, data.length, 0, function(err, w, buf) {
    if(w == data.length) {
      fs.close(fd);
      fs.stat('test.txt', function (err, stats) {
        assert.equal(stats.size, data.length);
      });
    }
  });
});
@bnoordhuis
Node.js Foundation member

@cryptix: why the s.size+1? Your test fails for me here (linux, latest master) as I suppose it should.

@cryptix

Oh no.. thats awkward.. i'm sorry.
Of Course it fails for me, too. I wanted to see if the assertion triggers if the size would be off and copyd without paying attention.
Without the +1 the test should be fine i think.. ~_~

@fprijate fprijate closed this Sep 7, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment