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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion arduino-core/src/processing/app/BaseNoGui.java
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,22 @@ static public String sanitizeName(String origName) {
}

/**
* Spew the contents of a String object out to a file.
* Save the content of a String into a file
* - Save the content into a temp file
* - Find the canonical path of the file (if it's a symlink, follow it)
* - Remove the original file
* - Move temp file to original path
* This ensures that the file is not getting truncated if the disk is full
*/
static public void saveFile(String str, File file) throws IOException {
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
PApplet.saveStrings(temp, new String[] { str });

try {
file = file.getCanonicalFile();
} catch (IOException e) {
}

if (file.exists()) {
boolean result = file.delete();
if (!result) {
Expand Down