fix: copy example with .pde main sketch file

Closes arduino/arduino-ide#2377

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2024-02-22 12:27:43 +01:00 committed by Akos Kitta
parent 4217c0001d
commit aa9b10d68e
2 changed files with 40 additions and 4 deletions

View File

@ -609,9 +609,13 @@ export class SketchesServiceImpl
force: true,
});
const sourceMainSketchFilePath = FileUri.fsPath(sketch.mainFileUri);
// Can copy sketch with pde main sketch file: https://github.com/arduino/arduino-ide/issues/2377
const ext = path.extname(sourceMainSketchFilePath);
// rename the main sketch file
await fs.rename(
join(temp, `${sourceFolderBasename}.ino`),
join(temp, `${sourceFolderBasename}${ext}`),
join(temp, `${destinationFolderBasename}.ino`)
);

View File

@ -3,18 +3,19 @@ import {
DisposableCollection,
} from '@theia/core/lib/common/disposable';
import { isWindows } from '@theia/core/lib/common/os';
import { URI } from '@theia/core/lib/common/uri';
import { FileUri } from '@theia/core/lib/node/file-uri';
import { Container } from '@theia/core/shared/inversify';
import { expect } from 'chai';
import { promises as fs } from 'node:fs';
import { basename, join } from 'node:path';
import { rejects } from 'node:assert/strict';
import { promises as fs } from 'node:fs';
import path, { basename, join } from 'node:path';
import { sync as rimrafSync } from 'rimraf';
import temp from 'temp';
import { Sketch, SketchesError, SketchesService } from '../../common/protocol';
import {
isAccessibleSketchPath,
SketchesServiceImpl,
isAccessibleSketchPath,
} from '../../node/sketches-service-impl';
import { ErrnoException } from '../../node/utils/errors';
import { createBaseContainer, startDaemon } from './node-test-bindings';
@ -332,6 +333,37 @@ describe('sketches-service-impl', () => {
);
});
it('should copy sketch if the main sketch file has pde extension (#2377)', async () => {
const sketchesService =
container.get<SketchesServiceImpl>(SketchesService);
let sketch = await sketchesService.createNewSketch();
toDispose.push(disposeSketch(sketch));
expect(sketch.mainFileUri.endsWith('.ino')).to.be.true;
// Create a sketch and rename the main sketch file to .pde
const mainSketchFilePathIno = FileUri.fsPath(new URI(sketch.mainFileUri));
const sketchFolderPath = path.dirname(mainSketchFilePathIno);
const mainSketchFilePathPde = path.join(
sketchFolderPath,
`${basename(sketchFolderPath)}.pde`
);
await fs.rename(mainSketchFilePathIno, mainSketchFilePathPde);
sketch = await sketchesService.loadSketch(sketch.uri);
expect(sketch.mainFileUri.endsWith('.pde')).to.be.true;
const tempDirPath = await sketchesService['createTempFolder']();
const destinationPath = join(tempDirPath, 'GH-2377');
const destinationUri = FileUri.create(destinationPath).toString();
await sketchesService.copy(sketch, {
destinationUri,
});
const copiedSketch = await sketchesService.loadSketch(destinationUri);
expect(copiedSketch.mainFileUri.endsWith('.ino')).to.be.true;
});
it('should copy sketch inside the sketch folder', async () => {
const sketchesService =
container.get<SketchesServiceImpl>(SketchesService);