Skip to content

Commit bc4c3e0

Browse files
author
Akos Kitta
committed
fixed issue when checking if a sketch is temp
convert all windows drive letters to lower case. [ATL-380] Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent aa2bed8 commit bc4c3e0

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

arduino-ide-extension/src/common/utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ export const naturalCompare: (left: string, right: string) => number = require('
33
export function notEmpty(arg: string | undefined | null): arg is string {
44
return !!arg;
55
}
6+
7+
export function firstToLowerCase(what: string): string {
8+
return what.charAt(0).toLowerCase() + what.slice(1);
9+
}

arduino-ide-extension/src/node/sketches-service-impl.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ import { ncp } from 'ncp';
66
import { Stats } from 'fs';
77
import * as fs from './fs-extra';
88
import URI from '@theia/core/lib/common/uri';
9+
import { isWindows } from '@theia/core/lib/common/os';
910
import { FileUri, BackendApplicationContribution } from '@theia/core/lib/node';
1011
import { ConfigService } from '../common/protocol/config-service';
1112
import { SketchesService, Sketch } from '../common/protocol/sketches-service';
13+
import { firstToLowerCase } from '../common/utils';
1214

1315

1416
// As currently implemented on Linux,
1517
// the maximum number of symbolic links that will be followed while resolving a pathname is 40
1618
const MAX_FILESYSTEM_DEPTH = 40;
1719

20+
const WIN32_DRIVE_REGEXP = /^[a-zA-Z]:\\/;
21+
1822
// TODO: `fs`: use async API
1923
@injectable()
2024
export class SketchesServiceImpl implements SketchesService, BackendApplicationContribution {
@@ -330,8 +334,19 @@ void loop() {
330334
}
331335

332336
async isTemp(sketch: Sketch): Promise<boolean> {
333-
const sketchPath = FileUri.fsPath(sketch.uri);
334-
return sketchPath.indexOf('.arduinoProIDE-unsaved') !== -1 && sketchPath.startsWith(os.tmpdir());
337+
let sketchPath = FileUri.fsPath(sketch.uri);
338+
let temp = os.tmpdir();
339+
// Note: VS Code URI normalizes the drive letter. `C:` will be converted into `c:`.
340+
// https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992
341+
if (isWindows) {
342+
if (WIN32_DRIVE_REGEXP.exec(sketchPath)) {
343+
sketchPath = firstToLowerCase(sketchPath);
344+
}
345+
if (WIN32_DRIVE_REGEXP.exec(temp)) {
346+
temp = firstToLowerCase(temp);
347+
}
348+
}
349+
return sketchPath.indexOf('.arduinoProIDE-unsaved') !== -1 && sketchPath.startsWith(temp);
335350
}
336351

337352
async copy(sketch: Sketch, { destinationUri }: { destinationUri: string }): Promise<string> {

0 commit comments

Comments
 (0)