Skip to content

Commit d9e32b3

Browse files
authored
Merge pull request #8 from vikas-lt/MLE-3611
handle file permission issue when it tries to update the deprected tu…
2 parents e1660e6 + 981a29f commit d9e32b3

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

lib/tunnel_binary.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ function TunnelBinary(httpTunnelConfig, options) {
1919
this.binaryVersion = 'v3';
2020
if (options['legacy']) {
2121
this.binaryVersion = 'v2';
22-
executableName = "ltcomponent";
22+
executableName = 'ltcomponent';
2323
}
2424
this.httpTunnelConfig = httpTunnelConfig;
2525
this.hostOS = process.platform;
@@ -37,13 +37,14 @@ function TunnelBinary(httpTunnelConfig, options) {
3737
this.httpPath = this.httpTunnelConfig.jsonResponse.binaryLinks[this.platform][this.binaryVersion][
3838
this.bits
3939
].httpPath;
40-
this.binaryName = this.httpTunnelConfig.jsonResponse.binaryLinks[this.platform][this.binaryVersion][
41-
this.bits
42-
].binaryName;
43-
this.httpHashContents = this.httpTunnelConfig.jsonResponse.binaryLinks[this.platform][this.binaryVersion][
44-
this.bits
45-
].hash;
46-
this.localHashContents = localTunnelConfig_.binaryLinks[this.platform][this.binaryVersion][this.bits].hash;
40+
this.binaryName = this.httpTunnelConfig.jsonResponse.binaryLinks[this.platform][
41+
this.binaryVersion
42+
][this.bits].binaryName;
43+
this.httpHashContents = this.httpTunnelConfig.jsonResponse.binaryLinks[this.platform][
44+
this.binaryVersion
45+
][this.bits].hash;
46+
this.localHashContents =
47+
localTunnelConfig_.binaryLinks[this.platform][this.binaryVersion][this.bits].hash;
4748
logger = this.httpTunnelConfig.logger;
4849

4950
/**
@@ -91,7 +92,7 @@ function TunnelBinary(httpTunnelConfig, options) {
9192
if (this.checkPath_(destParentDir)) {
9293
this.rmDir(destParentDir);
9394
}
94-
fs.mkdirSync(destParentDir, { recursive : true });
95+
fs.mkdirSync(destParentDir, { recursive: true });
9596
// Generate binary path.
9697
var binaryPath = path.join(destParentDir, this.binaryName);
9798
var fileStream = fs.createWriteStream(binaryPath);
@@ -217,10 +218,18 @@ function TunnelBinary(httpTunnelConfig, options) {
217218
return fnCallback(binaryPath);
218219
} else {
219220
console.log(`Binary is deprecated`);
220-
fs.writeFileSync(
221-
__dirname + '/cfg/node-tunnel-config-v3-latest.json',
222-
JSON.stringify(this.httpTunnelConfig.jsonResponse)
223-
);
221+
try {
222+
fs.writeFileSync(
223+
__dirname + '/cfg/node-tunnel-config-v3-latest.json',
224+
JSON.stringify(this.httpTunnelConfig.jsonResponse)
225+
);
226+
} catch (e) {
227+
console.log(
228+
'Permission denied! Please execute the command using sudo or provide the required read & write permissions to file : ',
229+
__dirname + '/cfg/node-tunnel-config-v3-latest.json'
230+
);
231+
throw e;
232+
}
224233
localTunnelConfig_ = this.httpTunnelConfig.jsonResponse;
225234
that.download_(conf, destParentDir, 5, fnCallback);
226235
}
@@ -263,7 +272,8 @@ function TunnelBinary(httpTunnelConfig, options) {
263272
*/
264273
this.availableDirs_ = function() {
265274
var orderedPathLength = this.orderedPaths.length;
266-
var _path, iCounter = 0;
275+
var _path,
276+
iCounter = 0;
267277
for (var i = 0; i < orderedPathLength; i++) {
268278
iCounter++;
269279
_path = this.orderedPaths[i];
@@ -284,7 +294,7 @@ function TunnelBinary(httpTunnelConfig, options) {
284294
this.makePath_ = function(path) {
285295
try {
286296
if (!this.checkPath_(path)) {
287-
fs.mkdirSync(path, { recursive : true });
297+
fs.mkdirSync(path, { recursive: true });
288298
}
289299
return true;
290300
} catch (e) {
@@ -333,7 +343,11 @@ function TunnelBinary(httpTunnelConfig, options) {
333343
fs.rmdirSync(dir);
334344
}
335345
};
336-
this.orderedPaths = [path.join(this.homeDir_(), '.lambdatest', this.binaryVersion), path.join(process.cwd(), this.binaryVersion), path.join(os.tmpdir(), this.binaryVersion )];
346+
this.orderedPaths = [
347+
path.join(this.homeDir_(), '.lambdatest', this.binaryVersion),
348+
path.join(process.cwd(), this.binaryVersion),
349+
path.join(os.tmpdir(), this.binaryVersion)
350+
];
337351
}
338352

339353
module.exports = TunnelBinary;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/node-tunnel",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "Nodejs bindings for LambdaTest Tunnel",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)