1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-17 11:54:33 +01:00

Fix symlinks being replaced with files on save

Fixes #5478

Backported from Processing 0abee5af6a/app/src/processing/app/Util.java (L174)
This commit is contained in:
Martino Facchin 2016-11-04 18:30:52 +01:00
parent c209e33e97
commit 2d1f49a077

View File

@ -1061,11 +1061,22 @@ public class BaseNoGui {
}
/**
* 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) {