Skip to content

Commit ae38cfe

Browse files
3cptschaub
authored andcommitted
chore: use 0 internally for uid/gid on Windows
1 parent 980447a commit ae38cfe

File tree

1 file changed

+9
-23
lines changed

1 file changed

+9
-23
lines changed

lib/item.js

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ const permissions = {
1919
};
2020

2121
function getUid() {
22-
// force NaN on windows.
23-
return process.getuid ? process.getuid() : NaN;
22+
// force 0 on windows.
23+
return process.getuid ? process.getuid() : 0;
2424
}
2525

2626
function getGid() {
27-
// force NaN on windows.
28-
return process.getgid ? process.getgid() : NaN;
27+
// force 0 on windows.
28+
return process.getgid ? process.getgid() : 0;
2929
}
3030

3131
/**
@@ -110,8 +110,7 @@ Item.prototype.canRead = function() {
110110
let can = false;
111111
if (uid === 0) {
112112
can = true;
113-
} else if (uid === this._uid || uid !== uid) {
114-
// (uid !== uid) means uid is NaN, only for windows
113+
} else if (uid === this._uid) {
115114
can = (permissions.USER_READ & this._mode) === permissions.USER_READ;
116115
} else if (gid === this._gid) {
117116
can = (permissions.GROUP_READ & this._mode) === permissions.GROUP_READ;
@@ -131,8 +130,7 @@ Item.prototype.canWrite = function() {
131130
let can = false;
132131
if (uid === 0) {
133132
can = true;
134-
} else if (uid === this._uid || uid !== uid) {
135-
// (uid !== uid) means uid is NaN, only for windows
133+
} else if (uid === this._uid) {
136134
can = (permissions.USER_WRITE & this._mode) === permissions.USER_WRITE;
137135
} else if (gid === this._gid) {
138136
can = (permissions.GROUP_WRITE & this._mode) === permissions.GROUP_WRITE;
@@ -152,8 +150,7 @@ Item.prototype.canExecute = function() {
152150
let can = false;
153151
if (uid === 0) {
154152
can = true;
155-
} else if (uid === this._uid || isNaN(uid)) {
156-
// NaN occurs on windows
153+
} else if (uid === this._uid) {
157154
can = (permissions.USER_EXEC & this._mode) === permissions.USER_EXEC;
158155
} else if (gid === this._gid) {
159156
can = (permissions.GROUP_EXEC & this._mode) === permissions.GROUP_EXEC;
@@ -289,19 +286,8 @@ Item.prototype.getStats = function(bigint) {
289286
stats[0] = convert(8675309); // dev
290287
// [1] is mode
291288
stats[2] = convert(this.links); // nlink
292-
293-
const uid = this.getUid();
294-
if (!isNaN(uid)) {
295-
// uid is NaN on windows
296-
stats[3] = convert(uid); // uid
297-
}
298-
299-
const gid = this.getGid();
300-
if (!isNaN(gid)) {
301-
// gid is NaN on windows
302-
stats[4] = convert(gid); // gid
303-
}
304-
289+
stats[3] = convert(this.getUid()); // uid
290+
stats[4] = convert(this.getGid()); // gid
305291
stats[5] = convert(0); // rdev
306292
stats[6] = convert(4096); // blksize
307293
stats[7] = convert(this._id); // ino

0 commit comments

Comments
 (0)