Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Wrong fs.stat size on win32 #1647

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

Wrong fs.stat size on win32 #1647

fprijate opened this issue Sep 4, 2011 · 7 comments

Comments

@fprijate
Copy link

fprijate commented Sep 4, 2011

platform win32, MSVC build

fs.stat and fs.statSync return wrong size

@piscisaureus
Copy link

We may be mixing up struct _stat and struct _stat64.

@fprijate
Copy link
Author

fprijate commented Sep 4, 2011

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

@ry
Copy link

ry commented Sep 5, 2011

see joyent/libuv@b90459f

@piscisaureus
Copy link

This bug should be closed after the next libuv update.

@cryptix
Copy link

cryptix commented Sep 6, 2011

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
Copy link
Member

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

@cryptix
Copy link

cryptix commented Sep 6, 2011

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 as completed Sep 7, 2011
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants