Skip to content

Subfolder structure of sketch lost after "Save As" operation #2077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
jsmwrench opened this issue May 27, 2023 · 6 comments · Fixed by #2292
Closed
3 tasks done

Subfolder structure of sketch lost after "Save As" operation #2077

jsmwrench opened this issue May 27, 2023 · 6 comments · Fixed by #2292
Assignees
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project

Comments

@jsmwrench
Copy link

jsmwrench commented May 27, 2023

Describe the problem

Arduino sketches may contain files under subfolders:

🐛 After a "Save As..." operation, any subfolders are lost and the files are all moved to the root sketch folder.

To reproduce

  1. Click the following link to download the demonstration sketch:
    HasSubfolders.zip
  2. Unzip the downloaded file.
  3. Take note of the file structure of the sketch:
    HasSubfolders/
    ├── HasSubfolders.ino
    └── src/
        └── FromSubfolder.h
    
  4. Select File > Open from the Arduino IDE menus.
  5. Select the HasSubfolders.ino file from the unzipped folder.
  6. Select File > Save As..." from the Arduino IDE menus.
  7. Save the sketch to any convenient name and location.
  8. Select Sketch > Show Sketch Folder from the Arduino IDE menus.

🐛 The subfolder structure of the sketch was lost:

HasSubfoldersAfterSaveAs/
├── FromSubfolder.h
└── HasSubfoldersAfterSaveAs.ino

Expected behavior

A "Save As" operation does not make any changes to the sketch file structure.

Arduino IDE version

94d2962

Operating system

  • Windows
  • Linux
  • macOS

Operating system version

  • Windows 11
  • Ubuntu 22.04
  • macOS Ventura

Additional context

I bisected the regression to 0ab2826 (the fault does not occur when using 2aad0e3).

Additional reports

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
@jsmwrench jsmwrench added the type: imperfection Perceived defect in any part of project label May 27, 2023
@per1234 per1234 self-assigned this May 29, 2023
@per1234 per1234 added the topic: code Related to content of the project itself label May 29, 2023
@per1234
Copy link
Contributor

per1234 commented May 29, 2023

Hi @jsmwrench. Thanks for your report.

the original file was opened from an external drive. I then used File/Save As to save it to my "sketches" folder.

Please check to see whether the unexpected 36 files are also present in the folder on that external drive.

A common misconception is that an Arduino sketch is a file. The sketch is actually a folder. When you do a "Save As" operation with a sketch, all the files from the original sketch folder are saved to the folder that is the target of the "Save As" operation. So if you had previously placed all those 36 files in the original sketch folder then it is expected that they would also be present in the new folder as well.

@per1234 per1234 added the status: waiting for information More information must be provided before work can proceed label May 29, 2023
@fwlrichard
Copy link

Save as is also dumping All Files from all sub folders into the Sketch folder.

Original Sketch Folder Containing only the Sketch and a data folder. Data folder contains 4xfile.txt files.

SaveAs_Issue_ORG

Open Sketch click "Save As" and as you can see now the new Sketch folder contains the sketch and all 4 of the data files from the "data" folder that is now gone.

SaveAs_Issue_BAD

@per1234 - All previous versions of the Arduino IDE have been able to maintain file structure when doing a "Save As. "
Problem started with IDE Version: 2.1.0
Date: 2023-04-19T15:31:10.185Z
CLI Version: 0.32.2

@jsmwrench
Copy link
Author

None of the new files are in the original folder. The original folder only had the sketch itself and the AccelStepper library in it. I opened the sketch in VS Code and saved as a new file on my computer and when I did, the IDE created all of these files in the same folder as the newly saved sketch.
Folder I took it from:
From folder

New Folder:
New Folder

@jsmwrench
Copy link
Author

Okay, so I just figured out that all of the extra files are from the AccelStepper library. I'm not sure why it took all of those files on "Save As", but it did. I guess this can be closed.

@fwlrichard
Copy link

per1234
Please do not close this jsmwrench attachment shows the exact same issue that I have. It is not a "misconception" of the sketch being a folder. You can clearly see that the file folder "AccelStepper" is now missing in the second picture jsmwrench posted. I would put money on the fact that all of the extra files were originally contained within the "AccelStepper" Folder.

This is not normal or expected behavior of "SaveAs"
"SaveAs" is dumpling all sub folder files into the root sketch folder.
Expected result is for the original file folder structure to remain intact, just as it would if you clicked "Save."

@per1234 per1234 removed the status: waiting for information More information must be provided before work can proceed label Jul 13, 2023
@per1234 per1234 changed the title when saving as, sketch folder fills with files (libraries???) Subfolder structure of sketch lost after "Save As" operation Jul 13, 2023
@per1234
Copy link
Contributor

per1234 commented Jul 13, 2023

I am able to reproduce the fault and have updated the report to clearly describe the bug. Thanks for bringing this to our attention @jsmwrench and for your clarification @fwlrichard

@per1234 per1234 removed their assignment Jul 13, 2023
@kittaakos kittaakos self-assigned this Nov 23, 2023
@kittaakos kittaakos mentioned this issue Nov 23, 2023
4 tasks
kittaakos pushed a commit that referenced this issue Jan 15, 2024
This commit rewrites how IDE copies sketches as part of the _Save As_
operation. Instead of copying to the destination, IDE copies the sketch
into a temporary location, then to the desired destination.

This commit drops [`cpy`](https://www.npmjs.com/package/cpy).
Ref: sindresorhus/cpy@47b89a7

Closes #2077

Signed-off-by: Akos Kitta <[email protected]>
@kittaakos kittaakos added the conclusion: resolved Issue was resolved label Jan 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
conclusion: resolved Issue was resolved topic: code Related to content of the project itself type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants