aboutsummaryrefslogtreecommitdiff
path: root/src/library_nodefs.js
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2013-10-22 13:34:32 +0300
committerJukka Jylänki <jujjyl@gmail.com>2013-10-22 13:34:32 +0300
commitaea0476209dd2eec119a7678bdde9e8aa5bc1b83 (patch)
tree3b1a005b384135e682e3b26ee626ddbc5a7a0744 /src/library_nodefs.js
parentbe989520749958289c1d0be30389550ff79dde6b (diff)
Fake node.js stat() call on Windows to report a blocksize and blocks number. Otherwise these would be 'undefined', which later in unit tests would throw an error in SAFE_HEAP_STORE. Fixes o1.test_unistd_truncate.
Diffstat (limited to 'src/library_nodefs.js')
-rw-r--r--src/library_nodefs.js13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/library_nodefs.js b/src/library_nodefs.js
index fc36a8ac..af3a10ea 100644
--- a/src/library_nodefs.js
+++ b/src/library_nodefs.js
@@ -2,8 +2,10 @@ mergeInto(LibraryManager.library, {
$NODEFS__deps: ['$FS', '$PATH'],
$NODEFS__postset: 'if (ENVIRONMENT_IS_NODE) { var fs = require("fs"); }',
$NODEFS: {
+ isWindows: false,
mount: function (mount) {
assert(ENVIRONMENT_IS_NODE);
+ NODEFS.isWindows = !!process.platform.match(/^win/); // Do this (possibly costly?) check ahead of time to not have to do it at runtime below.
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
},
createNode: function (parent, name, mode, dev) {
@@ -19,8 +21,7 @@ mergeInto(LibraryManager.library, {
var stat;
try {
stat = fs.lstatSync(path);
- var isWin = !!process.platform.match(/^win/);
- if (isWin) {
+ if (NODEFS.isWindows) {
// On Windows, directories return permission bits 'rw-rw-rw-', even though they have 'rwxrwxrwx', so
// propagate write bits to execute bits.
stat.mode = stat.mode | ((stat.mode & 146) >> 1);
@@ -86,6 +87,14 @@ mergeInto(LibraryManager.library, {
if (!e.code) throw e;
throw new FS.ErrnoError(ERRNO_CODES[e.code]);
}
+ // node.js v0.10.20 doesn't report blksize and blocks on Windows. Fake them with default blksize of 4096.
+ // See http://support.microsoft.com/kb/140365
+ if (NODEFS.isWindows && !stat.blksize) {
+ stat.blksize = 4096;
+ }
+ if (NODEFS.isWindows && !stat.blocks) {
+ stat.blocks = (stat.size+stat.blksize-1)/stat.blksize|0;
+ }
return {
dev: stat.dev,
ino: stat.ino,