mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-11 11:19:26 +00:00
fix: sketch Save As errors on name collision
The Save As operation is halted and the problem clearly communicated to the user when there is a collision between the target primary source file name and existing secondary source files of the sketch. Closes #827 Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
@@ -158,6 +158,37 @@ describe('sketches-service-impl', () => {
|
||||
);
|
||||
});
|
||||
|
||||
it('should error when the destination sketch folder name collides with an existing sketch file name', async () => {
|
||||
const sketchesService =
|
||||
container.get<SketchesServiceImpl>(SketchesService);
|
||||
const tempDirPath = await sketchesService['createTempFolder']();
|
||||
const destinationPath = join(tempDirPath, 'ExistingSketchFile');
|
||||
let sketch = await sketchesService.createNewSketch();
|
||||
toDispose.push(disposeSketch(sketch));
|
||||
const sourcePath = FileUri.fsPath(sketch.uri);
|
||||
const otherInoBasename = 'ExistingSketchFile.ino';
|
||||
const otherInoPath = join(sourcePath, otherInoBasename);
|
||||
await fs.writeFile(otherInoPath, '// a comment', { encoding: 'utf8' });
|
||||
|
||||
sketch = await sketchesService.loadSketch(sketch.uri);
|
||||
expect(Sketch.isInSketch(FileUri.create(otherInoPath), sketch)).to.be
|
||||
.true;
|
||||
|
||||
await rejects(
|
||||
sketchesService.copy(sketch, {
|
||||
destinationUri: FileUri.create(destinationPath).toString(),
|
||||
}),
|
||||
(reason) => {
|
||||
return (
|
||||
typeof reason === 'object' &&
|
||||
reason !== null &&
|
||||
SketchesError.SketchAlreadyContainsThisFile.is(reason) &&
|
||||
reason.data.existingSketchFilename === otherInoBasename
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('should copy a sketch when the destination does not exist', async () => {
|
||||
const sketchesService =
|
||||
container.get<SketchesServiceImpl>(SketchesService);
|
||||
|
||||
Reference in New Issue
Block a user