Skip to content
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

Fix "save as" operation for the data folder of a sketch #6041

Merged
merged 1 commit into from
Mar 16, 2017

Conversation

jeroenoverman
Copy link
Contributor

This pull fixes #5998.

When performing a save as operation the data folder of the sketch was not copied to the new location.

What has changed:

  • switching to the new folder is now the last operation in the save as method.
    • this caused not finding a data folder, since the folder was already changed to the new location
  • If the data folder does not exists yet, it is created before the files are copied to the new location

I have tested this on my Windows machine and it solves the issue.

@mastrolinux mastrolinux added the in progress Work on this item is in progress label Mar 5, 2017

// Copy the data folder (this may take a while.. add progress bar?)
if (getDataFolder().exists()) {
File newDataFolder = new File(newFolder, "data");
// Create the data folder
if (!newDataFolder.mkdirs()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check for newDataFolder.exists() before bailing out? The check could be probably turned into if(!(newDataFolder.exists() || newDataFolder.mkdirs())) . Do you see any drawback in this approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can check if the folder exists, but since we just created the parent folder at line 341, it is very unlikely the folder already exits.

Never the less it won't harm if we implement this extra check. So I will add the check and test if it still works.

@matthijskooijman
Copy link
Collaborator

Changes look good to me. The first and last commit should probably be dropped, no point in polluting the history with them. As for the second commit (moving the folder update), it would probably be good to expand the commit message a bit to point out that folder is an instance variable used by getDataFolder() and that the old code would never see the old data folder for that reason?

// Create the data folder
if (!newDataFolder.mkdirs()) {
// Check if data folder exits, if not try to create the data folder
if (!(newDataFolder.exists() || newDataFolder.mkdirs())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that if (!newDataFolder.exists() && !newDataFolder.mkdirs()) is a bit easier to read, would you agree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability you might even want to separate the condition into two if statements. (In case you don't know how the lazy and/or operator works).

But I think it is better to keep them into one if statement. I will change it to the and operator for better readability.

Changed the location where the variable `folder` gets updated. The
function `getDataFolder()` uses this variable to return the data folder.
It was looking for the data folder of the original sketch in the folder
of the new created sketch.
Furthermore the data folder will now be created if it does not exist yet
in the new sketch before copying the files of the original sketch.
@jeroenoverman
Copy link
Contributor Author

I have fixed the comments you gave me.

@jeroenoverman
Copy link
Contributor Author

@facchinm Is this Pull Request ready to be merged or should something still be changed or more tested?

@facchinm
Copy link
Member

Looks fine, thanks for the ping 😉

@facchinm facchinm merged commit 14b3f9b into arduino:master Mar 16, 2017
@mastrolinux mastrolinux removed the in progress Work on this item is in progress label Mar 16, 2017
@facchinm facchinm added this to the Release 1.8.2 milestone Mar 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 1.8.1 doesn't copy 'data' folder on save as
4 participants