Skip to content

Commit 4f7a0f7

Browse files
committed
fix: auto chmod binary files
1 parent 38bd2e3 commit 4f7a0f7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/launcher/index.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { spawnSync } from 'child_process';
22
import os from 'os';
33
import path from 'path';
4+
import { chmodSync, statSync } from 'fs';
45

56
const platform = os.platform();
67
const arch = os.arch();
@@ -39,6 +40,14 @@ const executablePath = path.resolve(path.join(
3940
platform === 'win32' ? 'ipc-json-bridge.exe' : 'ipc-json-bridge'
4041
));
4142

43+
try {
44+
const stats = statSync(executablePath);
45+
if (!(stats.mode & 0o100)) chmodSync(executablePath, stats.mode | 0o100);
46+
} catch (error) {
47+
console.error(`Failed to check/fix permissions for ${executablePath}:`, error.message);
48+
process.exit(1);
49+
}
50+
4251
const result = spawnSync(executablePath, process.argv.slice(2), { stdio: 'inherit' });
4352

4453
if (result.error) {

src/sdk/Service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { spawn, ChildProcess } from 'child_process';
22
import { join, resolve } from 'path';
3+
import { existsSync, statSync, chmodSync } from 'fs';
34
import { platform, arch } from 'os';
45
import { EventEmitter } from 'events';
56
import {
@@ -34,6 +35,9 @@ export class IpcBridge extends EventEmitter {
3435
this.socketPath = options.socketPath || '';
3536
if (this.isClient && !this.socketPath) throw new Error('Client mode requires a socket path');
3637
this.binaryPath = this.resolveBinaryPath(options.binaryPath);
38+
if (!existsSync(this.binaryPath)) {
39+
throw new Error(`IPC bridge binary not found: ${this.binaryPath}`);
40+
}
3741
}
3842

3943
// Type-safe event emitter methods
@@ -111,6 +115,9 @@ export class IpcBridge extends EventEmitter {
111115
throw new Error('IPC bridge is already running');
112116
}
113117

118+
const stats = statSync(this.binaryPath);
119+
if (!(stats.mode & 0o100)) chmodSync(this.binaryPath, stats.mode | 0o100);
120+
114121
return new Promise((resolve, reject) => {
115122
const args = [
116123
this.isClient ? '--client' : '--server',

0 commit comments

Comments
 (0)