Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Commit 3649e62

Browse files
authored
Merge pull request #1601 from microsoft/dev/bemcmorr/bundled-cli-check-executable
Don't set CLI executable bit if already set
2 parents 374c78f + 92d7eaf commit 3649e62

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/arduino/arduinoSettings.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
import { chmod } from "fs/promises";
4+
import { constants as fsconstants, promises as fs } from "fs";
55
import * as os from "os";
66
import * as path from "path";
77
import * as vscode from "vscode";
88
import * as WinReg from "winreg";
99
import * as util from "../common/util";
1010

11+
import { messages } from "../common/constants";
1112
import { resolveArduinoPath } from "../common/platform";
1213

1314
import * as Logger from "../logger/logger";
@@ -248,7 +249,26 @@ export class ArduinoSettings implements IArduinoSettings {
248249
if (bundledPath && this._useArduinoCli && !this._commandPath) {
249250
// The extension VSIX stripped the executable bit, so we need to set it.
250251
// 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+
252272
this._usingBundledArduinoCli = true;
253273
Logger.traceUserData("using-bundled-arduino-cli");
254274
this._arduinoPath = path.dirname(bundledPath);

src/common/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const messages = {
3737
SERIAL_PORT_NOT_STARTED: "Serial Monitor has not been started.",
3838
SEND_BEFORE_OPEN_SERIALPORT: "Please open a serial port first.",
3939
NO_PROGRAMMMER_SELECTED: "Please select the programmer first.",
40+
ARDUINO_CLI_NOT_EXECUTABLE: "The bundled Arduino CLI could not be marked executable. Ensure that VS Code is able to execute:",
4041
};
4142

4243
export const statusBarPriority = {

0 commit comments

Comments
 (0)