|
1 | 1 | // Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | // Licensed under the MIT license.
|
3 | 3 |
|
4 |
| -import { chmod } from "fs/promises"; |
| 4 | +import { constants as fsconstants, promises as fs } from "fs"; |
5 | 5 | import * as os from "os";
|
6 | 6 | import * as path from "path";
|
7 | 7 | import * as vscode from "vscode";
|
8 | 8 | import * as WinReg from "winreg";
|
9 | 9 | import * as util from "../common/util";
|
10 | 10 |
|
| 11 | +import { messages } from "../common/constants"; |
11 | 12 | import { resolveArduinoPath } from "../common/platform";
|
12 | 13 |
|
13 | 14 | import * as Logger from "../logger/logger";
|
@@ -248,7 +249,26 @@ export class ArduinoSettings implements IArduinoSettings {
|
248 | 249 | if (bundledPath && this._useArduinoCli && !this._commandPath) {
|
249 | 250 | // The extension VSIX stripped the executable bit, so we need to set it.
|
250 | 251 | // 0x755 means rwxr-xr-x (read and execute for everyone, write for owner).
|
251 |
| - await chmod(bundledPath, 0o755); |
| 252 | + // There have been reports of the executable bit already being set on M1 |
| 253 | + // Macs, but this call failing, so first check to see if the file is |
| 254 | + // already executable. |
| 255 | + // https://github.com/microsoft/vscode-arduino/issues/1599 |
| 256 | + let isExecutable = false; |
| 257 | + try { |
| 258 | + await fs.access(bundledPath, fsconstants.X_OK); |
| 259 | + isExecutable = true; |
| 260 | + } catch { |
| 261 | + // Nothing to do. isExecutable is already false. |
| 262 | + } |
| 263 | + |
| 264 | + if (!isExecutable) { |
| 265 | + try { |
| 266 | + await fs.chmod(bundledPath, 0o755); |
| 267 | + } catch (e) { |
| 268 | + Logger.notifyUserError("arduino-cli-not-executable", e, messages.ARDUINO_CLI_NOT_EXECUTABLE + " " + bundledPath); |
| 269 | + } |
| 270 | + } |
| 271 | + |
252 | 272 | this._usingBundledArduinoCli = true;
|
253 | 273 | Logger.traceUserData("using-bundled-arduino-cli");
|
254 | 274 | this._arduinoPath = path.dirname(bundledPath);
|
|
0 commit comments