Skip to content
Merged
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
45 changes: 19 additions & 26 deletions src/vs/platform/native/electron-main/nativeHostMainService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
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));
}
}

Expand Down
Loading