Skip to content

Commit 63162c3

Browse files
author
Akos Kitta
committed
fix: resolve path when filtering for copy
1 parent f9b1a69 commit 63162c3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

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

+14-4
Original file line numberDiff line numberDiff line change
@@ -561,18 +561,28 @@ export class SketchesServiceImpl
561561

562562
let filter: CopyOptions['filter'];
563563
if (onlySketchFiles) {
564-
const sketchFilePaths = Sketch.uris(sketch).map(FileUri.fsPath);
564+
// The Windows paths, can be a trash (see below). Hence, it must be resolved with Node.js.
565+
// After resolving the path, the drive letter is still a gamble (can be upper or lower case) and could result in a false negative match.
566+
// Here, all sketch file paths must be resolved by Node.js, to provide the same drive letter casing.
567+
const sketchFilePaths = await Promise.all(
568+
Sketch.uris(sketch)
569+
.map(FileUri.fsPath)
570+
.map((path) => fs.realpath(path))
571+
);
565572
filter = async (s) => {
566-
if (sketchFilePaths.includes(s)) {
573+
// On Windows, the source path could start with a complete trash. For example, \\\\?\\c:\\Users\\kittaakos\\AppData\\Local\\Temp\\.arduinoIDE-unsaved20231024-9300-1hp64fi.g8yh\\sketch_nov24d.
574+
// The path must be resolved.
575+
const resolvedSource = await fs.realpath(s);
576+
if (sketchFilePaths.includes(resolvedSource)) {
567577
return true;
568578
}
569-
const stat = await fs.stat(s);
579+
const stat = await fs.stat(resolvedSource);
570580
if (stat.isFile()) {
571581
return false;
572582
}
573583
// Copy the folder if any of the sketch file path starts with this folder
574584
return sketchFilePaths.some((sketchFilePath) =>
575-
sketchFilePath.startsWith(s)
585+
sketchFilePath.startsWith(resolvedSource)
576586
);
577587
};
578588
} else {

Diff for: arduino-ide-extension/src/test/node/sketches-service-impl.slow-test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ describe('sketches-service-impl', () => {
405405
expect(sketch.otherSketchFileUris).to.be.empty;
406406
expect(sketch.rootFolderFileUris).to.be.empty;
407407

408-
const destinationUri = FileUri.fsPath(destinationPath).toString();
408+
const destinationUri = FileUri.create(destinationPath).toString();
409409
const copySketch = await sketchesService.copy(sketch, { destinationUri });
410410
toDispose.push(disposeSketch(copySketch));
411411
expect(copySketch.mainFileUri).to.be.equal(

0 commit comments

Comments
 (0)