Skip to content

Commit 9caaa2c

Browse files
author
Akos Kitta
committed
fix: bail when sketchbook dir is an existing file
Signed-off-by: Akos Kitta <[email protected]>
1 parent 7efc4c8 commit 9caaa2c

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

Diff for: arduino-ide-extension/src/browser/dialogs/settings/settings.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
import { ElectronCommands } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
2828
import { DefaultTheme } from '@theia/application-package/lib/application-props';
2929
import { FrontendApplicationConfigProvider } from '@theia/core/lib/browser/frontend-application-config-provider';
30+
import type { FileStat } from '@theia/filesystem/lib/common/files';
3031

3132
export const WINDOW_SETTING = 'window';
3233
export const EDITOR_SETTING = 'editor';
@@ -231,7 +232,11 @@ export class SettingsService {
231232
try {
232233
const { sketchbookPath, editorFontSize, themeId } = await settings;
233234
const sketchbookDir = await this.fileSystemExt.getUri(sketchbookPath);
234-
if (!(await this.fileService.exists(new URI(sketchbookDir)))) {
235+
let sketchbookStat: FileStat | undefined = undefined;
236+
try {
237+
sketchbookStat = await this.fileService.resolve(new URI(sketchbookDir));
238+
} catch {}
239+
if (!sketchbookStat || !sketchbookStat.isDirectory) {
235240
return nls.localize(
236241
'arduino/preferences/invalid.sketchbook.location',
237242
'Invalid sketchbook location: {0}',

Diff for: arduino-ide-extension/src/node/config-service-impl.ts

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { promises as fs, constants } from 'fs';
1+
import { promises as fs } from 'fs';
22
import { dirname } from 'path';
33
import * as yaml from 'js-yaml';
44
import * as grpc from '@grpc/grpc-js';
@@ -259,25 +259,23 @@ export class ConfigServiceImpl
259259
private async checkAccessible({
260260
directories,
261261
}: DefaultCliConfig): Promise<string[]> {
262-
const accessible = (folderPath: string) =>
263-
fs.access(folderPath, constants.R_OK | constants.W_OK);
264-
const toConfigErrors = (
265-
folderPath: string,
266-
result: PromiseSettledResult<unknown>
267-
) =>
268-
result.status === 'rejected'
269-
? [
270-
nls.localize(
271-
'arduino/configuration/cli/inaccessibleDirectory',
272-
"Could not access the sketchbook location at '{0}': {1}",
273-
folderPath,
274-
String(result.reason)
275-
),
276-
]
277-
: [];
278-
const { user } = directories;
279-
const [userAccessible] = await Promise.allSettled([accessible(user)]); // XXX: validate `directory.data` if required
280-
return [...toConfigErrors(user, userAccessible)];
262+
try {
263+
await fs.readdir(directories.user);
264+
return [];
265+
} catch (err) {
266+
console.error(
267+
`Check accessible failed for input: ${directories.user}`,
268+
err
269+
);
270+
return [
271+
nls.localize(
272+
'arduino/configuration/cli/inaccessibleDirectory',
273+
"Could not access the sketchbook location at '{0}': {1}",
274+
directories.user,
275+
String(err)
276+
),
277+
];
278+
}
281279
}
282280

283281
private async updateDaemon(

0 commit comments

Comments
 (0)