Skip to content

Fix symlinks being replaced with files on save #5573

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

Merged
merged 1 commit into from
Dec 7, 2016

Conversation

facchinm
Copy link
Member

@facchinm facchinm commented Nov 7, 2016

Fixes #5478

tested on Linux, please confirm that it works in Win and OSX before merging

@cmaglie cmaglie modified the milestone: Release 1.6.13 Nov 7, 2016
@matthijskooijman
Copy link
Collaborator

The fix itself looks ok, but I'm wondering if we really need this "write to a tempfile, delete the original and move the tempfile"-approach here at all? Just opening the original file for writing would transparently handle symbolic links AFAICS?

Digging through git history shows that it used to work like that, but it was changed in upstream processing, without any comments about why this is: 2e26a2d9#diff-b6fda0bf6be0a53c0741a9b02ac16f37R1898

Digging in the Processing repo gives this commit and this bug report, which says the tempfile is to prevent truncating the file when the disk is full, which seems like a good reason.

The latest version of Processing has also fixed the symlink problem similar like in this PR (though it uses File.getCanonicalFile() which is a bit more compact than the code in this PR): https://github.com/processing/processing/blob/0abee5af6ad3b11cf2b73bb794b8a97c157c4762/app/src/processing/app/Util.java#L166-L203

@facchinm, could you update the PR to use getCanonicalFile(), and add a commit that adds a comment about why this tempfile approach is used?

@facchinm
Copy link
Member Author

Thanks for digging into Processing sources @matthijskooijman !
File.getCanonicalFile() looks good, I'm testing it and eventually replacing the commit as you suggested

@facchinm
Copy link
Member Author

@matthijskooijman , how does it look now? Functionality is ok


try {
File canon = file.getCanonicalFile();
file = canon;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this can just be file = file.getCanonicalFile();. If getCanonicalFile() throws, the assignment will not be executed.

@facchinm facchinm merged commit a93b45d into arduino:master Dec 7, 2016
@cmaglie cmaglie deleted the fix_symlink_5478 branch December 19, 2016 17:09
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.

4 participants