Skip to content

Naming collision during "Save As" causes overwrite of secondary sketch file #827

Closed
@per1234

Description

@per1234

Describe the problem

The name of the primary source file of a sketch must match the sketch folder. For this reason, the IDE's "Save As..." function does two things:

  • Saves the sketch files to a folder of the selected name (e.g., FooSketch).
  • Renames the primary source file to match the new sketch name (e.g., FooSketch.ino).

This introduces the possibility of a collision between the target primary source file name and existing secondary source files of the sketch.

🙂 When such a collision occurs while using Arduino IDE 1.x, the operation is halted and the problem clearly communicated to the user:

image

🐛 When such a collision occurs while using Arduino IDE 2.x, the secondary source file is silently overwritten.

To reproduce

  1. Select File > New from the Arduino IDE menus.
  2. Click the button on the right side of the editor tabs bar.
  3. Select "New Tab" from the menu.
  4. Create a tab named Foo.ino
  5. Add some unique content to the tab:
    // Foo.ino tab content
  6. Select File > Save As... from the Arduino IDE menus.
  7. Save the sketch as Foo

🐛 The sketch now contains only a single file Foo.ino, with the contents from the primary source file. The previous contents of the Foo.ino secondary source file have been lost.

Expected behavior

  1. Halt the operation that would result in data loss.
  2. Clearly communicate the problem to the user.

-OR-

  1. Request confirmation from the user before overwriting the file.

Arduino IDE version

Original report

2.0.0-rc3-snapshot.69ac1f4

Last verified with

9a6a457

Operating system

Windows

Operating system version

11

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the latest nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions