Description
openedon Feb 11, 2023
Describe the problem
The Arduino IDE editor toolbar contains a "context" menu accessed via the ●●● icon. This menu includes a "Rename" option. The behavior of the "Rename" option depends on which type of sketch file tab is selected in the editor:
- If it is a secondary file, the option renames the file alone
- If it is the primary
.ino
file (the leftmost tab), the file and sketch folder are renamed
🐛 If the user selects a location inside the current sketch folder when renaming the primary tab, the sketch may be deleted.
To reproduce
- Select File > New Sketch from the Arduino IDE menus.
- Select File > Save As... from the Arduino IDE menus.
- Save the sketch with the name
Foo
- Click on the "Foo.ino" tab in the Arduino IDE editor.
ⓘ This step is required due to No delete/rename menu actions from the editor toolbar if editor has no focus after app start #1847 - Click the ●●● icon on the right side of the editor toolbar.
The editor context menu will open. - Select "Rename" from the menu.
The "Save sketch folder as..." dialog will open. - Select the
Foo
folder from the navigation panel of the dialog. - Save the sketch as
Bar
🐛 Intermittently, the above procedure will cause the the Bar
sketch to be deleted along with the Foo
parent folder.
The other times it will not be deleted, but the logs show that the IDE still attempted the deletion:
2023-02-11T22:29:01.644Z sketches-service ERROR Failed to delete sketch at c:\Users\per\Documents\Arduino\Foo.
2023-02-11T22:29:01.645Z root ERROR Request deleteSketch failed with error: EBUSY: resource busy or locked, rmdir 'c:\Users\per\Documents\Arduino\Foo\Bar'
2023-02-11T22:29:01.694Z root ERROR Error occurred when executing the startup task 'arduino-delete-sketch' with args: '["file:///c%3A/Users/per/Documents/Arduino/Foo"].
The intermittent outcome seems to be dependent on the timing of whether the deletion of the Foo
folder is completed before the IDE opens the Foo/Bar/Bar.ino
file. If the former, the sketch is deleted. If the latter, the deletion process fails due to the IDE creating a lock on it by having the sketch open.
Expected behavior
There is no valid use case for this procedure. The user will only attempt the above procedure based on a misunderstanding of the nature on an Arduino sketch and how the IDE's "Rename" feature works when done on the primary sketch file. These users expect the outcome to be that the primary sketch file alone is renamed, resulting in this structure:
Foo/
└── Bar.ino
However, the IDE's "Rename" feature intentionally does not work this way due to the requirement that the primary .ino
file match the sketch folder name.
So the ideal behavior would be for Arduino IDE to:
- Prevent the sketch from being be renamed to a location inside its previous sketch folder.
- Clearly communicate to the user that this is not allowed.
If the above is not possible, the second best behavior would be to end with a structure like this:
Foo/
└── Bar/
└── Bar.ino
This will not be the user's expected outcome, but the sketch is not deleted and remains valid.
Arduino IDE version
Operating system
Windows
Operating system version
11
Additional context
I am also able to reproduce the fault using the tester build from #1833 (b9e9ae9). I found the fault was no longer intermittent, but sometimes has a different characteristic in that the sketch is deleted after existing the IDE. It seems the deletion is postponed when the IDE is not able to complete the process due to a lock:
>>> Finishing scheduled sketch deletions before app quit...
>>> Running sketch deletion c:\Users\per\Documents\Arduino\Foo before app quit...
<<< Deleted sketch c:\Users\per\Documents\Arduino\Foo
<<< Successfully finishing scheduled sketch deletions.
Originally reported at https://forum.arduino.cc/t/arduino-ide-deleted-all-project-files-after-changing-from-ino-to-cpp/1088672
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
Activity