forked from isaacs/node-graceful-fs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always make
fs.Stats
’ .uid
and .gid
fields unsigned
At the time of writing, all currently published versions of Node.js return signed 32-bit integers in their return values for the `uid` and `gid` fields of `fs.Stats` instances. This is problematic, because some of Node’s other `fs` methods like `chown` expect unsigned 32-bit integer input and throw when encountering negative integers; this has broken e.g. `sudo npm install -g` on `OS X`, where `nobody` has a UID that would be returned as `-2` by `fs.stat()`. Ref: nodejs/node#8515 Ref: npm/npm#13918
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
var test = require('tap').test | ||
var util = require('util') | ||
var fs = require('fs') | ||
|
||
// mock fs.statSync to return signed uids/gids | ||
var realStatSync = fs.statSync | ||
fs.statSync = function(path) { | ||
var stats = realStatSync.call(fs, path) | ||
stats.uid = -2 | ||
stats.gid = -2 | ||
return stats | ||
} | ||
|
||
var gfs = require('../graceful-fs.js') | ||
|
||
test('graceful fs uses same stats constructor as fs', function (t) { | ||
t.equal(gfs.Stats, fs.Stats, 'should reference the same constructor') | ||
|
||
if (!process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH) { | ||
t.equal(fs.statSync(__filename).uid, -2) | ||
t.equal(fs.statSync(__filename).gid, -2) | ||
} | ||
|
||
t.equal(gfs.statSync(__filename).uid, 0xfffffffe) | ||
t.equal(gfs.statSync(__filename).gid, 0xfffffffe) | ||
|
||
t.end() | ||
}) |