Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of util.inherits() is discouraged. #2908

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions lib/run/secure-fs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const fs = require('fs'),
_ = require('lodash'),
path = require('path'),
util = require('util'),
Readable = require('stream').Readable,

PPERM_ERR = 'PPERM: insecure file access outside working directory',
Expand Down Expand Up @@ -166,22 +165,21 @@ SecureFS.prototype.createReadStream = function (path, options) {
return this._fs.createReadStream(this.resolvePathSync(path), options);
}
catch (err) {
// Create a fake read steam that emits and error and
const ErrorReadStream = function () {
// Replicating behavior of fs module of disabling emitClose on destroy
Readable.call(this, { emitClose: false });

// Emit the error event with insure file access error
this.emit('error', new Error(PPERM_ERR));

// Options exists and disables autoClose then don't destroy
(options && !options.autoClose) || this.destroy();
};

util.inherits(ErrorReadStream, Readable);
// Create a fake read stream that emits and error
class ErrorReadStream extends Readable {
constructor () {
// Replicating behavior of fs module of disabling emitClose on destroy
super({ emitClose: false });
// Emit the error event with insure file access error
this.emit('error', new Error(PPERM_ERR));
// Options exists and disables autoClose then don't destroy
(options && !options.autoClose) || this.destroy();
}
}

return new ErrorReadStream();
}
};

module.exports = SecureFS;