From a0e0f9401fae28e862c1ba9d6d97821f9bf75256 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 7 Aug 2025 19:39:31 +0900 Subject: [PATCH] fix: re-install command on macOS via elevation --- .../electron-main/nativeHostMainService.ts | 45 ++++++++----------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/vs/platform/native/electron-main/nativeHostMainService.ts b/src/vs/platform/native/electron-main/nativeHostMainService.ts index dd6c9a4618cf3..f1976f4e7e6fc 100644 --- a/src/vs/platform/native/electron-main/nativeHostMainService.ts +++ b/src/vs/platform/native/electron-main/nativeHostMainService.ts @@ -396,41 +396,34 @@ export class NativeHostMainService extends Disposable implements INativeHostMain return; } } - - // Different source, delete it first - await fs.promises.unlink(source); } catch (error) { if (error.code !== 'ENOENT') { throw error; // throw on any error but file not found } } - try { - await fs.promises.symlink(target, source); - } catch (error) { - if (error.code !== 'EACCES' && error.code !== 'ENOENT') { - throw error; - } + await this.installShellCommandWithPrivileges(windowId, source, target); + } - const { response } = await this.showMessageBox(windowId, { - type: 'info', - message: localize('warnEscalation', "{0} will now prompt with 'osascript' for Administrator privileges to install the shell command.", this.productService.nameShort), - buttons: [ - localize({ key: 'ok', comment: ['&& denotes a mnemonic'] }, "&&OK"), - localize('cancel', "Cancel") - ] - }); + private async installShellCommandWithPrivileges(windowId: number | undefined, source: string, target: string): Promise { + const { response } = await this.showMessageBox(windowId, { + type: 'info', + message: localize('warnEscalation', "{0} will now prompt with 'osascript' for Administrator privileges to install the shell command.", this.productService.nameShort), + buttons: [ + localize({ key: 'ok', comment: ['&& denotes a mnemonic'] }, "&&OK"), + localize('cancel', "Cancel") + ] + }); - if (response === 1 /* Cancel */) { - throw new CancellationError(); - } + if (response === 1 /* Cancel */) { + throw new CancellationError(); + } - try { - const command = `osascript -e "do shell script \\"mkdir -p /usr/local/bin && ln -sf \'${target}\' \'${source}\'\\" with administrator privileges"`; - await promisify(exec)(command); - } catch (error) { - throw new Error(localize('cantCreateBinFolder', "Unable to install the shell command '{0}'.", source)); - } + try { + const command = `osascript -e "do shell script \\"mkdir -p /usr/local/bin && ln -sf \'${target}\' \'${source}\'\\" with administrator privileges"`; + await promisify(exec)(command); + } catch (error) { + throw new Error(localize('cantCreateBinFolder', "Unable to install the shell command '{0}'.", source)); } }