mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-20 14:54:31 +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:
parent
c209e33e97
commit
2d1f49a077
@ -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 {
|
static public void saveFile(String str, File file) throws IOException {
|
||||||
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
|
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
|
||||||
PApplet.saveStrings(temp, new String[] { str });
|
PApplet.saveStrings(temp, new String[] { str });
|
||||||
|
|
||||||
|
try {
|
||||||
|
file = file.getCanonicalFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
boolean result = file.delete();
|
boolean result = file.delete();
|
||||||
if (!result) {
|
if (!result) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user