mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-10 02:48:33 +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:
@@ -530,6 +530,35 @@ export class SketchesServiceImpl
|
||||
throw SketchesError.InvalidFolderName(message, destinationFolderBasename);
|
||||
}
|
||||
|
||||
// verify a possible name collision with existing ino files
|
||||
if (sourceFolderBasename !== destinationFolderBasename) {
|
||||
try {
|
||||
const otherInoBasename = `${destinationFolderBasename}.ino`;
|
||||
const otherInoPath = join(source, otherInoBasename);
|
||||
const stat = await fs.stat(otherInoPath);
|
||||
if (stat.isFile()) {
|
||||
const message = nls.localize(
|
||||
'arduino/sketch/sketchAlreadyContainsThisFileError',
|
||||
"The sketch already contains a file named '{0}'",
|
||||
otherInoBasename
|
||||
);
|
||||
// if can read the file, it will be a collision
|
||||
throw SketchesError.SketchAlreadyContainsThisFile(
|
||||
message,
|
||||
sourceFolderBasename,
|
||||
destinationFolderBasename,
|
||||
otherInoBasename
|
||||
);
|
||||
}
|
||||
// Otherwise, it's OK, if it is an existing directory
|
||||
} catch (err) {
|
||||
// It's OK if the file is missing.
|
||||
if (!ErrnoException.isENOENT(err)) {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let filter: CopyOptions['filter'];
|
||||
if (onlySketchFiles) {
|
||||
// The Windows paths, can be a trash (see below). Hence, it must be resolved with Node.js.
|
||||
|
||||
Reference in New Issue
Block a user