From bc4c3e04f59232ba9ef04fb2246be86fa8b7da93 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Mon, 10 Aug 2020 13:46:36 +0200 Subject: [PATCH] fixed issue when checking if a sketch is temp convert all windows drive letters to lower case. [ATL-380] Signed-off-by: Akos Kitta --- arduino-ide-extension/src/common/utils.ts | 4 ++++ .../src/node/sketches-service-impl.ts | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/arduino-ide-extension/src/common/utils.ts b/arduino-ide-extension/src/common/utils.ts index 7c438918..5e355dad 100644 --- a/arduino-ide-extension/src/common/utils.ts +++ b/arduino-ide-extension/src/common/utils.ts @@ -3,3 +3,7 @@ export const naturalCompare: (left: string, right: string) => number = require(' export function notEmpty(arg: string | undefined | null): arg is string { return !!arg; } + +export function firstToLowerCase(what: string): string { + return what.charAt(0).toLowerCase() + what.slice(1); +} diff --git a/arduino-ide-extension/src/node/sketches-service-impl.ts b/arduino-ide-extension/src/node/sketches-service-impl.ts index b694c20e..f79e8480 100644 --- a/arduino-ide-extension/src/node/sketches-service-impl.ts +++ b/arduino-ide-extension/src/node/sketches-service-impl.ts @@ -6,15 +6,19 @@ import { ncp } from 'ncp'; import { Stats } from 'fs'; import * as fs from './fs-extra'; import URI from '@theia/core/lib/common/uri'; +import { isWindows } from '@theia/core/lib/common/os'; import { FileUri, BackendApplicationContribution } from '@theia/core/lib/node'; import { ConfigService } from '../common/protocol/config-service'; import { SketchesService, Sketch } from '../common/protocol/sketches-service'; +import { firstToLowerCase } from '../common/utils'; // As currently implemented on Linux, // the maximum number of symbolic links that will be followed while resolving a pathname is 40 const MAX_FILESYSTEM_DEPTH = 40; +const WIN32_DRIVE_REGEXP = /^[a-zA-Z]:\\/; + // TODO: `fs`: use async API @injectable() export class SketchesServiceImpl implements SketchesService, BackendApplicationContribution { @@ -330,8 +334,19 @@ void loop() { } async isTemp(sketch: Sketch): Promise { - const sketchPath = FileUri.fsPath(sketch.uri); - return sketchPath.indexOf('.arduinoProIDE-unsaved') !== -1 && sketchPath.startsWith(os.tmpdir()); + let sketchPath = FileUri.fsPath(sketch.uri); + let temp = os.tmpdir(); + // Note: VS Code URI normalizes the drive letter. `C:` will be converted into `c:`. + // https://github.com/Microsoft/vscode/issues/68325#issuecomment-462239992 + if (isWindows) { + if (WIN32_DRIVE_REGEXP.exec(sketchPath)) { + sketchPath = firstToLowerCase(sketchPath); + } + if (WIN32_DRIVE_REGEXP.exec(temp)) { + temp = firstToLowerCase(temp); + } + } + return sketchPath.indexOf('.arduinoProIDE-unsaved') !== -1 && sketchPath.startsWith(temp); } async copy(sketch: Sketch, { destinationUri }: { destinationUri: string }): Promise {