fix: copy when punctuation marks in sketch path

Changed the `source` and `cwd` args to avoid accidentally creating an
invalid `glob` patterns when doing the brace expansion by `cpy`.

Closes #2043

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta
2023-05-04 14:30:38 +02:00
committed by Akos Kitta
parent e6828f86d7
commit 964ea3bc0c
2 changed files with 87 additions and 7 deletions

View File

@@ -444,7 +444,7 @@ export class SketchesServiceImpl
* For example, on Windows, instead of getting an [8.3 filename](https://en.wikipedia.org/wiki/8.3_filename), callers will get a fully resolved path.
* `C:\\Users\\KITTAA~1\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2022615-21100-iahybb.yyvh\\sketch_jul15a` will be `C:\\Users\\kittaakos\\AppData\\Local\\Temp\\.arduinoIDE-unsaved2022615-21100-iahybb.yyvh\\sketch_jul15a`
*/
createTempFolder(): Promise<string> {
private createTempFolder(): Promise<string> {
return new Promise<string>((resolve, reject) => {
temp.mkdir({ prefix: TempSketchPrefix }, (createError, dirPath) => {
if (createError) {
@@ -523,13 +523,14 @@ export class SketchesServiceImpl
} else {
filter = () => true;
}
await cpy(source, destination, {
await cpy(sourceFolderBasename, destination, {
rename: (basename) =>
sourceFolderBasename !== destinationFolderBasename &&
basename === `${sourceFolderBasename}.ino`
? `${destinationFolderBasename}.ino`
: basename,
filter,
cwd: path.dirname(source),
});
const copiedSketch = await this.doLoadSketch(destinationUri, false);
return copiedSketch;