Skip to content

Commit

Permalink
fix: dont patch getuid and getgid on process anymore (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleen42 authored Jun 24, 2022
1 parent 1a1e18e commit 1c19e87
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ describe('process', () => {
expect(typeof _process).toBe('object');
});
it('.getuid() and .getgid()', () => {
expect(typeof proc.getuid()).toBe('number');
expect(typeof proc.getgid()).toBe('number');
expect(typeof proc.getuid?.() ?? 0).toBe('number');
expect(typeof proc.getgid?.() ?? 0).toBe('number');
});
it('.cwd()', () => {
expect(typeof proc.cwd()).toBe('string');
Expand Down
10 changes: 6 additions & 4 deletions src/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { EventEmitter } from 'events';
import Stats from './Stats';

const { S_IFMT, S_IFDIR, S_IFREG, S_IFLNK, O_APPEND } = constants;
const getuid = (): number => process.getuid?.() ?? 0;
const getgid = (): number => process.getgid?.() ?? 0;

export const SEP = '/';

Expand All @@ -17,8 +19,8 @@ export class Node extends EventEmitter {
ino: number;

// User ID and group ID.
uid: number = process.getuid();
gid: number = process.getgid();
uid: number = getuid();
gid: number = getgid();

atime = new Date();
mtime = new Date();
Expand Down Expand Up @@ -167,7 +169,7 @@ export class Node extends EventEmitter {
this.emit('change', this);
}

canRead(uid: number = process.getuid(), gid: number = process.getgid()): boolean {
canRead(uid: number = getuid(), gid: number = getgid()): boolean {
if (this.perm & S.IROTH) {
return true;
}
Expand All @@ -187,7 +189,7 @@ export class Node extends EventEmitter {
return false;
}

canWrite(uid: number = process.getuid(), gid: number = process.getgid()): boolean {
canWrite(uid: number = getuid(), gid: number = getgid()): boolean {
if (this.perm & S.IWOTH) {
return true;
}
Expand Down
6 changes: 2 additions & 4 deletions src/process.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Here we mock the global `process` variable in case we are not in Node's environment.

export interface IProcess {
getuid(): number;
getuid?(): number;

getgid(): number;
getgid?(): number;

cwd(): string;

Expand Down Expand Up @@ -38,8 +38,6 @@ const maybeReturnProcess = (): IProcess | undefined => {
export function createProcess(): IProcess {
const p: IProcess = maybeReturnProcess() || ({} as IProcess);

if (!p.getuid) p.getuid = () => 0;
if (!p.getgid) p.getgid = () => 0;
if (!p.cwd) p.cwd = () => '/';
if (!p.nextTick) p.nextTick = require('./setImmediate').default;
if (!p.emitWarning)
Expand Down

0 comments on commit 1c19e87

Please sign in to comment.